@alienplatform/sdk 1.10.7 → 1.11.1
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/.turbo/turbo-build.log +37 -8
- package/dist/bearerTokenAuthenticationPolicy.js +3028 -0
- package/dist/bindings/index.d.ts +1 -0
- package/dist/bindings/index.d.ts.map +1 -1
- package/dist/bindings/postgres.d.ts +90 -0
- package/dist/bindings/postgres.d.ts.map +1 -0
- package/dist/bindings/postgres.test.d.ts +2 -0
- package/dist/bindings/postgres.test.d.ts.map +1 -0
- package/dist/client.js +2376 -0
- package/dist/commands/index.js +1 -1
- package/dist/dist-cjs.js +3 -0
- package/dist/dist-cjs2.js +718 -0
- package/dist/dist-cjs3.js +2486 -0
- package/dist/dist-cjs4.js +171 -0
- package/dist/dist-cjs5.js +429 -0
- package/dist/dist-cjs6.js +60 -0
- package/dist/dist-cjs7.js +978 -0
- package/dist/dist-cjs8.js +86 -0
- package/dist/dist-cjs9.js +319 -0
- package/dist/dist.js +498 -36
- package/dist/dist2.js +1239 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/es5.js +1624 -0
- package/dist/esm.js +18211 -0
- package/dist/esm2.js +3104 -0
- package/dist/event-streams.js +203 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +336 -24996
- package/dist/jws.js +611 -0
- package/dist/open.js +460 -0
- package/dist/package.js +4 -0
- package/dist/protocols.js +954 -0
- package/dist/protocols2.js +5565 -0
- package/dist/rolldown-runtime.js +37 -0
- package/dist/serde.js +5542 -0
- package/dist/signin.js +723 -0
- package/dist/src.js +24900 -0
- package/dist/src2.js +114030 -0
- package/dist/sso-oidc.js +940 -0
- package/dist/sts.js +1329 -0
- package/dist/tslib.es6.js +543 -0
- package/package.json +26 -2
- package/src/bindings/index.ts +1 -0
- package/src/bindings/postgres.test.ts +17 -0
- package/src/bindings/postgres.ts +446 -0
- package/src/errors.ts +21 -0
- package/src/index.ts +5 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { a as __toCommonJS, i as __require, t as __commonJSMin } from "./rolldown-runtime.js";
|
|
2
|
+
import { n as init_client, t as client_exports } from "./client.js";
|
|
3
|
+
import { A as config_exports, j as init_config } from "./serde.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.972.52/node_modules/@aws-sdk/credential-provider-web-identity/dist-cjs/fromWebToken.js
|
|
5
|
+
var require_fromWebToken = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.fromWebToken = void 0;
|
|
8
|
+
const fromWebToken = (init) => async (awsIdentityProperties) => {
|
|
9
|
+
init.logger?.debug("@aws-sdk/credential-provider-web-identity - fromWebToken");
|
|
10
|
+
const { roleArn, roleSessionName, webIdentityToken, providerId, policyArns, policy, durationSeconds } = init;
|
|
11
|
+
let { roleAssumerWithWebIdentity } = init;
|
|
12
|
+
if (!roleAssumerWithWebIdentity) {
|
|
13
|
+
const { getDefaultRoleAssumerWithWebIdentity } = await import("./sts.js");
|
|
14
|
+
roleAssumerWithWebIdentity = getDefaultRoleAssumerWithWebIdentity({
|
|
15
|
+
...init.clientConfig,
|
|
16
|
+
credentialProviderLogger: init.logger,
|
|
17
|
+
parentClientConfig: {
|
|
18
|
+
...awsIdentityProperties?.callerClientConfig,
|
|
19
|
+
...init.parentClientConfig
|
|
20
|
+
}
|
|
21
|
+
}, init.clientPlugins);
|
|
22
|
+
}
|
|
23
|
+
return roleAssumerWithWebIdentity({
|
|
24
|
+
RoleArn: roleArn,
|
|
25
|
+
RoleSessionName: roleSessionName ?? `aws-sdk-js-session-${Date.now()}`,
|
|
26
|
+
WebIdentityToken: webIdentityToken,
|
|
27
|
+
ProviderId: providerId,
|
|
28
|
+
PolicyArns: policyArns,
|
|
29
|
+
Policy: policy,
|
|
30
|
+
DurationSeconds: durationSeconds
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.fromWebToken = fromWebToken;
|
|
34
|
+
}));
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region ../../node_modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.972.52/node_modules/@aws-sdk/credential-provider-web-identity/dist-cjs/fromTokenFile.js
|
|
37
|
+
var require_fromTokenFile = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.fromTokenFile = void 0;
|
|
40
|
+
const client_1 = (init_client(), __toCommonJS(client_exports));
|
|
41
|
+
const config_1 = (init_config(), __toCommonJS(config_exports));
|
|
42
|
+
const node_fs_1 = __require("node:fs");
|
|
43
|
+
const fromWebToken_1 = require_fromWebToken();
|
|
44
|
+
const ENV_TOKEN_FILE = "AWS_WEB_IDENTITY_TOKEN_FILE";
|
|
45
|
+
const ENV_ROLE_ARN = "AWS_ROLE_ARN";
|
|
46
|
+
const ENV_ROLE_SESSION_NAME = "AWS_ROLE_SESSION_NAME";
|
|
47
|
+
const fromTokenFile = (init = {}) => async (awsIdentityProperties) => {
|
|
48
|
+
init.logger?.debug("@aws-sdk/credential-provider-web-identity - fromTokenFile");
|
|
49
|
+
const webIdentityTokenFile = init?.webIdentityTokenFile ?? process.env[ENV_TOKEN_FILE];
|
|
50
|
+
const roleArn = init?.roleArn ?? process.env[ENV_ROLE_ARN];
|
|
51
|
+
const roleSessionName = init?.roleSessionName ?? process.env[ENV_ROLE_SESSION_NAME];
|
|
52
|
+
if (!webIdentityTokenFile || !roleArn) throw new config_1.CredentialsProviderError("Web identity configuration not specified", { logger: init.logger });
|
|
53
|
+
const credentials = await (0, fromWebToken_1.fromWebToken)({
|
|
54
|
+
...init,
|
|
55
|
+
webIdentityToken: config_1.externalDataInterceptor?.getTokenRecord?.()[webIdentityTokenFile] ?? (0, node_fs_1.readFileSync)(webIdentityTokenFile, { encoding: "ascii" }),
|
|
56
|
+
roleArn,
|
|
57
|
+
roleSessionName
|
|
58
|
+
})(awsIdentityProperties);
|
|
59
|
+
if (webIdentityTokenFile === process.env[ENV_TOKEN_FILE]) (0, client_1.setCredentialFeature)(credentials, "CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN", "h");
|
|
60
|
+
return credentials;
|
|
61
|
+
};
|
|
62
|
+
exports.fromTokenFile = fromTokenFile;
|
|
63
|
+
}));
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region ../../node_modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.972.52/node_modules/@aws-sdk/credential-provider-web-identity/dist-cjs/index.js
|
|
66
|
+
var require_dist_cjs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
67
|
+
var fromTokenFile = require_fromTokenFile();
|
|
68
|
+
var fromWebToken = require_fromWebToken();
|
|
69
|
+
Object.prototype.hasOwnProperty.call(fromTokenFile, "__proto__") && !Object.prototype.hasOwnProperty.call(exports, "__proto__") && Object.defineProperty(exports, "__proto__", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
value: fromTokenFile["__proto__"]
|
|
72
|
+
});
|
|
73
|
+
Object.keys(fromTokenFile).forEach(function(k) {
|
|
74
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = fromTokenFile[k];
|
|
75
|
+
});
|
|
76
|
+
Object.prototype.hasOwnProperty.call(fromWebToken, "__proto__") && !Object.prototype.hasOwnProperty.call(exports, "__proto__") && Object.defineProperty(exports, "__proto__", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
value: fromWebToken["__proto__"]
|
|
79
|
+
});
|
|
80
|
+
Object.keys(fromWebToken).forEach(function(k) {
|
|
81
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = fromWebToken[k];
|
|
82
|
+
});
|
|
83
|
+
}));
|
|
84
|
+
//#endregion
|
|
85
|
+
export default require_dist_cjs();
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { a as __toCommonJS, i as __require, t as __commonJSMin } from "./rolldown-runtime.js";
|
|
2
|
+
import { A as config_exports, j as init_config } from "./serde.js";
|
|
3
|
+
import { n as protocols_exports, t as init_protocols } from "./protocols.js";
|
|
4
|
+
//#region ../../node_modules/.pnpm/@smithy+credential-provider-imds@4.3.9/node_modules/@smithy/credential-provider-imds/dist-cjs/index.js
|
|
5
|
+
var require_dist_cjs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
6
|
+
var config = (init_config(), __toCommonJS(config_exports));
|
|
7
|
+
var node_http = __require("node:http");
|
|
8
|
+
var protocols = (init_protocols(), __toCommonJS(protocols_exports));
|
|
9
|
+
const isImdsCredentials = (arg) => Boolean(arg) && typeof arg === "object" && typeof arg.AccessKeyId === "string" && typeof arg.SecretAccessKey === "string" && typeof arg.Token === "string" && typeof arg.Expiration === "string";
|
|
10
|
+
const fromImdsCredentials = (creds) => ({
|
|
11
|
+
accessKeyId: creds.AccessKeyId,
|
|
12
|
+
secretAccessKey: creds.SecretAccessKey,
|
|
13
|
+
sessionToken: creds.Token,
|
|
14
|
+
expiration: new Date(creds.Expiration),
|
|
15
|
+
...creds.AccountId && { accountId: creds.AccountId }
|
|
16
|
+
});
|
|
17
|
+
const DEFAULT_TIMEOUT = 1e3;
|
|
18
|
+
const DEFAULT_MAX_RETRIES = 0;
|
|
19
|
+
const providerConfigFromInit = ({ maxRetries = DEFAULT_MAX_RETRIES, timeout = DEFAULT_TIMEOUT }) => ({
|
|
20
|
+
maxRetries,
|
|
21
|
+
timeout
|
|
22
|
+
});
|
|
23
|
+
function httpRequest(options) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const req = node_http.request({
|
|
26
|
+
method: "GET",
|
|
27
|
+
...options,
|
|
28
|
+
hostname: options.hostname?.replace(/^\[(.+)\]$/, "$1")
|
|
29
|
+
});
|
|
30
|
+
req.on("error", (err) => {
|
|
31
|
+
reject(Object.assign(new config.ProviderError("Unable to connect to instance metadata service"), err));
|
|
32
|
+
req.destroy();
|
|
33
|
+
});
|
|
34
|
+
req.on("timeout", () => {
|
|
35
|
+
reject(new config.ProviderError("TimeoutError from instance metadata service"));
|
|
36
|
+
req.destroy();
|
|
37
|
+
});
|
|
38
|
+
req.on("response", (res) => {
|
|
39
|
+
const { statusCode = 400 } = res;
|
|
40
|
+
if (statusCode < 200 || 300 <= statusCode) {
|
|
41
|
+
reject(Object.assign(new config.ProviderError("Error response received from instance metadata service"), { statusCode }));
|
|
42
|
+
req.destroy();
|
|
43
|
+
}
|
|
44
|
+
const chunks = [];
|
|
45
|
+
res.on("data", (chunk) => {
|
|
46
|
+
chunks.push(chunk);
|
|
47
|
+
});
|
|
48
|
+
res.on("end", () => {
|
|
49
|
+
resolve(Buffer.concat(chunks));
|
|
50
|
+
req.destroy();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
req.end();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const retry = (toRetry, maxRetries) => {
|
|
57
|
+
let promise = toRetry();
|
|
58
|
+
for (let i = 0; i < maxRetries; i++) promise = promise.catch(toRetry);
|
|
59
|
+
return promise;
|
|
60
|
+
};
|
|
61
|
+
const ENV_CMDS_FULL_URI = "AWS_CONTAINER_CREDENTIALS_FULL_URI";
|
|
62
|
+
const ENV_CMDS_RELATIVE_URI = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI";
|
|
63
|
+
const ENV_CMDS_AUTH_TOKEN = "AWS_CONTAINER_AUTHORIZATION_TOKEN";
|
|
64
|
+
const fromContainerMetadata = (init = {}) => {
|
|
65
|
+
const { timeout, maxRetries } = providerConfigFromInit(init);
|
|
66
|
+
return () => retry(async () => {
|
|
67
|
+
const requestOptions = await getCmdsUri({ logger: init.logger });
|
|
68
|
+
const credsResponse = JSON.parse(await requestFromEcsImds(timeout, requestOptions));
|
|
69
|
+
if (!isImdsCredentials(credsResponse)) throw new config.CredentialsProviderError("Invalid response received from instance metadata service.", { logger: init.logger });
|
|
70
|
+
return fromImdsCredentials(credsResponse);
|
|
71
|
+
}, maxRetries);
|
|
72
|
+
};
|
|
73
|
+
const requestFromEcsImds = async (timeout, options) => {
|
|
74
|
+
if (process.env[ENV_CMDS_AUTH_TOKEN]) options.headers = {
|
|
75
|
+
...options.headers,
|
|
76
|
+
Authorization: process.env[ENV_CMDS_AUTH_TOKEN]
|
|
77
|
+
};
|
|
78
|
+
return (await httpRequest({
|
|
79
|
+
...options,
|
|
80
|
+
timeout
|
|
81
|
+
})).toString();
|
|
82
|
+
};
|
|
83
|
+
const CMDS_IP = "169.254.170.2";
|
|
84
|
+
const GREENGRASS_HOSTS = new Set(["localhost", "127.0.0.1"]);
|
|
85
|
+
const GREENGRASS_PROTOCOLS = new Set(["http:", "https:"]);
|
|
86
|
+
const getCmdsUri = async ({ logger }) => {
|
|
87
|
+
if (process.env[ENV_CMDS_RELATIVE_URI]) return {
|
|
88
|
+
hostname: CMDS_IP,
|
|
89
|
+
path: process.env[ENV_CMDS_RELATIVE_URI]
|
|
90
|
+
};
|
|
91
|
+
if (process.env[ENV_CMDS_FULL_URI]) {
|
|
92
|
+
let parsed;
|
|
93
|
+
try {
|
|
94
|
+
parsed = new URL(process.env[ENV_CMDS_FULL_URI]);
|
|
95
|
+
} catch {
|
|
96
|
+
throw new config.CredentialsProviderError(`${process.env[ENV_CMDS_FULL_URI]} is not a valid container metadata service URL`, {
|
|
97
|
+
tryNextLink: false,
|
|
98
|
+
logger
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (!parsed.hostname || !GREENGRASS_HOSTS.has(parsed.hostname)) throw new config.CredentialsProviderError(`${parsed.hostname} is not a valid container metadata service hostname`, {
|
|
102
|
+
tryNextLink: false,
|
|
103
|
+
logger
|
|
104
|
+
});
|
|
105
|
+
if (!parsed.protocol || !GREENGRASS_PROTOCOLS.has(parsed.protocol)) throw new config.CredentialsProviderError(`${parsed.protocol} is not a valid container metadata service protocol`, {
|
|
106
|
+
tryNextLink: false,
|
|
107
|
+
logger
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
protocol: parsed.protocol,
|
|
111
|
+
hostname: parsed.hostname,
|
|
112
|
+
path: parsed.pathname + parsed.search,
|
|
113
|
+
port: parsed.port ? parseInt(parsed.port, 10) : void 0
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
throw new config.CredentialsProviderError(`The container metadata credential provider cannot be used unless the ${ENV_CMDS_RELATIVE_URI} or ${ENV_CMDS_FULL_URI} environment variable is set`, {
|
|
117
|
+
tryNextLink: false,
|
|
118
|
+
logger
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
var InstanceMetadataV1FallbackError = class InstanceMetadataV1FallbackError extends config.CredentialsProviderError {
|
|
122
|
+
tryNextLink;
|
|
123
|
+
name = "InstanceMetadataV1FallbackError";
|
|
124
|
+
constructor(message, tryNextLink = true) {
|
|
125
|
+
super(message, tryNextLink);
|
|
126
|
+
this.tryNextLink = tryNextLink;
|
|
127
|
+
Object.setPrototypeOf(this, InstanceMetadataV1FallbackError.prototype);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
exports.Endpoint = void 0;
|
|
131
|
+
(function(Endpoint) {
|
|
132
|
+
Endpoint["IPv4"] = "http://169.254.169.254";
|
|
133
|
+
Endpoint["IPv6"] = "http://[fd00:ec2::254]";
|
|
134
|
+
})(exports.Endpoint || (exports.Endpoint = {}));
|
|
135
|
+
const ENV_ENDPOINT_NAME = "AWS_EC2_METADATA_SERVICE_ENDPOINT";
|
|
136
|
+
const CONFIG_ENDPOINT_NAME = "ec2_metadata_service_endpoint";
|
|
137
|
+
const ENDPOINT_CONFIG_OPTIONS = {
|
|
138
|
+
environmentVariableSelector: (env) => env[ENV_ENDPOINT_NAME],
|
|
139
|
+
configFileSelector: (profile) => profile[CONFIG_ENDPOINT_NAME],
|
|
140
|
+
default: void 0
|
|
141
|
+
};
|
|
142
|
+
var EndpointMode;
|
|
143
|
+
(function(EndpointMode) {
|
|
144
|
+
EndpointMode["IPv4"] = "IPv4";
|
|
145
|
+
EndpointMode["IPv6"] = "IPv6";
|
|
146
|
+
})(EndpointMode || (EndpointMode = {}));
|
|
147
|
+
const ENV_ENDPOINT_MODE_NAME = "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE";
|
|
148
|
+
const CONFIG_ENDPOINT_MODE_NAME = "ec2_metadata_service_endpoint_mode";
|
|
149
|
+
const ENDPOINT_MODE_CONFIG_OPTIONS = {
|
|
150
|
+
environmentVariableSelector: (env) => env[ENV_ENDPOINT_MODE_NAME],
|
|
151
|
+
configFileSelector: (profile) => profile[CONFIG_ENDPOINT_MODE_NAME],
|
|
152
|
+
default: EndpointMode.IPv4
|
|
153
|
+
};
|
|
154
|
+
const getInstanceMetadataEndpoint = async () => protocols.parseUrl(await getFromEndpointConfig() || await getFromEndpointModeConfig());
|
|
155
|
+
const getFromEndpointConfig = async () => config.loadConfig(ENDPOINT_CONFIG_OPTIONS)();
|
|
156
|
+
const getFromEndpointModeConfig = async () => {
|
|
157
|
+
const endpointMode = await config.loadConfig(ENDPOINT_MODE_CONFIG_OPTIONS)();
|
|
158
|
+
switch (endpointMode) {
|
|
159
|
+
case EndpointMode.IPv4: return exports.Endpoint.IPv4;
|
|
160
|
+
case EndpointMode.IPv6: return exports.Endpoint.IPv6;
|
|
161
|
+
default: throw new Error(`Unsupported endpoint mode: ${endpointMode}. Select from ${Object.values(EndpointMode)}`);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const STATIC_STABILITY_REFRESH_INTERVAL_SECONDS = 300;
|
|
165
|
+
const STATIC_STABILITY_REFRESH_INTERVAL_JITTER_WINDOW_SECONDS = 300;
|
|
166
|
+
const getExtendedInstanceMetadataCredentials = (credentials, logger) => {
|
|
167
|
+
const refreshInterval = STATIC_STABILITY_REFRESH_INTERVAL_SECONDS + Math.floor(Math.random() * STATIC_STABILITY_REFRESH_INTERVAL_JITTER_WINDOW_SECONDS);
|
|
168
|
+
const newExpiration = new Date(Date.now() + refreshInterval * 1e3);
|
|
169
|
+
logger.warn(`Attempting credential expiration extension due to a credential service availability issue. A refresh of these credentials will be attempted after ${new Date(newExpiration)}.\nFor more information, please visit: https://docs.aws.amazon.com/sdkref/latest/guide/feature-static-credentials.html`);
|
|
170
|
+
const originalExpiration = credentials.originalExpiration ?? credentials.expiration;
|
|
171
|
+
return {
|
|
172
|
+
...credentials,
|
|
173
|
+
...originalExpiration ? { originalExpiration } : {},
|
|
174
|
+
expiration: newExpiration
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
const staticStabilityProvider = (provider, options = {}) => {
|
|
178
|
+
const logger = options?.logger || console;
|
|
179
|
+
let pastCredentials;
|
|
180
|
+
return async () => {
|
|
181
|
+
let credentials;
|
|
182
|
+
try {
|
|
183
|
+
credentials = await provider();
|
|
184
|
+
if (credentials.expiration && credentials.expiration.getTime() < Date.now()) credentials = getExtendedInstanceMetadataCredentials(credentials, logger);
|
|
185
|
+
} catch (e) {
|
|
186
|
+
if (pastCredentials) {
|
|
187
|
+
logger.warn("Credential renew failed: ", e);
|
|
188
|
+
credentials = getExtendedInstanceMetadataCredentials(pastCredentials, logger);
|
|
189
|
+
} else throw e;
|
|
190
|
+
}
|
|
191
|
+
pastCredentials = credentials;
|
|
192
|
+
return credentials;
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
const IMDS_PATH = "/latest/meta-data/iam/security-credentials/";
|
|
196
|
+
const IMDS_TOKEN_PATH = "/latest/api/token";
|
|
197
|
+
const AWS_EC2_METADATA_V1_DISABLED = "AWS_EC2_METADATA_V1_DISABLED";
|
|
198
|
+
const PROFILE_AWS_EC2_METADATA_V1_DISABLED = "ec2_metadata_v1_disabled";
|
|
199
|
+
const X_AWS_EC2_METADATA_TOKEN = "x-aws-ec2-metadata-token";
|
|
200
|
+
const fromInstanceMetadata = (init = {}) => staticStabilityProvider(getInstanceMetadataProvider(init), { logger: init.logger });
|
|
201
|
+
const getInstanceMetadataProvider = (init = {}) => {
|
|
202
|
+
let disableFetchToken = false;
|
|
203
|
+
const { logger, profile } = init;
|
|
204
|
+
const { timeout, maxRetries } = providerConfigFromInit(init);
|
|
205
|
+
const getCredentials = async (maxRetries, options) => {
|
|
206
|
+
if (disableFetchToken || options.headers?.[X_AWS_EC2_METADATA_TOKEN] == null) {
|
|
207
|
+
let fallbackBlockedFromProfile = false;
|
|
208
|
+
let fallbackBlockedFromProcessEnv = false;
|
|
209
|
+
const configValue = await config.loadConfig({
|
|
210
|
+
environmentVariableSelector: (env) => {
|
|
211
|
+
const envValue = env[AWS_EC2_METADATA_V1_DISABLED];
|
|
212
|
+
fallbackBlockedFromProcessEnv = !!envValue && envValue !== "false";
|
|
213
|
+
if (envValue === void 0) throw new config.CredentialsProviderError(`${AWS_EC2_METADATA_V1_DISABLED} not set in env, checking config file next.`, { logger: init.logger });
|
|
214
|
+
return fallbackBlockedFromProcessEnv;
|
|
215
|
+
},
|
|
216
|
+
configFileSelector: (profile) => {
|
|
217
|
+
const profileValue = profile[PROFILE_AWS_EC2_METADATA_V1_DISABLED];
|
|
218
|
+
fallbackBlockedFromProfile = !!profileValue && profileValue !== "false";
|
|
219
|
+
return fallbackBlockedFromProfile;
|
|
220
|
+
},
|
|
221
|
+
default: false
|
|
222
|
+
}, { profile })();
|
|
223
|
+
if (init.ec2MetadataV1Disabled || configValue) {
|
|
224
|
+
const causes = [];
|
|
225
|
+
if (init.ec2MetadataV1Disabled) causes.push("credential provider initialization (runtime option ec2MetadataV1Disabled)");
|
|
226
|
+
if (fallbackBlockedFromProfile) causes.push(`config file profile (${PROFILE_AWS_EC2_METADATA_V1_DISABLED})`);
|
|
227
|
+
if (fallbackBlockedFromProcessEnv) causes.push(`process environment variable (${AWS_EC2_METADATA_V1_DISABLED})`);
|
|
228
|
+
throw new InstanceMetadataV1FallbackError(`AWS EC2 Metadata v1 fallback has been blocked by AWS SDK configuration in the following: [${causes.join(", ")}].`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const imdsProfile = (await retry(async () => {
|
|
232
|
+
let profile;
|
|
233
|
+
try {
|
|
234
|
+
profile = await getProfile(options);
|
|
235
|
+
} catch (err) {
|
|
236
|
+
if (err.statusCode === 401) disableFetchToken = false;
|
|
237
|
+
throw err;
|
|
238
|
+
}
|
|
239
|
+
return profile;
|
|
240
|
+
}, maxRetries)).trim();
|
|
241
|
+
return retry(async () => {
|
|
242
|
+
let creds;
|
|
243
|
+
try {
|
|
244
|
+
creds = await getCredentialsFromProfile(imdsProfile, options, init);
|
|
245
|
+
} catch (err) {
|
|
246
|
+
if (err.statusCode === 401) disableFetchToken = false;
|
|
247
|
+
throw err;
|
|
248
|
+
}
|
|
249
|
+
return creds;
|
|
250
|
+
}, maxRetries);
|
|
251
|
+
};
|
|
252
|
+
return async () => {
|
|
253
|
+
const endpoint = await getInstanceMetadataEndpoint();
|
|
254
|
+
if (disableFetchToken) {
|
|
255
|
+
logger?.debug("AWS SDK Instance Metadata", "using v1 fallback (no token fetch)");
|
|
256
|
+
return getCredentials(maxRetries, {
|
|
257
|
+
...endpoint,
|
|
258
|
+
timeout
|
|
259
|
+
});
|
|
260
|
+
} else {
|
|
261
|
+
let token;
|
|
262
|
+
try {
|
|
263
|
+
token = (await getMetadataToken({
|
|
264
|
+
...endpoint,
|
|
265
|
+
timeout
|
|
266
|
+
})).toString();
|
|
267
|
+
} catch (error) {
|
|
268
|
+
if (error?.statusCode === 400) throw Object.assign(error, { message: "EC2 Metadata token request returned error" });
|
|
269
|
+
else if (error.message === "TimeoutError" || [
|
|
270
|
+
403,
|
|
271
|
+
404,
|
|
272
|
+
405
|
|
273
|
+
].includes(error.statusCode)) disableFetchToken = true;
|
|
274
|
+
logger?.debug("AWS SDK Instance Metadata", "using v1 fallback (initial)");
|
|
275
|
+
return getCredentials(maxRetries, {
|
|
276
|
+
...endpoint,
|
|
277
|
+
timeout
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return getCredentials(maxRetries, {
|
|
281
|
+
...endpoint,
|
|
282
|
+
headers: { [X_AWS_EC2_METADATA_TOKEN]: token },
|
|
283
|
+
timeout
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
const getMetadataToken = async (options) => httpRequest({
|
|
289
|
+
...options,
|
|
290
|
+
path: IMDS_TOKEN_PATH,
|
|
291
|
+
method: "PUT",
|
|
292
|
+
headers: { "x-aws-ec2-metadata-token-ttl-seconds": "21600" }
|
|
293
|
+
});
|
|
294
|
+
const getProfile = async (options) => (await httpRequest({
|
|
295
|
+
...options,
|
|
296
|
+
path: IMDS_PATH
|
|
297
|
+
})).toString();
|
|
298
|
+
const getCredentialsFromProfile = async (profile, options, init) => {
|
|
299
|
+
const credentialsResponse = JSON.parse((await httpRequest({
|
|
300
|
+
...options,
|
|
301
|
+
path: IMDS_PATH + profile
|
|
302
|
+
})).toString());
|
|
303
|
+
if (!isImdsCredentials(credentialsResponse)) throw new config.CredentialsProviderError("Invalid response received from instance metadata service.", { logger: init.logger });
|
|
304
|
+
return fromImdsCredentials(credentialsResponse);
|
|
305
|
+
};
|
|
306
|
+
exports.DEFAULT_MAX_RETRIES = DEFAULT_MAX_RETRIES;
|
|
307
|
+
exports.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
|
|
308
|
+
exports.ENV_CMDS_AUTH_TOKEN = ENV_CMDS_AUTH_TOKEN;
|
|
309
|
+
exports.ENV_CMDS_FULL_URI = ENV_CMDS_FULL_URI;
|
|
310
|
+
exports.ENV_CMDS_RELATIVE_URI = ENV_CMDS_RELATIVE_URI;
|
|
311
|
+
exports.fromContainerMetadata = fromContainerMetadata;
|
|
312
|
+
exports.fromInstanceMetadata = fromInstanceMetadata;
|
|
313
|
+
exports.getInstanceMetadataEndpoint = getInstanceMetadataEndpoint;
|
|
314
|
+
exports.httpRequest = httpRequest;
|
|
315
|
+
exports.providerConfigFromInit = providerConfigFromInit;
|
|
316
|
+
}));
|
|
317
|
+
//#endregion
|
|
318
|
+
export default require_dist_cjs();
|
|
319
|
+
export {};
|