Skip to content

Commit 5e7ed08

Browse files
committed
chore(config-resolver): add NodeUseFipsEndpointConfigOptions
1 parent 1b3c9b7 commit 5e7ed08

File tree

3 files changed

+74
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)