-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(middleware-bucket-endpoint): use booleanSelector from node-conf…
…ig-provider (#2946)
- Loading branch information
Showing
8 changed files
with
133 additions
and
122 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
...ges/middleware-bucket-endpoint/src/NodeDisableMultiregionAccessPointConfigOptions.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,50 @@ | ||
import { booleanSelector, SelectorType } from "@aws-sdk/node-config-provider"; | ||
|
||
import { | ||
NODE_DISABLE_MULTIREGION_ACCESS_POINT_CONFIG_OPTIONS, | ||
NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME, | ||
NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME, | ||
} from "./NodeDisableMultiregionAccessPointConfigOptions"; | ||
|
||
jest.mock("@aws-sdk/node-config-provider"); | ||
|
||
describe("NODE_USE_ARN_REGION_CONFIG_OPTIONS", () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const test = (func: Function, obj: { [key: string]: string }, key: string, type: SelectorType) => { | ||
it.each([true, false, undefined])("returns %s", (output) => { | ||
(booleanSelector as jest.Mock).mockReturnValueOnce(output); | ||
expect(func(obj)).toEqual(output); | ||
expect(booleanSelector).toBeCalledWith(obj, key, type); | ||
}); | ||
|
||
it("throws error", () => { | ||
const mockError = new Error("error"); | ||
(booleanSelector as jest.Mock).mockImplementationOnce(() => { | ||
throw mockError; | ||
}); | ||
expect(() => { | ||
func(obj); | ||
}).toThrow(mockError); | ||
}); | ||
}; | ||
|
||
describe("calls booleanSelector for environmentVariableSelector", () => { | ||
const env: { [NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME]: any } = {} as any; | ||
const { environmentVariableSelector } = NODE_DISABLE_MULTIREGION_ACCESS_POINT_CONFIG_OPTIONS; | ||
test(environmentVariableSelector, env, NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME, SelectorType.ENV); | ||
}); | ||
|
||
describe("calls booleanSelector for configFileSelector", () => { | ||
const profileContent: { [NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME]: any } = {} as any; | ||
const { configFileSelector } = NODE_DISABLE_MULTIREGION_ACCESS_POINT_CONFIG_OPTIONS; | ||
test(configFileSelector, profileContent, NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME, SelectorType.CONFIG); | ||
}); | ||
|
||
it("returns false for default", () => { | ||
const { default: defaultValue } = NODE_DISABLE_MULTIREGION_ACCESS_POINT_CONFIG_OPTIONS; | ||
expect(defaultValue).toEqual(false); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/middleware-bucket-endpoint/src/NodeDisableMultiregionAccessPointConfigOptions.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,13 @@ | ||
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider"; | ||
import { booleanSelector, SelectorType } from "@aws-sdk/node-config-provider"; | ||
|
||
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME = "AWS_S3_DISABLE_MULTIREGION_ACCESS_POINTS"; | ||
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME = "s3_disable_multiregion_access_points"; | ||
|
||
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = { | ||
environmentVariableSelector: (env: NodeJS.ProcessEnv) => | ||
booleanSelector(env, NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME, SelectorType.ENV), | ||
configFileSelector: (profile) => | ||
booleanSelector(profile, NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME, SelectorType.CONFIG), | ||
default: false, | ||
}; |
50 changes: 50 additions & 0 deletions
50
packages/middleware-bucket-endpoint/src/NodeUseArnRegionConfigOptions.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,50 @@ | ||
import { booleanSelector, SelectorType } from "@aws-sdk/node-config-provider"; | ||
|
||
import { | ||
NODE_USE_ARN_REGION_CONFIG_OPTIONS, | ||
NODE_USE_ARN_REGION_ENV_NAME, | ||
NODE_USE_ARN_REGION_INI_NAME, | ||
} from "./NodeUseArnRegionConfigOptions"; | ||
|
||
jest.mock("@aws-sdk/node-config-provider"); | ||
|
||
describe("NODE_USE_ARN_REGION_CONFIG_OPTIONS", () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
const test = (func: Function, obj: { [key: string]: string }, key: string, type: SelectorType) => { | ||
it.each([true, false, undefined])("returns %s", (output) => { | ||
(booleanSelector as jest.Mock).mockReturnValueOnce(output); | ||
expect(func(obj)).toEqual(output); | ||
expect(booleanSelector).toBeCalledWith(obj, key, type); | ||
}); | ||
|
||
it("throws error", () => { | ||
const mockError = new Error("error"); | ||
(booleanSelector as jest.Mock).mockImplementationOnce(() => { | ||
throw mockError; | ||
}); | ||
expect(() => { | ||
func(obj); | ||
}).toThrow(mockError); | ||
}); | ||
}; | ||
|
||
describe("calls booleanSelector for environmentVariableSelector", () => { | ||
const env: { [NODE_USE_ARN_REGION_ENV_NAME]: any } = {} as any; | ||
const { environmentVariableSelector } = NODE_USE_ARN_REGION_CONFIG_OPTIONS; | ||
test(environmentVariableSelector, env, NODE_USE_ARN_REGION_ENV_NAME, SelectorType.ENV); | ||
}); | ||
|
||
describe("calls booleanSelector for configFileSelector", () => { | ||
const profileContent: { [NODE_USE_ARN_REGION_INI_NAME]: any } = {} as any; | ||
const { configFileSelector } = NODE_USE_ARN_REGION_CONFIG_OPTIONS; | ||
test(configFileSelector, profileContent, NODE_USE_ARN_REGION_INI_NAME, SelectorType.CONFIG); | ||
}); | ||
|
||
it("returns false for default", () => { | ||
const { default: defaultValue } = NODE_USE_ARN_REGION_CONFIG_OPTIONS; | ||
expect(defaultValue).toEqual(false); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
packages/middleware-bucket-endpoint/src/NodeUseArnRegionConfigOptions.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,17 @@ | ||
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider"; | ||
import { booleanSelector, SelectorType } from "@aws-sdk/node-config-provider"; | ||
|
||
export const NODE_USE_ARN_REGION_ENV_NAME = "AWS_S3_USE_ARN_REGION"; | ||
export const NODE_USE_ARN_REGION_INI_NAME = "s3_use_arn_region"; | ||
|
||
/** | ||
* Config to load useArnRegion from environment variables and shared INI files | ||
* | ||
* @api private | ||
*/ | ||
export const NODE_USE_ARN_REGION_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = { | ||
environmentVariableSelector: (env: NodeJS.ProcessEnv) => | ||
booleanSelector(env, NODE_USE_ARN_REGION_ENV_NAME, SelectorType.ENV), | ||
configFileSelector: (profile) => booleanSelector(profile, NODE_USE_ARN_REGION_INI_NAME, SelectorType.CONFIG), | ||
default: false, | ||
}; |
68 changes: 0 additions & 68 deletions
68
packages/middleware-bucket-endpoint/src/configuration.spec.ts
This file was deleted.
Oops, something went wrong.
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
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