Skip to content

Commit 47b845b

Browse files
committed
chore(config-resolver): add UseFipsEndpointConfigOptions
1 parent 74e25df commit 47b845b

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {
2+
CONFIG_USE_FIPS_ENDPOINT,
3+
ENV_USE_FIPS_ENDPOINT,
4+
USE_FIPS_ENDPOINT_CONFIG_OPTIONS,
5+
} from "./UseFipsEndpointConfigOptions";
6+
7+
describe("USE_FIPS_ENDPOINT_CONFIG_OPTIONS", () => {
8+
const test = (selector, obj, key) => {
9+
beforeEach(() => {
10+
delete obj[key];
11+
});
12+
13+
it(`should return undefined if ${key} is not defined`, () => {
14+
expect(selector(obj)).toBeUndefined();
15+
});
16+
17+
it.each([
18+
[true, "true"],
19+
[false, "false"],
20+
])(`should return boolean %s if ${key}="%s"`, (output, input) => {
21+
obj[key] = input;
22+
expect(selector(obj)).toBe(output);
23+
});
24+
25+
it.each(["0", "1", "yes", "no", undefined, null, void 0, ""])(`should throw if ${key}=%s`, (input) => {
26+
obj[key] = input;
27+
expect(() => selector(obj)).toThrow();
28+
});
29+
};
30+
31+
describe("environment variable selector", () => {
32+
const env: { [ENV_USE_FIPS_ENDPOINT]: any } = {} as any;
33+
const { environmentVariableSelector } = USE_FIPS_ENDPOINT_CONFIG_OPTIONS;
34+
test(environmentVariableSelector, env, ENV_USE_FIPS_ENDPOINT);
35+
});
36+
37+
describe("config file selector", () => {
38+
const profileContent: { [CONFIG_USE_FIPS_ENDPOINT]: any } = {} as any;
39+
const { configFileSelector } = USE_FIPS_ENDPOINT_CONFIG_OPTIONS;
40+
test(configFileSelector, profileContent, CONFIG_USE_FIPS_ENDPOINT);
41+
});
42+
43+
it("returns false by default", () => {
44+
const { default: defaultValue } = USE_FIPS_ENDPOINT_CONFIG_OPTIONS;
45+
expect(defaultValue).toEqual(false);
46+
});
47+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider";
2+
3+
export const ENV_USE_FIPS_ENDPOINT = "AWS_USE_FIPS_ENDPOINT";
4+
export const CONFIG_USE_FIPS_ENDPOINT = "use_fips_endpoint";
5+
6+
export const USE_FIPS_ENDPOINT_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = {
7+
environmentVariableSelector: (env) => {
8+
if (!Object.prototype.hasOwnProperty.call(env, ENV_USE_FIPS_ENDPOINT)) return undefined;
9+
if (env[ENV_USE_FIPS_ENDPOINT] === "true") return true;
10+
if (env[ENV_USE_FIPS_ENDPOINT] === "false") return false;
11+
throw new Error(
12+
`Cannot load env ${ENV_USE_FIPS_ENDPOINT}. Expected "true" or "false", got ${env[ENV_USE_FIPS_ENDPOINT]}.`
13+
);
14+
},
15+
configFileSelector: (profile) => {
16+
if (!Object.prototype.hasOwnProperty.call(profile, CONFIG_USE_FIPS_ENDPOINT)) return undefined;
17+
if (profile[CONFIG_USE_FIPS_ENDPOINT] === "true") return true;
18+
if (profile[CONFIG_USE_FIPS_ENDPOINT] === "false") return false;
19+
throw new Error(
20+
`Cannot load shared config entry ${CONFIG_USE_FIPS_ENDPOINT}. Expected "true" or "false", got ${profile[CONFIG_USE_FIPS_ENDPOINT]}.`
21+
);
22+
},
23+
default: false,
24+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from "./UseFipsEndpointConfigOptions";
12
export * from "./config";
23
export * from "./resolveRegionConfig";

0 commit comments

Comments
 (0)