@aws-sdk/util-defaults-mode-node
Advanced tools
Comparing version 3.180.0 to 3.183.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03) | ||
**Note:** Version bump only for package @aws-sdk/util-defaults-mode-node | ||
# [3.180.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.179.0...v3.180.0) (2022-09-27) | ||
@@ -8,0 +16,0 @@ |
@@ -1,6 +0,6 @@ | ||
export var AWS_EXECUTION_ENV = "AWS_EXECUTION_ENV"; | ||
export var AWS_REGION_ENV = "AWS_REGION"; | ||
export var AWS_DEFAULT_REGION_ENV = "AWS_DEFAULT_REGION"; | ||
export var ENV_IMDS_DISABLED = "AWS_EC2_METADATA_DISABLED"; | ||
export var DEFAULTS_MODE_OPTIONS = ["in-region", "cross-region", "mobile", "standard", "legacy"]; | ||
export var IMDS_REGION_PATH = "/latest/meta-data/placement/region"; | ||
export const AWS_EXECUTION_ENV = "AWS_EXECUTION_ENV"; | ||
export const AWS_REGION_ENV = "AWS_REGION"; | ||
export const AWS_DEFAULT_REGION_ENV = "AWS_DEFAULT_REGION"; | ||
export const ENV_IMDS_DISABLED = "AWS_EC2_METADATA_DISABLED"; | ||
export const DEFAULTS_MODE_OPTIONS = ["in-region", "cross-region", "mobile", "standard", "legacy"]; | ||
export const IMDS_REGION_PATH = "/latest/meta-data/placement/region"; |
@@ -1,8 +0,8 @@ | ||
var AWS_DEFAULTS_MODE_ENV = "AWS_DEFAULTS_MODE"; | ||
var AWS_DEFAULTS_MODE_CONFIG = "defaults_mode"; | ||
export var NODE_DEFAULTS_MODE_CONFIG_OPTIONS = { | ||
environmentVariableSelector: function (env) { | ||
const AWS_DEFAULTS_MODE_ENV = "AWS_DEFAULTS_MODE"; | ||
const AWS_DEFAULTS_MODE_CONFIG = "defaults_mode"; | ||
export const NODE_DEFAULTS_MODE_CONFIG_OPTIONS = { | ||
environmentVariableSelector: (env) => { | ||
return env[AWS_DEFAULTS_MODE_ENV]; | ||
}, | ||
configFileSelector: function (profile) { | ||
configFileSelector: (profile) => { | ||
return profile[AWS_DEFAULTS_MODE_CONFIG]; | ||
@@ -9,0 +9,0 @@ }, |
@@ -1,2 +0,1 @@ | ||
import { __assign, __awaiter, __generator } from "tslib"; | ||
import { NODE_REGION_CONFIG_OPTIONS } from "@aws-sdk/config-resolver"; | ||
@@ -8,95 +7,47 @@ import { getInstanceMetadataEndpoint, httpRequest } from "@aws-sdk/credential-provider-imds"; | ||
import { NODE_DEFAULTS_MODE_CONFIG_OPTIONS } from "./defaultsModeConfig"; | ||
export var resolveDefaultsModeConfig = function (_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.region, region = _c === void 0 ? loadConfig(NODE_REGION_CONFIG_OPTIONS) : _c, _d = _b.defaultsMode, defaultsMode = _d === void 0 ? loadConfig(NODE_DEFAULTS_MODE_CONFIG_OPTIONS) : _d; | ||
return memoize(function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var mode, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!(typeof defaultsMode === "function")) return [3, 2]; | ||
return [4, defaultsMode()]; | ||
case 1: | ||
_a = _b.sent(); | ||
return [3, 3]; | ||
case 2: | ||
_a = defaultsMode; | ||
_b.label = 3; | ||
case 3: | ||
mode = _a; | ||
switch (mode === null || mode === void 0 ? void 0 : mode.toLowerCase()) { | ||
case "auto": | ||
return [2, resolveNodeDefaultsModeAuto(region)]; | ||
case "in-region": | ||
case "cross-region": | ||
case "mobile": | ||
case "standard": | ||
case "legacy": | ||
return [2, Promise.resolve(mode === null || mode === void 0 ? void 0 : mode.toLocaleLowerCase())]; | ||
case undefined: | ||
return [2, Promise.resolve("legacy")]; | ||
default: | ||
throw new Error("Invalid parameter for \"defaultsMode\", expect ".concat(DEFAULTS_MODE_OPTIONS.join(", "), ", got ").concat(mode)); | ||
} | ||
return [2]; | ||
} | ||
}); | ||
}); }); | ||
export const resolveDefaultsModeConfig = ({ region = loadConfig(NODE_REGION_CONFIG_OPTIONS), defaultsMode = loadConfig(NODE_DEFAULTS_MODE_CONFIG_OPTIONS), } = {}) => memoize(async () => { | ||
const mode = typeof defaultsMode === "function" ? await defaultsMode() : defaultsMode; | ||
switch (mode?.toLowerCase()) { | ||
case "auto": | ||
return resolveNodeDefaultsModeAuto(region); | ||
case "in-region": | ||
case "cross-region": | ||
case "mobile": | ||
case "standard": | ||
case "legacy": | ||
return Promise.resolve(mode?.toLocaleLowerCase()); | ||
case undefined: | ||
return Promise.resolve("legacy"); | ||
default: | ||
throw new Error(`Invalid parameter for "defaultsMode", expect ${DEFAULTS_MODE_OPTIONS.join(", ")}, got ${mode}`); | ||
} | ||
}); | ||
const resolveNodeDefaultsModeAuto = async (clientRegion) => { | ||
if (clientRegion) { | ||
const resolvedRegion = typeof clientRegion === "function" ? await clientRegion() : clientRegion; | ||
const inferredRegion = await inferPhysicalRegion(); | ||
if (!inferredRegion) { | ||
return "standard"; | ||
} | ||
if (resolvedRegion === inferredRegion) { | ||
return "in-region"; | ||
} | ||
else { | ||
return "cross-region"; | ||
} | ||
} | ||
return "standard"; | ||
}; | ||
var resolveNodeDefaultsModeAuto = function (clientRegion) { return __awaiter(void 0, void 0, void 0, function () { | ||
var resolvedRegion, _a, inferredRegion; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!clientRegion) return [3, 5]; | ||
if (!(typeof clientRegion === "function")) return [3, 2]; | ||
return [4, clientRegion()]; | ||
case 1: | ||
_a = _b.sent(); | ||
return [3, 3]; | ||
case 2: | ||
_a = clientRegion; | ||
_b.label = 3; | ||
case 3: | ||
resolvedRegion = _a; | ||
return [4, inferPhysicalRegion()]; | ||
case 4: | ||
inferredRegion = _b.sent(); | ||
if (!inferredRegion) { | ||
return [2, "standard"]; | ||
} | ||
if (resolvedRegion === inferredRegion) { | ||
return [2, "in-region"]; | ||
} | ||
else { | ||
return [2, "cross-region"]; | ||
} | ||
_b.label = 5; | ||
case 5: return [2, "standard"]; | ||
const inferPhysicalRegion = async () => { | ||
if (process.env[AWS_EXECUTION_ENV] && (process.env[AWS_REGION_ENV] || process.env[AWS_DEFAULT_REGION_ENV])) { | ||
return process.env[AWS_REGION_ENV] ?? process.env[AWS_DEFAULT_REGION_ENV]; | ||
} | ||
if (!process.env[ENV_IMDS_DISABLED]) { | ||
try { | ||
const endpoint = await getInstanceMetadataEndpoint(); | ||
return (await httpRequest({ ...endpoint, path: IMDS_REGION_PATH })).toString(); | ||
} | ||
}); | ||
}); }; | ||
var inferPhysicalRegion = function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var endpoint, e_1; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (process.env[AWS_EXECUTION_ENV] && (process.env[AWS_REGION_ENV] || process.env[AWS_DEFAULT_REGION_ENV])) { | ||
return [2, (_a = process.env[AWS_REGION_ENV]) !== null && _a !== void 0 ? _a : process.env[AWS_DEFAULT_REGION_ENV]]; | ||
} | ||
if (!!process.env[ENV_IMDS_DISABLED]) return [3, 5]; | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 4, , 5]); | ||
return [4, getInstanceMetadataEndpoint()]; | ||
case 2: | ||
endpoint = _b.sent(); | ||
return [4, httpRequest(__assign(__assign({}, endpoint), { path: IMDS_REGION_PATH }))]; | ||
case 3: return [2, (_b.sent()).toString()]; | ||
case 4: | ||
e_1 = _b.sent(); | ||
return [3, 5]; | ||
case 5: return [2]; | ||
catch (e) { | ||
} | ||
}); | ||
}); }; | ||
} | ||
}; |
{ | ||
"name": "@aws-sdk/util-defaults-mode-node", | ||
"version": "3.180.0", | ||
"version": "3.183.0", | ||
"scripts": { | ||
@@ -22,11 +22,11 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", | ||
"dependencies": { | ||
"@aws-sdk/config-resolver": "3.178.0", | ||
"@aws-sdk/credential-provider-imds": "3.178.0", | ||
"@aws-sdk/node-config-provider": "3.178.0", | ||
"@aws-sdk/property-provider": "3.178.0", | ||
"@aws-sdk/types": "3.178.0", | ||
"@aws-sdk/config-resolver": "3.183.0", | ||
"@aws-sdk/credential-provider-imds": "3.183.0", | ||
"@aws-sdk/node-config-provider": "3.183.0", | ||
"@aws-sdk/property-provider": "3.183.0", | ||
"@aws-sdk/types": "3.183.0", | ||
"tslib": "^2.3.1" | ||
}, | ||
"devDependencies": { | ||
"@aws-sdk/smithy-client": "3.180.0", | ||
"@aws-sdk/smithy-client": "3.183.0", | ||
"@tsconfig/recommended": "1.0.1", | ||
@@ -33,0 +33,0 @@ "@types/node": "^10.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30020
202
+ Added@aws-sdk/config-resolver@3.183.0(transitive)
+ Added@aws-sdk/credential-provider-imds@3.183.0(transitive)
+ Added@aws-sdk/is-array-buffer@3.183.0(transitive)
+ Added@aws-sdk/node-config-provider@3.183.0(transitive)
+ Added@aws-sdk/property-provider@3.183.0(transitive)
+ Added@aws-sdk/querystring-parser@3.183.0(transitive)
+ Added@aws-sdk/shared-ini-file-loader@3.183.0(transitive)
+ Added@aws-sdk/signature-v4@3.183.0(transitive)
+ Added@aws-sdk/types@3.183.0(transitive)
+ Added@aws-sdk/url-parser@3.183.0(transitive)
+ Added@aws-sdk/util-config-provider@3.183.0(transitive)
+ Added@aws-sdk/util-hex-encoding@3.183.0(transitive)
+ Added@aws-sdk/util-middleware@3.183.0(transitive)
+ Added@aws-sdk/util-uri-escape@3.183.0(transitive)
- Removed@aws-sdk/config-resolver@3.178.0(transitive)
- Removed@aws-sdk/credential-provider-imds@3.178.0(transitive)
- Removed@aws-sdk/is-array-buffer@3.170.0(transitive)
- Removed@aws-sdk/node-config-provider@3.178.0(transitive)
- Removed@aws-sdk/property-provider@3.178.0(transitive)
- Removed@aws-sdk/querystring-parser@3.178.0(transitive)
- Removed@aws-sdk/shared-ini-file-loader@3.178.0(transitive)
- Removed@aws-sdk/signature-v4@3.178.0(transitive)
- Removed@aws-sdk/types@3.178.0(transitive)
- Removed@aws-sdk/url-parser@3.178.0(transitive)
- Removed@aws-sdk/util-config-provider@3.170.0(transitive)
- Removed@aws-sdk/util-hex-encoding@3.170.0(transitive)
- Removed@aws-sdk/util-middleware@3.178.0(transitive)
- Removed@aws-sdk/util-uri-escape@3.170.0(transitive)
Updated@aws-sdk/types@3.183.0