Backend half
This commit is contained in:
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
export const getAwsRegionExtensionConfiguration = (runtimeConfig) => {
|
||||
return {
|
||||
setRegion(region) {
|
||||
runtimeConfig.region = region;
|
||||
},
|
||||
region() {
|
||||
return runtimeConfig.region;
|
||||
},
|
||||
};
|
||||
};
|
||||
export const resolveAwsRegionExtensionConfiguration = (awsRegionExtensionConfiguration) => {
|
||||
return {
|
||||
region: awsRegionExtensionConfiguration.region(),
|
||||
};
|
||||
};
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./extensions";
|
||||
export * from "./regionConfig";
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
export const REGION_ENV_NAME = "AWS_REGION";
|
||||
export const REGION_INI_NAME = "region";
|
||||
export const NODE_REGION_CONFIG_OPTIONS = {
|
||||
environmentVariableSelector: (env) => env[REGION_ENV_NAME],
|
||||
configFileSelector: (profile) => profile[REGION_INI_NAME],
|
||||
default: () => {
|
||||
throw new Error("Region is missing");
|
||||
},
|
||||
};
|
||||
export const NODE_REGION_CONFIG_FILE_OPTIONS = {
|
||||
preferredFile: "credentials",
|
||||
};
|
||||
Generated
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
import { isFipsRegion } from "./isFipsRegion";
|
||||
export const getRealRegion = (region) => isFipsRegion(region)
|
||||
? ["fips-aws-global", "aws-fips"].includes(region)
|
||||
? "us-east-1"
|
||||
: region.replace(/fips-(dkr-|prod-)?|-fips/, "")
|
||||
: region;
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./config";
|
||||
export * from "./resolveRegionConfig";
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export const isFipsRegion = (region) => typeof region === "string" && (region.startsWith("fips-") || region.endsWith("-fips"));
|
||||
Generated
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
import { getRealRegion } from "./getRealRegion";
|
||||
import { isFipsRegion } from "./isFipsRegion";
|
||||
export const resolveRegionConfig = (input) => {
|
||||
const { region, useFipsEndpoint } = input;
|
||||
if (!region) {
|
||||
throw new Error("Region is missing");
|
||||
}
|
||||
return Object.assign(input, {
|
||||
region: async () => {
|
||||
if (typeof region === "string") {
|
||||
return getRealRegion(region);
|
||||
}
|
||||
const providedRegion = await region();
|
||||
return getRealRegion(providedRegion);
|
||||
},
|
||||
useFipsEndpoint: async () => {
|
||||
const providedRegion = typeof region === "string" ? region : await region();
|
||||
if (isFipsRegion(providedRegion)) {
|
||||
return true;
|
||||
}
|
||||
return typeof useFipsEndpoint !== "function" ? Promise.resolve(!!useFipsEndpoint) : useFipsEndpoint();
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user