@aws-sdk/credential-provider-http 3.972.48 → 3.972.50
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/dist-cjs/fromHttp/checkUrl.js +3 -7
- package/dist-cjs/fromHttp/fromHttp.browser.js +12 -16
- package/dist-cjs/fromHttp/fromHttp.js +16 -21
- package/dist-cjs/fromHttp/requestHelpers.js +14 -18
- package/dist-cjs/fromHttp/retry-wrapper.js +1 -5
- package/dist-cjs/index.browser.js +2 -5
- package/dist-cjs/index.js +2 -7
- package/package.json +6 -6
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkUrl = void 0;
|
|
4
|
-
const config_1 = require("@smithy/core/config");
|
|
1
|
+
const { CredentialsProviderError } = require("@smithy/core/config");
|
|
5
2
|
const LOOPBACK_CIDR_IPv4 = "127.0.0.0/8";
|
|
6
3
|
const LOOPBACK_CIDR_IPv6 = "::1/128";
|
|
7
4
|
const ECS_CONTAINER_HOST = "169.254.170.2";
|
|
8
5
|
const EKS_CONTAINER_HOST_IPv4 = "169.254.170.23";
|
|
9
6
|
const EKS_CONTAINER_HOST_IPv6 = "[fd00:ec2::23]";
|
|
10
|
-
|
|
7
|
+
exports.checkUrl = (url, logger) => {
|
|
11
8
|
if (url.protocol === "https:") {
|
|
12
9
|
return;
|
|
13
10
|
}
|
|
@@ -38,9 +35,8 @@ const checkUrl = (url, logger) => {
|
|
|
38
35
|
return;
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
|
-
throw new
|
|
38
|
+
throw new CredentialsProviderError(`URL not accepted. It must either be HTTPS or match one of the following:
|
|
42
39
|
- loopback CIDR 127.0.0.0/8 or [::1/128]
|
|
43
40
|
- ECS container host 169.254.170.2
|
|
44
41
|
- EKS container host 169.254.170.23 or [fd00:ec2::23]`, { logger });
|
|
45
42
|
};
|
|
46
|
-
exports.checkUrl = checkUrl;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const requestHelpers_1 = require("./requestHelpers");
|
|
8
|
-
const retry_wrapper_1 = require("./retry-wrapper");
|
|
9
|
-
const fromHttp = (options = {}) => {
|
|
1
|
+
const { CredentialsProviderError } = require("@smithy/core/config");
|
|
2
|
+
const { FetchHttpHandler } = require("@smithy/fetch-http-handler");
|
|
3
|
+
const { checkUrl } = require("./checkUrl");
|
|
4
|
+
const { createGetRequest, getCredentials } = require("./requestHelpers");
|
|
5
|
+
const { retryWrapper } = require("./retry-wrapper");
|
|
6
|
+
exports.fromHttp = (options = {}) => {
|
|
10
7
|
options.logger?.debug("@aws-sdk/credential-provider-http - fromHttp");
|
|
11
8
|
let host;
|
|
12
9
|
const full = options.credentialsFullUri;
|
|
@@ -14,18 +11,17 @@ const fromHttp = (options = {}) => {
|
|
|
14
11
|
host = full;
|
|
15
12
|
}
|
|
16
13
|
else {
|
|
17
|
-
throw new
|
|
14
|
+
throw new CredentialsProviderError("No HTTP credential provider host provided.", { logger: options.logger });
|
|
18
15
|
}
|
|
19
16
|
const url = new URL(host);
|
|
20
|
-
|
|
21
|
-
const requestHandler = new
|
|
22
|
-
return
|
|
23
|
-
const request =
|
|
17
|
+
checkUrl(url, options.logger);
|
|
18
|
+
const requestHandler = new FetchHttpHandler();
|
|
19
|
+
return retryWrapper(async () => {
|
|
20
|
+
const request = createGetRequest(url);
|
|
24
21
|
if (options.authorizationToken) {
|
|
25
22
|
request.headers.Authorization = options.authorizationToken;
|
|
26
23
|
}
|
|
27
24
|
const result = await requestHandler.handle(request);
|
|
28
|
-
return
|
|
25
|
+
return getCredentials(result.response);
|
|
29
26
|
}, options.maxRetries ?? 3, options.timeout ?? 1000);
|
|
30
27
|
};
|
|
31
|
-
exports.fromHttp = fromHttp;
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const promises_1 = tslib_1.__importDefault(require("node:fs/promises"));
|
|
9
|
-
const checkUrl_1 = require("./checkUrl");
|
|
10
|
-
const requestHelpers_1 = require("./requestHelpers");
|
|
11
|
-
const retry_wrapper_1 = require("./retry-wrapper");
|
|
1
|
+
const { setCredentialFeature } = require("@aws-sdk/core/client");
|
|
2
|
+
const { CredentialsProviderError } = require("@smithy/core/config");
|
|
3
|
+
const { NodeHttpHandler } = require("@smithy/node-http-handler");
|
|
4
|
+
const fs = require("node:fs/promises");
|
|
5
|
+
const { checkUrl } = require("./checkUrl");
|
|
6
|
+
const { createGetRequest, getCredentials } = require("./requestHelpers");
|
|
7
|
+
const { retryWrapper } = require("./retry-wrapper");
|
|
12
8
|
const AWS_CONTAINER_CREDENTIALS_RELATIVE_URI = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI";
|
|
13
9
|
const DEFAULT_LINK_LOCAL_HOST = "http://169.254.170.2";
|
|
14
10
|
const AWS_CONTAINER_CREDENTIALS_FULL_URI = "AWS_CONTAINER_CREDENTIALS_FULL_URI";
|
|
15
11
|
const AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE = "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE";
|
|
16
12
|
const AWS_CONTAINER_AUTHORIZATION_TOKEN = "AWS_CONTAINER_AUTHORIZATION_TOKEN";
|
|
17
|
-
|
|
13
|
+
exports.fromHttp = (options = {}) => {
|
|
18
14
|
options.logger?.debug("@aws-sdk/credential-provider-http - fromHttp");
|
|
19
15
|
let host;
|
|
20
16
|
const relative = options.awsContainerCredentialsRelativeUri ?? process.env[AWS_CONTAINER_CREDENTIALS_RELATIVE_URI];
|
|
@@ -41,27 +37,27 @@ const fromHttp = (options = {}) => {
|
|
|
41
37
|
host = `${DEFAULT_LINK_LOCAL_HOST}${relative}`;
|
|
42
38
|
}
|
|
43
39
|
else {
|
|
44
|
-
throw new
|
|
40
|
+
throw new CredentialsProviderError(`No HTTP credential provider host provided.
|
|
45
41
|
Set AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI.`, { logger: options.logger });
|
|
46
42
|
}
|
|
47
43
|
const url = new URL(host);
|
|
48
|
-
|
|
49
|
-
const requestHandler =
|
|
44
|
+
checkUrl(url, options.logger);
|
|
45
|
+
const requestHandler = NodeHttpHandler.create({ connectionTimeout: options.timeout ?? 1000 });
|
|
50
46
|
const requestTimeout = options.timeout ?? 1000;
|
|
51
|
-
const provider =
|
|
52
|
-
const request =
|
|
47
|
+
const provider = retryWrapper(async () => {
|
|
48
|
+
const request = createGetRequest(url);
|
|
53
49
|
if (token) {
|
|
54
50
|
request.headers.Authorization = token;
|
|
55
51
|
}
|
|
56
52
|
else if (tokenFile) {
|
|
57
|
-
request.headers.Authorization = (await
|
|
53
|
+
request.headers.Authorization = (await fs.readFile(tokenFile)).toString();
|
|
58
54
|
}
|
|
59
55
|
try {
|
|
60
56
|
const result = await requestHandler.handle(request, { requestTimeout });
|
|
61
|
-
return
|
|
57
|
+
return getCredentials(result.response).then((creds) => setCredentialFeature(creds, "CREDENTIALS_HTTP", "z"));
|
|
62
58
|
}
|
|
63
59
|
catch (e) {
|
|
64
|
-
throw new
|
|
60
|
+
throw new CredentialsProviderError(String(e), { logger: options.logger });
|
|
65
61
|
}
|
|
66
62
|
}, options.maxRetries ?? 3, options.timeout ?? 1000);
|
|
67
63
|
return async () => {
|
|
@@ -73,4 +69,3 @@ Set AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
|
|
|
73
69
|
}
|
|
74
70
|
};
|
|
75
71
|
};
|
|
76
|
-
exports.fromHttp = fromHttp;
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const serde_1 = require("@smithy/core/serde");
|
|
8
|
-
const serde_2 = require("@smithy/core/serde");
|
|
9
|
-
function createGetRequest(url) {
|
|
10
|
-
return new protocols_1.HttpRequest({
|
|
1
|
+
const { CredentialsProviderError } = require("@smithy/core/config");
|
|
2
|
+
const { HttpRequest } = require("@smithy/core/protocols");
|
|
3
|
+
const { parseRfc3339DateTime } = require("@smithy/core/serde");
|
|
4
|
+
const { sdkStreamMixin } = require("@smithy/core/serde");
|
|
5
|
+
exports.createGetRequest = function createGetRequest(url) {
|
|
6
|
+
return new HttpRequest({
|
|
11
7
|
protocol: url.protocol,
|
|
12
8
|
hostname: url.hostname,
|
|
13
9
|
port: Number(url.port),
|
|
@@ -18,9 +14,9 @@ function createGetRequest(url) {
|
|
|
18
14
|
}, {}),
|
|
19
15
|
fragment: url.hash,
|
|
20
16
|
});
|
|
21
|
-
}
|
|
22
|
-
async function getCredentials(response, logger) {
|
|
23
|
-
const stream =
|
|
17
|
+
};
|
|
18
|
+
exports.getCredentials = async function getCredentials(response, logger) {
|
|
19
|
+
const stream = sdkStreamMixin(response.body);
|
|
24
20
|
const str = await stream.transformToString();
|
|
25
21
|
if (response.statusCode === 200) {
|
|
26
22
|
const parsed = JSON.parse(str);
|
|
@@ -28,14 +24,14 @@ async function getCredentials(response, logger) {
|
|
|
28
24
|
typeof parsed.SecretAccessKey !== "string" ||
|
|
29
25
|
typeof parsed.Token !== "string" ||
|
|
30
26
|
typeof parsed.Expiration !== "string") {
|
|
31
|
-
throw new
|
|
27
|
+
throw new CredentialsProviderError("HTTP credential provider response not of the required format, an object matching: " +
|
|
32
28
|
"{ AccessKeyId: string, SecretAccessKey: string, Token: string, Expiration: string(rfc3339) }", { logger });
|
|
33
29
|
}
|
|
34
30
|
return {
|
|
35
31
|
accessKeyId: parsed.AccessKeyId,
|
|
36
32
|
secretAccessKey: parsed.SecretAccessKey,
|
|
37
33
|
sessionToken: parsed.Token,
|
|
38
|
-
expiration:
|
|
34
|
+
expiration: parseRfc3339DateTime(parsed.Expiration),
|
|
39
35
|
};
|
|
40
36
|
}
|
|
41
37
|
if (response.statusCode >= 400 && response.statusCode < 500) {
|
|
@@ -44,10 +40,10 @@ async function getCredentials(response, logger) {
|
|
|
44
40
|
parsedBody = JSON.parse(str);
|
|
45
41
|
}
|
|
46
42
|
catch (e) { }
|
|
47
|
-
throw Object.assign(new
|
|
43
|
+
throw Object.assign(new CredentialsProviderError(`Server responded with status: ${response.statusCode}`, { logger }), {
|
|
48
44
|
Code: parsedBody.Code,
|
|
49
45
|
Message: parsedBody.Message,
|
|
50
46
|
});
|
|
51
47
|
}
|
|
52
|
-
throw new
|
|
53
|
-
}
|
|
48
|
+
throw new CredentialsProviderError(`Server responded with status: ${response.statusCode}`, { logger });
|
|
49
|
+
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.retryWrapper = void 0;
|
|
4
|
-
const retryWrapper = (toRetry, maxRetries, delayMs) => {
|
|
1
|
+
exports.retryWrapper = (toRetry, maxRetries, delayMs) => {
|
|
5
2
|
return async () => {
|
|
6
3
|
for (let i = 0; i < maxRetries; ++i) {
|
|
7
4
|
try {
|
|
@@ -14,4 +11,3 @@ const retryWrapper = (toRetry, maxRetries, delayMs) => {
|
|
|
14
11
|
return await toRetry();
|
|
15
12
|
};
|
|
16
13
|
};
|
|
17
|
-
exports.retryWrapper = retryWrapper;
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.fromHttp = void 0;
|
|
4
|
-
var fromHttp_browser_1 = require("./fromHttp/fromHttp.browser");
|
|
5
|
-
Object.defineProperty(exports, "fromHttp", { enumerable: true, get: function () { return fromHttp_browser_1.fromHttp; } });
|
|
1
|
+
const { fromHttp } = require("./fromHttp/fromHttp.browser");
|
|
2
|
+
exports.fromHttp = fromHttp;
|
package/dist-cjs/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/credential-provider-http",
|
|
3
|
-
"version": "3.972.
|
|
3
|
+
"version": "3.972.50",
|
|
4
4
|
"description": "AWS credential provider for containers and HTTP sources",
|
|
5
5
|
"main": "./dist-cjs/index.js",
|
|
6
6
|
"module": "./dist-es/index.js",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
|
|
19
19
|
"build:cjs": "node ../../scripts/compilation/inline",
|
|
20
|
-
"build:es": "tsc -p tsconfig.es.json",
|
|
20
|
+
"build:es": "premove dist-es && tsc -p tsconfig.es.json",
|
|
21
21
|
"build:include:deps": "yarn g:turbo run build -F=\"$npm_package_name\"",
|
|
22
|
-
"build:types": "tsc -p tsconfig.types.json",
|
|
22
|
+
"build:types": "premove dist-types && tsc -p tsconfig.types.json",
|
|
23
23
|
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
|
|
24
|
-
"clean": "premove dist-cjs dist-es dist-types
|
|
24
|
+
"clean": "premove dist-cjs dist-es dist-types",
|
|
25
25
|
"test": "yarn g:vitest run",
|
|
26
26
|
"test:watch": "yarn g:vitest watch",
|
|
27
27
|
"test:integration": "yarn g:vitest run -c vitest.config.integ.mts",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
},
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@aws-sdk/core": "^3.974.
|
|
42
|
-
"@aws-sdk/types": "^3.973.
|
|
41
|
+
"@aws-sdk/core": "^3.974.22",
|
|
42
|
+
"@aws-sdk/types": "^3.973.13",
|
|
43
43
|
"@smithy/core": "^3.24.6",
|
|
44
44
|
"@smithy/fetch-http-handler": "^5.4.6",
|
|
45
45
|
"@smithy/node-http-handler": "^4.7.6",
|