Skip to content

Commit

Permalink
chore(config-resolver): add NodeUseFipsEndpointConfigOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Oct 28, 2021
1 parent 1b3c9b7 commit 5e7ed08
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
CONFIG_USE_FIPS_ENDPOINT,
DEFAULT_USE_FIPS_ENDPOINT,
ENV_USE_FIPS_ENDPOINT,
NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS,
} from "./NodeUseFipsEndpointConfigOptions";

describe("NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS", () => {
const test = (selector, obj, key) => {
beforeEach(() => {
delete obj[key];
});

it(`should return undefined if ${key} is not defined`, () => {
expect(selector(obj)).toBeUndefined();
});

it.each([
[true, "true"],
[false, "false"],
])(`should return boolean %s if ${key}="%s"`, (output, input) => {
obj[key] = input;
expect(selector(obj)).toBe(output);
});

it.each(["0", "1", "yes", "no", undefined, null, void 0, ""])(`should throw if ${key}=%s`, (input) => {
obj[key] = input;
expect(() => selector(obj)).toThrow();
});
};

describe("environment variable selector", () => {
const env: { [ENV_USE_FIPS_ENDPOINT]: any } = {} as any;
const { environmentVariableSelector } = NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS;
test(environmentVariableSelector, env, ENV_USE_FIPS_ENDPOINT);
});

describe("config file selector", () => {
const profileContent: { [CONFIG_USE_FIPS_ENDPOINT]: any } = {} as any;
const { configFileSelector } = NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS;
test(configFileSelector, profileContent, CONFIG_USE_FIPS_ENDPOINT);
});

it(`returns ${DEFAULT_USE_FIPS_ENDPOINT} by default`, () => {
const { default: defaultValue } = NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS;
expect(defaultValue).toEqual(DEFAULT_USE_FIPS_ENDPOINT);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider";

export const ENV_USE_FIPS_ENDPOINT = "AWS_USE_FIPS_ENDPOINT";
export const CONFIG_USE_FIPS_ENDPOINT = "use_fips_endpoint";
export const DEFAULT_USE_FIPS_ENDPOINT = false;

export const NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = {
environmentVariableSelector: (env) => {
if (!Object.prototype.hasOwnProperty.call(env, ENV_USE_FIPS_ENDPOINT)) return undefined;
if (env[ENV_USE_FIPS_ENDPOINT] === "true") return true;
if (env[ENV_USE_FIPS_ENDPOINT] === "false") return false;
throw new Error(
`Cannot load env ${ENV_USE_FIPS_ENDPOINT}. Expected "true" or "false", got ${env[ENV_USE_FIPS_ENDPOINT]}.`
);
},
configFileSelector: (profile) => {
if (!Object.prototype.hasOwnProperty.call(profile, CONFIG_USE_FIPS_ENDPOINT)) return undefined;
if (profile[CONFIG_USE_FIPS_ENDPOINT] === "true") return true;
if (profile[CONFIG_USE_FIPS_ENDPOINT] === "false") return false;
throw new Error(
`Cannot load shared config entry ${CONFIG_USE_FIPS_ENDPOINT}. Expected "true" or "false", got ${profile[CONFIG_USE_FIPS_ENDPOINT]}.`
);
},
default: DEFAULT_USE_FIPS_ENDPOINT,
};
1 change: 1 addition & 0 deletions packages/config-resolver/src/regionConfig/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./NodeUseFipsEndpointConfigOptions";
export * from "./config";
export * from "./resolveRegionConfig";

0 comments on commit 5e7ed08

Please sign in to comment.