@aws-sdk/middleware-endpoint-discovery 3.186.0 → 3.190.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 +19 -0
- package/dist-es/configurations.js +12 -12
- package/dist-es/endpointDiscoveryMiddleware.js +40 -50
- package/dist-es/getCacheKey.js +12 -21
- package/dist-es/getEndpointDiscoveryPlugin.js +12 -13
- package/dist-es/resolveEndpointDiscoveryConfig.js +9 -8
- package/dist-es/updateDiscoveredEndpointInCache.js +56 -63
- package/dist-types/resolveEndpointDiscoveryConfig.d.ts +1 -1
- package/dist-types/ts3.4/resolveEndpointDiscoveryConfig.d.ts +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
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.190.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.189.0...v3.190.0) (2022-10-17)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **endpoint:** endpoints 2.0 all-service TS compilation fixes ([#4043](https://github.com/aws/aws-sdk-js-v3/issues/4043)) ([f2da618](https://github.com/aws/aws-sdk-js-v3/commit/f2da6182298d4d6b02e84fb723492c07c27469a8))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [3.188.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.187.0...v3.188.0) (2022-10-13)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @aws-sdk/middleware-endpoint-discovery
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
# [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package @aws-sdk/middleware-endpoint-discovery
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
environmentVariableSelector:
|
|
6
|
-
for (
|
|
7
|
-
|
|
1
|
+
const ENV_ENDPOINT_DISCOVERY = ["AWS_ENABLE_ENDPOINT_DISCOVERY", "AWS_ENDPOINT_DISCOVERY_ENABLED"];
|
|
2
|
+
const CONFIG_ENDPOINT_DISCOVERY = "endpoint_discovery_enabled";
|
|
3
|
+
const isFalsy = (value) => ["false", "0"].indexOf(value) >= 0;
|
|
4
|
+
export const NODE_ENDPOINT_DISCOVERY_CONFIG_OPTIONS = {
|
|
5
|
+
environmentVariableSelector: (env) => {
|
|
6
|
+
for (let i = 0; i < ENV_ENDPOINT_DISCOVERY.length; i++) {
|
|
7
|
+
const envKey = ENV_ENDPOINT_DISCOVERY[i];
|
|
8
8
|
if (envKey in env) {
|
|
9
|
-
|
|
9
|
+
const value = env[envKey];
|
|
10
10
|
if (value === "") {
|
|
11
|
-
throw Error(
|
|
11
|
+
throw Error(`Environment variable ${envKey} can't be empty of undefined, got "${value}"`);
|
|
12
12
|
}
|
|
13
13
|
return !isFalsy(value);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
-
configFileSelector:
|
|
17
|
+
configFileSelector: (profile) => {
|
|
18
18
|
if (CONFIG_ENDPOINT_DISCOVERY in profile) {
|
|
19
|
-
|
|
19
|
+
const value = profile[CONFIG_ENDPOINT_DISCOVERY];
|
|
20
20
|
if (value === undefined) {
|
|
21
|
-
throw Error(
|
|
21
|
+
throw Error(`Shared config entry ${CONFIG_ENDPOINT_DISCOVERY} can't be undefined, got "${value}"`);
|
|
22
22
|
}
|
|
23
23
|
return !isFalsy(value);
|
|
24
24
|
}
|
|
@@ -1,54 +1,44 @@
|
|
|
1
|
-
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
1
|
import { HttpRequest } from "@aws-sdk/protocol-http";
|
|
3
2
|
import { getCacheKey } from "./getCacheKey";
|
|
4
3
|
import { updateDiscoveredEndpointInCache } from "./updateDiscoveredEndpointInCache";
|
|
5
|
-
export
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
if (endpoint) {
|
|
46
|
-
request.hostname = endpoint;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return [2, next(args)];
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}); };
|
|
53
|
-
};
|
|
4
|
+
export const endpointDiscoveryMiddleware = (config, middlewareConfig) => (next, context) => async (args) => {
|
|
5
|
+
if (config.isCustomEndpoint) {
|
|
6
|
+
if (config.isClientEndpointDiscoveryEnabled) {
|
|
7
|
+
throw new Error(`Custom endpoint is supplied; endpointDiscoveryEnabled must not be true.`);
|
|
8
|
+
}
|
|
9
|
+
return next(args);
|
|
10
|
+
}
|
|
11
|
+
const { endpointDiscoveryCommandCtor } = config;
|
|
12
|
+
const { isDiscoveredEndpointRequired, identifiers } = middlewareConfig;
|
|
13
|
+
const { clientName, commandName } = context;
|
|
14
|
+
const isEndpointDiscoveryEnabled = await config.endpointDiscoveryEnabled();
|
|
15
|
+
const cacheKey = await getCacheKey(commandName, config, { identifiers });
|
|
16
|
+
if (isDiscoveredEndpointRequired) {
|
|
17
|
+
if (isEndpointDiscoveryEnabled === false) {
|
|
18
|
+
throw new Error(`Endpoint Discovery is disabled but ${commandName} on ${clientName} requires it.` +
|
|
19
|
+
` Please check your configurations.`);
|
|
20
|
+
}
|
|
21
|
+
await updateDiscoveredEndpointInCache(config, {
|
|
22
|
+
...middlewareConfig,
|
|
23
|
+
commandName,
|
|
24
|
+
cacheKey,
|
|
25
|
+
endpointDiscoveryCommandCtor,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else if (isEndpointDiscoveryEnabled) {
|
|
29
|
+
updateDiscoveredEndpointInCache(config, {
|
|
30
|
+
...middlewareConfig,
|
|
31
|
+
commandName,
|
|
32
|
+
cacheKey,
|
|
33
|
+
endpointDiscoveryCommandCtor,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const { request } = args;
|
|
37
|
+
if (cacheKey && HttpRequest.isInstance(request)) {
|
|
38
|
+
const endpoint = config.endpointCache.getEndpoint(cacheKey);
|
|
39
|
+
if (endpoint) {
|
|
40
|
+
request.hostname = endpoint;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return next(args);
|
|
54
44
|
};
|
package/dist-es/getCacheKey.js
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
}
|
|
1
|
+
export const getCacheKey = async (commandName, config, options) => {
|
|
2
|
+
const { accessKeyId } = await config.credentials();
|
|
3
|
+
const { identifiers } = options;
|
|
4
|
+
return JSON.stringify({
|
|
5
|
+
...(accessKeyId && { accessKeyId }),
|
|
6
|
+
...(identifiers && {
|
|
7
|
+
commandName,
|
|
8
|
+
identifiers: Object.entries(identifiers)
|
|
9
|
+
.sort()
|
|
10
|
+
.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {}),
|
|
11
|
+
}),
|
|
21
12
|
});
|
|
22
|
-
}
|
|
13
|
+
};
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
import { endpointDiscoveryMiddleware } from "./endpointDiscoveryMiddleware";
|
|
3
|
-
export
|
|
2
|
+
export const endpointDiscoveryMiddlewareOptions = {
|
|
4
3
|
name: "endpointDiscoveryMiddleware",
|
|
5
4
|
step: "build",
|
|
6
5
|
tags: ["ENDPOINT_DISCOVERY"],
|
|
7
6
|
override: true,
|
|
8
7
|
};
|
|
9
|
-
export
|
|
10
|
-
applyToStack:
|
|
8
|
+
export const getEndpointDiscoveryPlugin = (pluginConfig, middlewareConfig) => ({
|
|
9
|
+
applyToStack: (commandStack) => {
|
|
11
10
|
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, middlewareConfig), endpointDiscoveryMiddlewareOptions);
|
|
12
11
|
},
|
|
13
|
-
});
|
|
14
|
-
export
|
|
15
|
-
applyToStack:
|
|
16
|
-
commandStack.add(endpointDiscoveryMiddleware(pluginConfig,
|
|
12
|
+
});
|
|
13
|
+
export const getEndpointDiscoveryRequiredPlugin = (pluginConfig, middlewareConfig) => ({
|
|
14
|
+
applyToStack: (commandStack) => {
|
|
15
|
+
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, { ...middlewareConfig, isDiscoveredEndpointRequired: true }), endpointDiscoveryMiddlewareOptions);
|
|
17
16
|
},
|
|
18
|
-
});
|
|
19
|
-
export
|
|
20
|
-
applyToStack:
|
|
21
|
-
commandStack.add(endpointDiscoveryMiddleware(pluginConfig,
|
|
17
|
+
});
|
|
18
|
+
export const getEndpointDiscoveryOptionalPlugin = (pluginConfig, middlewareConfig) => ({
|
|
19
|
+
applyToStack: (commandStack) => {
|
|
20
|
+
commandStack.add(endpointDiscoveryMiddleware(pluginConfig, { ...middlewareConfig, isDiscoveredEndpointRequired: false }), endpointDiscoveryMiddlewareOptions);
|
|
22
21
|
},
|
|
23
|
-
});
|
|
22
|
+
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { __assign } from "tslib";
|
|
2
1
|
import { EndpointCache } from "@aws-sdk/endpoint-cache";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
export const resolveEndpointDiscoveryConfig = (input, { endpointDiscoveryCommandCtor }) => ({
|
|
3
|
+
...input,
|
|
4
|
+
endpointDiscoveryCommandCtor,
|
|
5
|
+
endpointCache: new EndpointCache(input.endpointCacheSize ?? 1000),
|
|
6
|
+
endpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined
|
|
7
|
+
? () => Promise.resolve(input.endpointDiscoveryEnabled)
|
|
8
|
+
: input.endpointDiscoveryEnabledProvider,
|
|
9
|
+
isClientEndpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined,
|
|
10
|
+
});
|
|
@@ -1,64 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
const requestQueue = {};
|
|
2
|
+
export const updateDiscoveredEndpointInCache = async (config, options) => new Promise((resolve, reject) => {
|
|
3
|
+
const { endpointCache } = config;
|
|
4
|
+
const { cacheKey, commandName, identifiers } = options;
|
|
5
|
+
const endpoints = endpointCache.get(cacheKey);
|
|
6
|
+
if (endpoints && endpoints.length === 1 && endpoints[0].Address === "") {
|
|
7
|
+
if (options.isDiscoveredEndpointRequired) {
|
|
8
|
+
if (!requestQueue[cacheKey])
|
|
9
|
+
requestQueue[cacheKey] = [];
|
|
10
|
+
requestQueue[cacheKey].push({ resolve, reject });
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
resolve();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
else if (endpoints && endpoints.length > 0) {
|
|
17
|
+
resolve();
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
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 }) => {
|
|
20
32
|
resolve();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
}); };
|
|
33
|
+
});
|
|
34
|
+
delete requestQueue[cacheKey];
|
|
35
|
+
}
|
|
36
|
+
resolve();
|
|
37
|
+
})
|
|
38
|
+
.catch((error) => {
|
|
39
|
+
endpointCache.delete(cacheKey);
|
|
40
|
+
const errorToThrow = Object.assign(new Error(`The operation to discover endpoint failed.` +
|
|
41
|
+
` Please retry, or provide a custom endpoint and disable endpoint discovery to proceed.`), { reason: error });
|
|
42
|
+
if (requestQueue[cacheKey]) {
|
|
43
|
+
requestQueue[cacheKey].forEach(({ reject }) => {
|
|
44
|
+
reject(errorToThrow);
|
|
45
|
+
});
|
|
46
|
+
delete requestQueue[cacheKey];
|
|
47
|
+
}
|
|
48
|
+
if (options.isDiscoveredEndpointRequired) {
|
|
49
|
+
reject(errorToThrow);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
endpointCache.set(cacheKey, placeholderEndpoints);
|
|
53
|
+
resolve();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
@@ -3,7 +3,7 @@ import { Credentials, MemoizedProvider, Provider } from "@aws-sdk/types";
|
|
|
3
3
|
export interface EndpointDiscoveryInputConfig {
|
|
4
4
|
}
|
|
5
5
|
export interface PreviouslyResolved {
|
|
6
|
-
isCustomEndpoint
|
|
6
|
+
isCustomEndpoint?: boolean;
|
|
7
7
|
credentials: MemoizedProvider<Credentials>;
|
|
8
8
|
endpointDiscoveryEnabledProvider: Provider<boolean | undefined>;
|
|
9
9
|
}
|
|
@@ -2,7 +2,7 @@ import { EndpointCache } from "@aws-sdk/endpoint-cache";
|
|
|
2
2
|
import { Credentials, MemoizedProvider, Provider } from "@aws-sdk/types";
|
|
3
3
|
export interface EndpointDiscoveryInputConfig {}
|
|
4
4
|
export interface PreviouslyResolved {
|
|
5
|
-
isCustomEndpoint
|
|
5
|
+
isCustomEndpoint?: boolean;
|
|
6
6
|
credentials: MemoizedProvider<Credentials>;
|
|
7
7
|
endpointDiscoveryEnabledProvider: Provider<boolean | undefined>;
|
|
8
8
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/middleware-endpoint-discovery",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.190.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.190.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.190.0",
|
|
33
|
+
"@aws-sdk/endpoint-cache": "3.188.0",
|
|
34
|
+
"@aws-sdk/protocol-http": "3.190.0",
|
|
35
|
+
"@aws-sdk/types": "3.190.0",
|
|
36
36
|
"tslib": "^2.3.1"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|