-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(config-resolver): add NodeUseFipsEndpointConfigOptions
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
packages/config-resolver/src/regionConfig/NodeUseFipsEndpointConfigOptions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
packages/config-resolver/src/regionConfig/NodeUseFipsEndpointConfigOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./NodeUseFipsEndpointConfigOptions"; | ||
export * from "./config"; | ||
export * from "./resolveRegionConfig"; |