@aws-sdk/middleware-endpoint-discovery 3.183.0 → 3.186.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist-es/configurations.js +12 -12
- package/dist-es/endpointDiscoveryMiddleware.js +50 -40
- package/dist-es/getCacheKey.js +21 -12
- package/dist-es/getEndpointDiscoveryPlugin.js +13 -12
- package/dist-es/resolveEndpointDiscoveryConfig.js +8 -9
- package/dist-es/updateDiscoveredEndpointInCache.js +63 -56
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @aws-sdk/middleware-endpoint-discovery
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)
|
|
7
15
|
|
|
8
16
|
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
environmentVariableSelector: (env)
|
|
6
|
-
for (
|
|
7
|
-
|
|
1
|
+
var ENV_ENDPOINT_DISCOVERY = ["AWS_ENABLE_ENDPOINT_DISCOVERY", "AWS_ENDPOINT_DISCOVERY_ENABLED"];
|
|
2
|
+
var CONFIG_ENDPOINT_DISCOVERY = "endpoint_discovery_enabled";
|
|
3
|
+
var isFalsy = function (value) { return ["false", "0"].indexOf(value) >= 0; };
|
|
4
|
+
export var NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS = {
|
|
5
|
+
environmentVariableSelector: function (env) {
|
|
6
|
+
for (var i = 0; i < ENV_ENDPOINT_DISCOVERY.length; i++) {
|
|
7
|
+
var envKey = ENV_ENDPOINT_DISCOVERY[i];
|
|
8
8
|
if (envKey in env) {
|
|
9
|
-
|
|
9
|
+
var value = env[envKey];
|
|
10
10
|
if (value === "") {
|
|
11
|
-
throw Error(
|
|
11
|
+
throw Error("Environment variable ".concat(envKey, " can't be empty of undefined, got \"").concat(value, "\""));
|
|
12
12
|
}
|
|
13
13
|
return !isFalsy(value);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
-
configFileSelector: (profile)
|
|
17
|
+
configFileSelector: function (profile) {
|
|
18
18
|
if (CONFIG_ENDPOINT_DISCOVERY in profile) {
|
|
19
|
-
|
|
19
|
+
var value = profile[CONFIG_ENDPOINT_DISCOVERY];
|
|
20
20
|
if (value === undefined) {
|
|
21
|
-
throw Error(
|
|
21
|
+
throw Error("Shared config entry ".concat(CONFIG_ENDPOINT_DISCOVERY, " can't be undefined, got \"").concat(value, "\""));
|
|
22
22
|
}
|
|
23
23
|
return !isFalsy(value);
|
|
24
24
|
}
|
|
@@ -1,44 +1,54 @@
|
|
|
1
|
+
import { __assign, __awaiter, __generator } from "tslib";
|
|
1
2
|
import { HttpRequest } from "@aws-sdk/protocol-http";
|
|
2
3
|
import { getCacheKey } from "./getCacheKey";
|
|
3
4
|
import { updateDiscoveredEndpointInCache } from "./updateDiscoveredEndpointInCache";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
5
|
+
export var endpointDiscoveryMiddleware = function (config, middlewareConfig) {
|
|
6
|
+
return function (next, context) {
|
|
7
|
+
return function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
|
8
|
+
var endpointDiscoveryCommandCtor, isDiscoveredEndpointRequired, identifiers, clientName, commandName, isEndpointDiscoveryEnabled, cacheKey, request, endpoint;
|
|
9
|
+
return __generator(this, function (_a) {
|
|
10
|
+
switch (_a.label) {
|
|
11
|
+
case 0:
|
|
12
|
+
if (config.isCustomEndpoint) {
|
|
13
|
+
if (config.isClientEndpointDiscoveryEnabled) {
|
|
14
|
+
throw new Error("Custom endpoint is supplied; endpointDiscoveryEnabled must not be true.");
|
|
15
|
+
}
|
|
16
|
+
return [2, next(args)];
|
|
17
|
+
}
|
|
18
|
+
endpointDiscoveryCommandCtor = config.endpointDiscoveryCommandCtor;
|
|
19
|
+
isDiscoveredEndpointRequired = middlewareConfig.isDiscoveredEndpointRequired, identifiers = middlewareConfig.identifiers;
|
|
20
|
+
clientName = context.clientName, commandName = context.commandName;
|
|
21
|
+
return [4, config.endpointDiscoveryEnabled()];
|
|
22
|
+
case 1:
|
|
23
|
+
isEndpointDiscoveryEnabled = _a.sent();
|
|
24
|
+
return [4, getCacheKey(commandName, config, { identifiers: identifiers })];
|
|
25
|
+
case 2:
|
|
26
|
+
cacheKey = _a.sent();
|
|
27
|
+
if (!isDiscoveredEndpointRequired) return [3, 4];
|
|
28
|
+
if (isEndpointDiscoveryEnabled === false) {
|
|
29
|
+
throw new Error("Endpoint Discovery is disabled but ".concat(commandName, " on ").concat(clientName, " requires it.") +
|
|
30
|
+
" Please check your configurations.");
|
|
31
|
+
}
|
|
32
|
+
return [4, updateDiscoveredEndpointInCache(config, __assign(__assign({}, middlewareConfig), { commandName: commandName, cacheKey: cacheKey, endpointDiscoveryCommandCtor: endpointDiscoveryCommandCtor }))];
|
|
33
|
+
case 3:
|
|
34
|
+
_a.sent();
|
|
35
|
+
return [3, 5];
|
|
36
|
+
case 4:
|
|
37
|
+
if (isEndpointDiscoveryEnabled) {
|
|
38
|
+
updateDiscoveredEndpointInCache(config, __assign(__assign({}, middlewareConfig), { commandName: commandName, cacheKey: cacheKey, endpointDiscoveryCommandCtor: endpointDiscoveryCommandCtor }));
|
|
39
|
+
}
|
|
40
|
+
_a.label = 5;
|
|
41
|
+
case 5:
|
|
42
|
+
request = args.request;
|
|
43
|
+
if (cacheKey && HttpRequest.isInstance(request)) {
|
|
44
|
+
endpoint = config.endpointCache.getEndpoint(cacheKey);
|
|
45
|
+
if (endpoint) {
|
|
46
|
+
request.hostname = endpoint;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return [2, next(args)];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}); };
|
|
53
|
+
};
|
|
44
54
|
};
|
package/dist-es/getCacheKey.js
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.
|
|
10
|
-
.
|
|
11
|
-
|
|
1
|
+
import { __assign, __awaiter, __generator, __read } from "tslib";
|
|
2
|
+
export var getCacheKey = function (commandName, config, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
3
|
+
var accessKeyId, identifiers;
|
|
4
|
+
return __generator(this, function (_a) {
|
|
5
|
+
switch (_a.label) {
|
|
6
|
+
case 0: return [4, config.credentials()];
|
|
7
|
+
case 1:
|
|
8
|
+
accessKeyId = (_a.sent()).accessKeyId;
|
|
9
|
+
identifiers = options.identifiers;
|
|
10
|
+
return [2, JSON.stringify(__assign(__assign({}, (accessKeyId && { accessKeyId: accessKeyId })), (identifiers && {
|
|
11
|
+
commandName: commandName,
|
|
12
|
+
identifiers: Object.entries(identifiers)
|
|
13
|
+
.sort()
|
|
14
|
+
.reduce(function (acc, _a) {
|
|
15
|
+
var _b;
|
|
16
|
+
var _c = __read(_a, 2), key = _c[0], value = _c[1];
|
|
17
|
+
return (__assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)));
|
|
18
|
+
}, {}),
|
|
19
|
+
})))];
|
|
20
|
+
}
|
|
12
21
|
});
|
|
13
|
-
};
|
|
22
|
+
}); };
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
1
2
|
import { endpointDiscoveryMiddleware } from "./endpointDiscoveryMiddleware";
|
|
2
|
-
export
|
|
3
|
+
export var endpointDiscoveryMiddlewareOptions = {
|
|
3
4
|
name: "endpointDiscoveryMiddleware",
|
|
4
5
|
step: "build",
|
|
5
6
|
tags: ["ENDPOINT_DISCOVERY"],
|
|
6
7
|
override: true,
|
|
7
8
|
};
|
|
8
|
-
export
|
|
9
|
-
applyToStack: (commandStack)
|
|
9
|
+
export var getEndpointDiscoveryPlugin = function (pluginConfig, middlewareConfig) { return ({
|
|
10
|
+
applyToStack: function (commandStack) {
|
|
10
11
|
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, middlewareConfig), endpointDiscoveryMiddlewareOptions);
|
|
11
12
|
},
|
|
12
|
-
});
|
|
13
|
-
export
|
|
14
|
-
applyToStack: (commandStack)
|
|
15
|
-
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, {
|
|
13
|
+
}); };
|
|
14
|
+
export var getEndpointDiscoveryRequiredPlugin = function (pluginConfig, middlewareConfig) { return ({
|
|
15
|
+
applyToStack: function (commandStack) {
|
|
16
|
+
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, __assign(__assign({}, middlewareConfig), { isDiscoveredEndpointRequired: true })), endpointDiscoveryMiddlewareOptions);
|
|
16
17
|
},
|
|
17
|
-
});
|
|
18
|
-
export
|
|
19
|
-
applyToStack: (commandStack)
|
|
20
|
-
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, {
|
|
18
|
+
}); };
|
|
19
|
+
export var getEndpointDiscoveryOptionalPlugin = function (pluginConfig, middlewareConfig) { return ({
|
|
20
|
+
applyToStack: function (commandStack) {
|
|
21
|
+
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, __assign(__assign({}, middlewareConfig), { isDiscoveredEndpointRequired: false })), endpointDiscoveryMiddlewareOptions);
|
|
21
22
|
},
|
|
22
|
-
});
|
|
23
|
+
}); };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
1
2
|
import { EndpointCache } from "@aws-sdk/endpoint-cache";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
endpointDiscoveryCommandCtor
|
|
5
|
-
endpointCache: new EndpointCache(input.endpointCacheSize
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
isClientEndpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined,
|
|
10
|
-
});
|
|
3
|
+
export var resolveEndpointDiscoveryConfig = function (input, _a) {
|
|
4
|
+
var _b;
|
|
5
|
+
var endpointDiscoveryCommandCtor = _a.endpointDiscoveryCommandCtor;
|
|
6
|
+
return (__assign(__assign({}, input), { endpointDiscoveryCommandCtor: endpointDiscoveryCommandCtor, endpointCache: new EndpointCache((_b = input.endpointCacheSize) !== null && _b !== void 0 ? _b : 1000), endpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined
|
|
7
|
+
? function () { return Promise.resolve(input.endpointDiscoveryEnabled); }
|
|
8
|
+
: input.endpointDiscoveryEnabledProvider, isClientEndpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined }));
|
|
9
|
+
};
|
|
@@ -1,57 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const placeholderEndpoints = [{ Address: "", CachePeriodInMinutes: 1 }];
|
|
21
|
-
endpointCache.set(cacheKey, placeholderEndpoints);
|
|
22
|
-
const command = new options.endpointDiscoveryCommandCtor({
|
|
23
|
-
Operation: commandName.slice(0, -7),
|
|
24
|
-
Identifiers: identifiers,
|
|
25
|
-
});
|
|
26
|
-
const handler = command.resolveMiddleware(options.clientStack, config, options.options);
|
|
27
|
-
handler(command)
|
|
28
|
-
.then((result) => {
|
|
29
|
-
endpointCache.set(cacheKey, result.output.Endpoints);
|
|
30
|
-
if (requestQueue[cacheKey]) {
|
|
31
|
-
requestQueue[cacheKey].forEach(({ resolve }) => {
|
|
1
|
+
import { __awaiter, __generator } from "tslib";
|
|
2
|
+
var requestQueue = {};
|
|
3
|
+
export var updateDiscoveredEndpointInCache = function (config, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4
|
+
return __generator(this, function (_a) {
|
|
5
|
+
return [2, new Promise(function (resolve, reject) {
|
|
6
|
+
var endpointCache = config.endpointCache;
|
|
7
|
+
var cacheKey = options.cacheKey, commandName = options.commandName, identifiers = options.identifiers;
|
|
8
|
+
var endpoints = endpointCache.get(cacheKey);
|
|
9
|
+
if (endpoints && endpoints.length === 1 && endpoints[0].Address === "") {
|
|
10
|
+
if (options.isDiscoveredEndpointRequired) {
|
|
11
|
+
if (!requestQueue[cacheKey])
|
|
12
|
+
requestQueue[cacheKey] = [];
|
|
13
|
+
requestQueue[cacheKey].push({ resolve: resolve, reject: reject });
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
resolve();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else if (endpoints && endpoints.length > 0) {
|
|
32
20
|
resolve();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
var placeholderEndpoints_1 = [{ Address: "", CachePeriodInMinutes: 1 }];
|
|
24
|
+
endpointCache.set(cacheKey, placeholderEndpoints_1);
|
|
25
|
+
var command = new options.endpointDiscoveryCommandCtor({
|
|
26
|
+
Operation: commandName.slice(0, -7),
|
|
27
|
+
Identifiers: identifiers,
|
|
28
|
+
});
|
|
29
|
+
var handler = command.resolveMiddleware(options.clientStack, config, options.options);
|
|
30
|
+
handler(command)
|
|
31
|
+
.then(function (result) {
|
|
32
|
+
endpointCache.set(cacheKey, result.output.Endpoints);
|
|
33
|
+
if (requestQueue[cacheKey]) {
|
|
34
|
+
requestQueue[cacheKey].forEach(function (_a) {
|
|
35
|
+
var resolve = _a.resolve;
|
|
36
|
+
resolve();
|
|
37
|
+
});
|
|
38
|
+
delete requestQueue[cacheKey];
|
|
39
|
+
}
|
|
40
|
+
resolve();
|
|
41
|
+
})
|
|
42
|
+
.catch(function (error) {
|
|
43
|
+
endpointCache.delete(cacheKey);
|
|
44
|
+
var errorToThrow = Object.assign(new Error("The operation to discover endpoint failed." +
|
|
45
|
+
" Please retry, or provide a custom endpoint and disable endpoint discovery to proceed."), { reason: error });
|
|
46
|
+
if (requestQueue[cacheKey]) {
|
|
47
|
+
requestQueue[cacheKey].forEach(function (_a) {
|
|
48
|
+
var reject = _a.reject;
|
|
49
|
+
reject(errorToThrow);
|
|
50
|
+
});
|
|
51
|
+
delete requestQueue[cacheKey];
|
|
52
|
+
}
|
|
53
|
+
if (options.isDiscoveredEndpointRequired) {
|
|
54
|
+
reject(errorToThrow);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
endpointCache.set(cacheKey, placeholderEndpoints_1);
|
|
58
|
+
resolve();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
})];
|
|
63
|
+
});
|
|
64
|
+
}); };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/middleware-endpoint-discovery",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.186.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
6
6
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@aws-sdk/node-config-provider": "3.
|
|
23
|
+
"@aws-sdk/node-config-provider": "3.186.0",
|
|
24
24
|
"@tsconfig/recommended": "1.0.1",
|
|
25
25
|
"concurrently": "7.0.0",
|
|
26
26
|
"downlevel-dts": "0.10.1",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"typescript": "~4.6.2"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@aws-sdk/config-resolver": "3.
|
|
33
|
-
"@aws-sdk/endpoint-cache": "3.
|
|
34
|
-
"@aws-sdk/protocol-http": "3.
|
|
35
|
-
"@aws-sdk/types": "3.
|
|
32
|
+
"@aws-sdk/config-resolver": "3.186.0",
|
|
33
|
+
"@aws-sdk/endpoint-cache": "3.186.0",
|
|
34
|
+
"@aws-sdk/protocol-http": "3.186.0",
|
|
35
|
+
"@aws-sdk/types": "3.186.0",
|
|
36
36
|
"tslib": "^2.3.1"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|