@aws-sdk/middleware-endpoint-discovery
Advanced tools
Comparing version 3.178.0 to 3.183.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03) | ||
### Bug Fixes | ||
* **endpoint-discovery:** delete failed cache entry in blocking operations ([#4011](https://github.com/aws/aws-sdk-js-v3/issues/4011)) ([c96ac94](https://github.com/aws/aws-sdk-js-v3/commit/c96ac9418a22687b867077e7d72b5d353d37778c)) | ||
# [3.178.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.177.0...v3.178.0) (2022-09-23) | ||
@@ -8,0 +19,0 @@ |
@@ -42,6 +42,3 @@ "use strict"; | ||
.catch((error) => { | ||
var _a; | ||
if (error.name === "InvalidEndpointException" || ((_a = error.$metadata) === null || _a === void 0 ? void 0 : _a.httpStatusCode) === 421) { | ||
endpointCache.delete(cacheKey); | ||
} | ||
endpointCache.delete(cacheKey); | ||
const errorToThrow = Object.assign(new Error(`The operation to discover endpoint failed.` + | ||
@@ -48,0 +45,0 @@ ` Please retry, or provide a custom endpoint and disable endpoint discovery to proceed.`), { reason: error }); |
@@ -1,12 +0,12 @@ | ||
var ENV_ENDPOINT_DISCOVERY = ["AWS_ENABLE_ENDPOINT_DISCOVERY", "AWS_ENDPOINT_DISCOVERY_ENABLED"]; | ||
var CONFIG_ENDPOINT_DISCOVERY = "endpoint_discovery_enabled"; | ||
var isFalsy = function (value) { return ["false", "0"].indexOf(value) >= 0; }; | ||
export var NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS = { | ||
environmentVariableSelector: function (env) { | ||
for (var i = 0; i < ENV_ENDPOINT_DISCOVERY.length; i++) { | ||
var envKey = ENV_ENDPOINT_DISCOVERY[i]; | ||
const ENV_ENDPOINT_DISCOVERY = ["AWS_ENABLE_ENDPOINT_DISCOVERY", "AWS_ENDPOINT_DISCOVERY_ENABLED"]; | ||
const CONFIG_ENDPOINT_DISCOVERY = "endpoint_discovery_enabled"; | ||
const isFalsy = (value) => ["false", "0"].indexOf(value) >= 0; | ||
export const NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS = { | ||
environmentVariableSelector: (env) => { | ||
for (let i = 0; i < ENV_ENDPOINT_DISCOVERY.length; i++) { | ||
const envKey = ENV_ENDPOINT_DISCOVERY[i]; | ||
if (envKey in env) { | ||
var value = env[envKey]; | ||
const value = env[envKey]; | ||
if (value === "") { | ||
throw Error("Environment variable ".concat(envKey, " can't be empty of undefined, got \"").concat(value, "\"")); | ||
throw Error(`Environment variable ${envKey} can't be empty of undefined, got "${value}"`); | ||
} | ||
@@ -17,7 +17,7 @@ return !isFalsy(value); | ||
}, | ||
configFileSelector: function (profile) { | ||
configFileSelector: (profile) => { | ||
if (CONFIG_ENDPOINT_DISCOVERY in profile) { | ||
var value = profile[CONFIG_ENDPOINT_DISCOVERY]; | ||
const value = profile[CONFIG_ENDPOINT_DISCOVERY]; | ||
if (value === undefined) { | ||
throw Error("Shared config entry ".concat(CONFIG_ENDPOINT_DISCOVERY, " can't be undefined, got \"").concat(value, "\"")); | ||
throw Error(`Shared config entry ${CONFIG_ENDPOINT_DISCOVERY} can't be undefined, got "${value}"`); | ||
} | ||
@@ -24,0 +24,0 @@ return !isFalsy(value); |
@@ -1,54 +0,44 @@ | ||
import { __assign, __awaiter, __generator } from "tslib"; | ||
import { HttpRequest } from "@aws-sdk/protocol-http"; | ||
import { getCacheKey } from "./getCacheKey"; | ||
import { updateDiscoveredEndpointInCache } from "./updateDiscoveredEndpointInCache"; | ||
export var endpointDiscoveryMiddleware = function (config, middlewareConfig) { | ||
return function (next, context) { | ||
return function (args) { return __awaiter(void 0, void 0, void 0, function () { | ||
var endpointDiscoveryCommandCtor, isDiscoveredEndpointRequired, identifiers, clientName, commandName, isEndpointDiscoveryEnabled, cacheKey, request, endpoint; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (config.isCustomEndpoint) { | ||
if (config.isClientEndpointDiscoveryEnabled) { | ||
throw new Error("Custom endpoint is supplied; endpointDiscoveryEnabled must not be true."); | ||
} | ||
return [2, next(args)]; | ||
} | ||
endpointDiscoveryCommandCtor = config.endpointDiscoveryCommandCtor; | ||
isDiscoveredEndpointRequired = middlewareConfig.isDiscoveredEndpointRequired, identifiers = middlewareConfig.identifiers; | ||
clientName = context.clientName, commandName = context.commandName; | ||
return [4, config.endpointDiscoveryEnabled()]; | ||
case 1: | ||
isEndpointDiscoveryEnabled = _a.sent(); | ||
return [4, getCacheKey(commandName, config, { identifiers: identifiers })]; | ||
case 2: | ||
cacheKey = _a.sent(); | ||
if (!isDiscoveredEndpointRequired) return [3, 4]; | ||
if (isEndpointDiscoveryEnabled === false) { | ||
throw new Error("Endpoint Discovery is disabled but ".concat(commandName, " on ").concat(clientName, " requires it.") + | ||
" Please check your configurations."); | ||
} | ||
return [4, updateDiscoveredEndpointInCache(config, __assign(__assign({}, middlewareConfig), { commandName: commandName, cacheKey: cacheKey, endpointDiscoveryCommandCtor: endpointDiscoveryCommandCtor }))]; | ||
case 3: | ||
_a.sent(); | ||
return [3, 5]; | ||
case 4: | ||
if (isEndpointDiscoveryEnabled) { | ||
updateDiscoveredEndpointInCache(config, __assign(__assign({}, middlewareConfig), { commandName: commandName, cacheKey: cacheKey, endpointDiscoveryCommandCtor: endpointDiscoveryCommandCtor })); | ||
} | ||
_a.label = 5; | ||
case 5: | ||
request = args.request; | ||
if (cacheKey && HttpRequest.isInstance(request)) { | ||
endpoint = config.endpointCache.getEndpoint(cacheKey); | ||
if (endpoint) { | ||
request.hostname = endpoint; | ||
} | ||
} | ||
return [2, next(args)]; | ||
} | ||
}); | ||
}); }; | ||
}; | ||
export const endpointDiscoveryMiddleware = (config, middlewareConfig) => (next, context) => async (args) => { | ||
if (config.isCustomEndpoint) { | ||
if (config.isClientEndpointDiscoveryEnabled) { | ||
throw new Error(`Custom endpoint is supplied; endpointDiscoveryEnabled must not be true.`); | ||
} | ||
return next(args); | ||
} | ||
const { endpointDiscoveryCommandCtor } = config; | ||
const { isDiscoveredEndpointRequired, identifiers } = middlewareConfig; | ||
const { clientName, commandName } = context; | ||
const isEndpointDiscoveryEnabled = await config.endpointDiscoveryEnabled(); | ||
const cacheKey = await getCacheKey(commandName, config, { identifiers }); | ||
if (isDiscoveredEndpointRequired) { | ||
if (isEndpointDiscoveryEnabled === false) { | ||
throw new Error(`Endpoint Discovery is disabled but ${commandName} on ${clientName} requires it.` + | ||
` Please check your configurations.`); | ||
} | ||
await updateDiscoveredEndpointInCache(config, { | ||
...middlewareConfig, | ||
commandName, | ||
cacheKey, | ||
endpointDiscoveryCommandCtor, | ||
}); | ||
} | ||
else if (isEndpointDiscoveryEnabled) { | ||
updateDiscoveredEndpointInCache(config, { | ||
...middlewareConfig, | ||
commandName, | ||
cacheKey, | ||
endpointDiscoveryCommandCtor, | ||
}); | ||
} | ||
const { request } = args; | ||
if (cacheKey && HttpRequest.isInstance(request)) { | ||
const endpoint = config.endpointCache.getEndpoint(cacheKey); | ||
if (endpoint) { | ||
request.hostname = endpoint; | ||
} | ||
} | ||
return next(args); | ||
}; |
@@ -1,22 +0,13 @@ | ||
import { __assign, __awaiter, __generator, __read } from "tslib"; | ||
export var getCacheKey = function (commandName, config, options) { return __awaiter(void 0, void 0, void 0, function () { | ||
var accessKeyId, identifiers; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, config.credentials()]; | ||
case 1: | ||
accessKeyId = (_a.sent()).accessKeyId; | ||
identifiers = options.identifiers; | ||
return [2, JSON.stringify(__assign(__assign({}, (accessKeyId && { accessKeyId: accessKeyId })), (identifiers && { | ||
commandName: commandName, | ||
identifiers: Object.entries(identifiers) | ||
.sort() | ||
.reduce(function (acc, _a) { | ||
var _b; | ||
var _c = __read(_a, 2), key = _c[0], value = _c[1]; | ||
return (__assign(__assign({}, acc), (_b = {}, _b[key] = value, _b))); | ||
}, {}), | ||
})))]; | ||
} | ||
export const getCacheKey = async (commandName, config, options) => { | ||
const { accessKeyId } = await config.credentials(); | ||
const { identifiers } = options; | ||
return JSON.stringify({ | ||
...(accessKeyId && { accessKeyId }), | ||
...(identifiers && { | ||
commandName, | ||
identifiers: Object.entries(identifiers) | ||
.sort() | ||
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}), | ||
}), | ||
}); | ||
}); }; | ||
}; |
@@ -1,4 +0,3 @@ | ||
import { __assign } from "tslib"; | ||
import { endpointDiscoveryMiddleware } from "./endpointDiscoveryMiddleware"; | ||
export var endpointDiscoveryMiddlewareOptions = { | ||
export const endpointDiscoveryMiddlewareOptions = { | ||
name: "endpointDiscoveryMiddleware", | ||
@@ -9,16 +8,16 @@ step: "build", | ||
}; | ||
export var getEndpointDiscoveryPlugin = function (pluginConfig, middlewareConfig) { return ({ | ||
applyToStack: function (commandStack) { | ||
export const getEndpointDiscoveryPlugin = (pluginConfig, middlewareConfig) => ({ | ||
applyToStack: (commandStack) => { | ||
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, middlewareConfig), endpointDiscoveryMiddlewareOptions); | ||
}, | ||
}); }; | ||
export var getEndpointDiscoveryRequiredPlugin = function (pluginConfig, middlewareConfig) { return ({ | ||
applyToStack: function (commandStack) { | ||
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, __assign(__assign({}, middlewareConfig), { isDiscoveredEndpointRequired: true })), endpointDiscoveryMiddlewareOptions); | ||
}); | ||
export const getEndpointDiscoveryRequiredPlugin = (pluginConfig, middlewareConfig) => ({ | ||
applyToStack: (commandStack) => { | ||
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, { ...middlewareConfig, isDiscoveredEndpointRequired: true }), endpointDiscoveryMiddlewareOptions); | ||
}, | ||
}); }; | ||
export var getEndpointDiscoveryOptionalPlugin = function (pluginConfig, middlewareConfig) { return ({ | ||
applyToStack: function (commandStack) { | ||
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, __assign(__assign({}, middlewareConfig), { isDiscoveredEndpointRequired: false })), endpointDiscoveryMiddlewareOptions); | ||
}); | ||
export const getEndpointDiscoveryOptionalPlugin = (pluginConfig, middlewareConfig) => ({ | ||
applyToStack: (commandStack) => { | ||
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, { ...middlewareConfig, isDiscoveredEndpointRequired: false }), endpointDiscoveryMiddlewareOptions); | ||
}, | ||
}); }; | ||
}); |
@@ -1,9 +0,10 @@ | ||
import { __assign } from "tslib"; | ||
import { EndpointCache } from "@aws-sdk/endpoint-cache"; | ||
export var resolveEndpointDiscoveryConfig = function (input, _a) { | ||
var _b; | ||
var endpointDiscoveryCommandCtor = _a.endpointDiscoveryCommandCtor; | ||
return (__assign(__assign({}, input), { endpointDiscoveryCommandCtor: endpointDiscoveryCommandCtor, endpointCache: new EndpointCache((_b = input.endpointCacheSize) !== null && _b !== void 0 ? _b : 1000), endpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined | ||
? function () { return Promise.resolve(input.endpointDiscoveryEnabled); } | ||
: input.endpointDiscoveryEnabledProvider, isClientEndpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined })); | ||
}; | ||
export const resolveEndpointDiscoveryConfig = (input, { endpointDiscoveryCommandCtor }) => ({ | ||
...input, | ||
endpointDiscoveryCommandCtor, | ||
endpointCache: new EndpointCache(input.endpointCacheSize ?? 1000), | ||
endpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined | ||
? () => Promise.resolve(input.endpointDiscoveryEnabled) | ||
: input.endpointDiscoveryEnabledProvider, | ||
isClientEndpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined, | ||
}); |
@@ -1,67 +0,57 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
var requestQueue = {}; | ||
export var updateDiscoveredEndpointInCache = function (config, options) { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2, new Promise(function (resolve, reject) { | ||
var endpointCache = config.endpointCache; | ||
var cacheKey = options.cacheKey, commandName = options.commandName, identifiers = options.identifiers; | ||
var endpoints = endpointCache.get(cacheKey); | ||
if (endpoints && endpoints.length === 1 && endpoints[0].Address === "") { | ||
if (options.isDiscoveredEndpointRequired) { | ||
if (!requestQueue[cacheKey]) | ||
requestQueue[cacheKey] = []; | ||
requestQueue[cacheKey].push({ resolve: resolve, reject: reject }); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
} | ||
else if (endpoints && endpoints.length > 0) { | ||
const requestQueue = {}; | ||
export const updateDiscoveredEndpointInCache = async (config, options) => new Promise((resolve, reject) => { | ||
const { endpointCache } = config; | ||
const { cacheKey, commandName, identifiers } = options; | ||
const endpoints = endpointCache.get(cacheKey); | ||
if (endpoints && endpoints.length === 1 && endpoints[0].Address === "") { | ||
if (options.isDiscoveredEndpointRequired) { | ||
if (!requestQueue[cacheKey]) | ||
requestQueue[cacheKey] = []; | ||
requestQueue[cacheKey].push({ resolve, reject }); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
} | ||
else if (endpoints && endpoints.length > 0) { | ||
resolve(); | ||
} | ||
else { | ||
const placeholderEndpoints = [{ Address: "", CachePeriodInMinutes: 1 }]; | ||
endpointCache.set(cacheKey, placeholderEndpoints); | ||
const command = new options.endpointDiscoveryCommandCtor({ | ||
Operation: commandName.slice(0, -7), | ||
Identifiers: identifiers, | ||
}); | ||
const handler = command.resolveMiddleware(options.clientStack, config, options.options); | ||
handler(command) | ||
.then((result) => { | ||
endpointCache.set(cacheKey, result.output.Endpoints); | ||
if (requestQueue[cacheKey]) { | ||
requestQueue[cacheKey].forEach(({ resolve }) => { | ||
resolve(); | ||
} | ||
else { | ||
var placeholderEndpoints_1 = [{ Address: "", CachePeriodInMinutes: 1 }]; | ||
endpointCache.set(cacheKey, placeholderEndpoints_1); | ||
var command = new options.endpointDiscoveryCommandCtor({ | ||
Operation: commandName.slice(0, -7), | ||
Identifiers: identifiers, | ||
}); | ||
var handler = command.resolveMiddleware(options.clientStack, config, options.options); | ||
handler(command) | ||
.then(function (result) { | ||
endpointCache.set(cacheKey, result.output.Endpoints); | ||
if (requestQueue[cacheKey]) { | ||
requestQueue[cacheKey].forEach(function (_a) { | ||
var resolve = _a.resolve; | ||
resolve(); | ||
}); | ||
delete requestQueue[cacheKey]; | ||
} | ||
resolve(); | ||
}) | ||
.catch(function (error) { | ||
var _a; | ||
if (error.name === "InvalidEndpointException" || ((_a = error.$metadata) === null || _a === void 0 ? void 0 : _a.httpStatusCode) === 421) { | ||
endpointCache.delete(cacheKey); | ||
} | ||
var errorToThrow = Object.assign(new Error("The operation to discover endpoint failed." + | ||
" Please retry, or provide a custom endpoint and disable endpoint discovery to proceed."), { reason: error }); | ||
if (requestQueue[cacheKey]) { | ||
requestQueue[cacheKey].forEach(function (_a) { | ||
var reject = _a.reject; | ||
reject(errorToThrow); | ||
}); | ||
delete requestQueue[cacheKey]; | ||
} | ||
if (options.isDiscoveredEndpointRequired) { | ||
reject(errorToThrow); | ||
} | ||
else { | ||
endpointCache.set(cacheKey, placeholderEndpoints_1); | ||
resolve(); | ||
} | ||
}); | ||
} | ||
})]; | ||
}); | ||
}); }; | ||
}); | ||
delete requestQueue[cacheKey]; | ||
} | ||
resolve(); | ||
}) | ||
.catch((error) => { | ||
endpointCache.delete(cacheKey); | ||
const errorToThrow = Object.assign(new Error(`The operation to discover endpoint failed.` + | ||
` Please retry, or provide a custom endpoint and disable endpoint discovery to proceed.`), { reason: error }); | ||
if (requestQueue[cacheKey]) { | ||
requestQueue[cacheKey].forEach(({ reject }) => { | ||
reject(errorToThrow); | ||
}); | ||
delete requestQueue[cacheKey]; | ||
} | ||
if (options.isDiscoveredEndpointRequired) { | ||
reject(errorToThrow); | ||
} | ||
else { | ||
endpointCache.set(cacheKey, placeholderEndpoints); | ||
resolve(); | ||
} | ||
}); | ||
} | ||
}); |
{ | ||
"name": "@aws-sdk/middleware-endpoint-discovery", | ||
"version": "3.178.0", | ||
"version": "3.183.0", | ||
"scripts": { | ||
@@ -23,3 +23,3 @@ "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'", | ||
"devDependencies": { | ||
"@aws-sdk/node-config-provider": "3.178.0", | ||
"@aws-sdk/node-config-provider": "3.183.0", | ||
"@tsconfig/recommended": "1.0.1", | ||
@@ -33,6 +33,6 @@ "concurrently": "7.0.0", | ||
"dependencies": { | ||
"@aws-sdk/config-resolver": "3.178.0", | ||
"@aws-sdk/endpoint-cache": "3.170.0", | ||
"@aws-sdk/protocol-http": "3.178.0", | ||
"@aws-sdk/types": "3.178.0", | ||
"@aws-sdk/config-resolver": "3.183.0", | ||
"@aws-sdk/endpoint-cache": "3.183.0", | ||
"@aws-sdk/protocol-http": "3.183.0", | ||
"@aws-sdk/types": "3.183.0", | ||
"tslib": "^2.3.1" | ||
@@ -39,0 +39,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
50969
596
+ Added@aws-sdk/config-resolver@3.183.0(transitive)
+ Added@aws-sdk/endpoint-cache@3.183.0(transitive)
+ Added@aws-sdk/is-array-buffer@3.183.0(transitive)
+ Added@aws-sdk/protocol-http@3.183.0(transitive)
+ Added@aws-sdk/signature-v4@3.183.0(transitive)
+ Added@aws-sdk/types@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/endpoint-cache@3.170.0(transitive)
- Removed@aws-sdk/is-array-buffer@3.170.0(transitive)
- Removed@aws-sdk/protocol-http@3.178.0(transitive)
- Removed@aws-sdk/signature-v4@3.178.0(transitive)
- Removed@aws-sdk/types@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