Skip to content

Commit 461ae0f

Browse files
committed
chore: move ConfigOptions out of configurations
1 parent abe4ed9 commit 461ae0f

File tree

5 files changed

+58
-54
lines changed

5 files changed

+58
-54
lines changed
Lines changed: 25 additions & 0 deletions
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 NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME = "AWS_S3_DISABLE_MULTIREGION_ACCESS_POINTS";
4+
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME = "s3_disable_multiregion_access_points";
5+
6+
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = {
7+
environmentVariableSelector: (env: NodeJS.ProcessEnv) => {
8+
if (!Object.prototype.hasOwnProperty.call(env, NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME)) return undefined;
9+
if (env[NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME] === "true") return true;
10+
if (env[NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME] === "false") return false;
11+
throw new Error(
12+
`Cannot load env ${NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME}. Expected "true" or "false", got ${env[NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME]}.`
13+
);
14+
},
15+
configFileSelector: (profile) => {
16+
if (!Object.prototype.hasOwnProperty.call(profile, NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME))
17+
return undefined;
18+
if (profile[NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME] === "true") return true;
19+
if (profile[NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME] === "false") return false;
20+
throw new Error(
21+
`Cannot load shared config entry ${NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME}. Expected "true" or "false", got ${profile[NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME]}.`
22+
);
23+
},
24+
default: false,
25+
};

packages/middleware-bucket-endpoint/src/configuration.spec.ts renamed to packages/middleware-bucket-endpoint/src/NodeUseArnRegionConfigOptions.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {
22
NODE_USE_ARN_REGION_CONFIG_OPTIONS as loadOptions,
33
NODE_USE_ARN_REGION_ENV_NAME,
44
NODE_USE_ARN_REGION_INI_NAME,
5-
} from "./configurations";
5+
} from "./NodeUseArnRegionConfigOptions";
6+
67
describe("Node useArnRegion config loader", () => {
78
describe("environment variable selector", () => {
89
const env: { [NODE_USE_ARN_REGION_ENV_NAME]: any } = {} as any;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider";
2+
3+
export const NODE_USE_ARN_REGION_ENV_NAME = "AWS_S3_USE_ARN_REGION";
4+
export const NODE_USE_ARN_REGION_INI_NAME = "s3_use_arn_region";
5+
6+
/**
7+
* Config to load useArnRegion from environment variables and shared INI files
8+
*
9+
* @api private
10+
*/
11+
export const NODE_USE_ARN_REGION_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = {
12+
environmentVariableSelector: (env: NodeJS.ProcessEnv) => {
13+
if (!Object.prototype.hasOwnProperty.call(env, NODE_USE_ARN_REGION_ENV_NAME)) return undefined;
14+
if (env[NODE_USE_ARN_REGION_ENV_NAME] === "true") return true;
15+
if (env[NODE_USE_ARN_REGION_ENV_NAME] === "false") return false;
16+
throw new Error(
17+
`Cannot load env ${NODE_USE_ARN_REGION_ENV_NAME}. Expected "true" or "false", got ${env[NODE_USE_ARN_REGION_ENV_NAME]}.`
18+
);
19+
},
20+
configFileSelector: (profile) => {
21+
if (!Object.prototype.hasOwnProperty.call(profile, NODE_USE_ARN_REGION_INI_NAME)) return undefined;
22+
if (profile[NODE_USE_ARN_REGION_INI_NAME] === "true") return true;
23+
if (profile[NODE_USE_ARN_REGION_INI_NAME] === "false") return false;
24+
throw new Error(
25+
`Cannot load shared config entry ${NODE_USE_ARN_REGION_INI_NAME}. Expected "true" or "false", got ${profile[NODE_USE_ARN_REGION_INI_NAME]}.`
26+
);
27+
},
28+
default: false,
29+
};

packages/middleware-bucket-endpoint/src/configurations.ts

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { LoadedConfigSelectors } from "@aws-sdk/node-config-provider";
21
import { Provider, RegionInfoProvider } from "@aws-sdk/types";
32

43
export interface BucketEndpointInputConfig {
@@ -100,55 +99,3 @@ export function resolveBucketEndpointConfig<T>(
10099
: () => Promise.resolve(disableMultiregionAccessPoints),
101100
};
102101
}
103-
104-
export const NODE_USE_ARN_REGION_ENV_NAME = "AWS_S3_USE_ARN_REGION";
105-
export const NODE_USE_ARN_REGION_INI_NAME = "s3_use_arn_region";
106-
107-
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME = "AWS_S3_DISABLE_MULTIREGION_ACCESS_POINTS";
108-
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME = "s3_disable_multiregion_access_points";
109-
110-
/**
111-
* Config to load useArnRegion from environment variables and shared INI files
112-
*
113-
* @api private
114-
*/
115-
export const NODE_USE_ARN_REGION_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = {
116-
environmentVariableSelector: (env: NodeJS.ProcessEnv) => {
117-
if (!Object.prototype.hasOwnProperty.call(env, NODE_USE_ARN_REGION_ENV_NAME)) return undefined;
118-
if (env[NODE_USE_ARN_REGION_ENV_NAME] === "true") return true;
119-
if (env[NODE_USE_ARN_REGION_ENV_NAME] === "false") return false;
120-
throw new Error(
121-
`Cannot load env ${NODE_USE_ARN_REGION_ENV_NAME}. Expected "true" or "false", got ${env[NODE_USE_ARN_REGION_ENV_NAME]}.`
122-
);
123-
},
124-
configFileSelector: (profile) => {
125-
if (!Object.prototype.hasOwnProperty.call(profile, NODE_USE_ARN_REGION_INI_NAME)) return undefined;
126-
if (profile[NODE_USE_ARN_REGION_INI_NAME] === "true") return true;
127-
if (profile[NODE_USE_ARN_REGION_INI_NAME] === "false") return false;
128-
throw new Error(
129-
`Cannot load shared config entry ${NODE_USE_ARN_REGION_INI_NAME}. Expected "true" or "false", got ${profile[NODE_USE_ARN_REGION_INI_NAME]}.`
130-
);
131-
},
132-
default: false,
133-
};
134-
135-
export const NODE_DISABLE_MULTIREGION_ACCESS_POINT_CONFIG_OPTIONS: LoadedConfigSelectors<boolean> = {
136-
environmentVariableSelector: (env: NodeJS.ProcessEnv) => {
137-
if (!Object.prototype.hasOwnProperty.call(env, NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME)) return undefined;
138-
if (env[NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME] === "true") return true;
139-
if (env[NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME] === "false") return false;
140-
throw new Error(
141-
`Cannot load env ${NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME}. Expected "true" or "false", got ${env[NODE_DISABLE_MULTIREGION_ACCESS_POINT_ENV_NAME]}.`
142-
);
143-
},
144-
configFileSelector: (profile) => {
145-
if (!Object.prototype.hasOwnProperty.call(profile, NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME))
146-
return undefined;
147-
if (profile[NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME] === "true") return true;
148-
if (profile[NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME] === "false") return false;
149-
throw new Error(
150-
`Cannot load shared config entry ${NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME}. Expected "true" or "false", got ${profile[NODE_DISABLE_MULTIREGION_ACCESS_POINT_INI_NAME]}.`
151-
);
152-
},
153-
default: false,
154-
};

packages/middleware-bucket-endpoint/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export * from "./NodeDisableMultiregionAccessPointConfigOptions";
2+
export * from "./NodeUseArnRegionConfigOptions";
13
export * from "./bucketEndpointMiddleware";
24
export * from "./bucketHostname";
35
export * from "./configurations";

0 commit comments

Comments
 (0)