@awsless/cli 0.0.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.
Files changed (50) hide show
  1. package/README.MD +487 -0
  2. package/dist/app.json +1 -0
  3. package/dist/app.stage.json +1 -0
  4. package/dist/bin.d.ts +1 -0
  5. package/dist/bin.js +49025 -0
  6. package/dist/build-json-schema.js +1925 -0
  7. package/dist/chunk-2TBBLACH.js +37 -0
  8. package/dist/chunk-3YEPERYO.js +1021 -0
  9. package/dist/chunk-4JFIJMQ6.js +46 -0
  10. package/dist/chunk-5TWBDDXS.js +60 -0
  11. package/dist/chunk-7NRPMOO4.js +876 -0
  12. package/dist/chunk-7XIGSOF4.js +100 -0
  13. package/dist/chunk-DSXFE5X2.js +174 -0
  14. package/dist/chunk-E7FQOYML.js +12 -0
  15. package/dist/chunk-GH475CSF.js +5005 -0
  16. package/dist/chunk-JHYKYQ5P.js +163 -0
  17. package/dist/chunk-LBISIOIM.js +28 -0
  18. package/dist/chunk-RCNT4C4P.js +50 -0
  19. package/dist/chunk-SIAA4J6H.js +21 -0
  20. package/dist/chunk-XNYTWFP6.js +241 -0
  21. package/dist/chunk-Z37AK4IA.js +546 -0
  22. package/dist/chunk-ZKH7AMP3.js +42 -0
  23. package/dist/dist-es-GXHCNXAC.js +489 -0
  24. package/dist/dist-es-J7SL4PXO.js +88 -0
  25. package/dist/dist-es-LL3VAI2X.js +70 -0
  26. package/dist/dist-es-QND3CYLI.js +380 -0
  27. package/dist/dist-es-STVZUSZG.js +21 -0
  28. package/dist/dist-es-TCFHB4OF.js +324 -0
  29. package/dist/dist-es-YFQTZTNE.js +167 -0
  30. package/dist/event-streams-74K5M656.js +244 -0
  31. package/dist/layers/sharp-arm.zip +0 -0
  32. package/dist/loadSso-O7PM54HL.js +592 -0
  33. package/dist/prebuild/icon/HASH +1 -0
  34. package/dist/prebuild/icon/bundle.zip +0 -0
  35. package/dist/prebuild/image/HASH +1 -0
  36. package/dist/prebuild/image/bundle.zip +0 -0
  37. package/dist/prebuild/on-error-log/HASH +1 -0
  38. package/dist/prebuild/on-error-log/bundle.zip +0 -0
  39. package/dist/prebuild/on-failure/HASH +1 -0
  40. package/dist/prebuild/on-failure/bundle.zip +0 -0
  41. package/dist/prebuild/rpc/HASH +1 -0
  42. package/dist/prebuild/rpc/bundle.zip +0 -0
  43. package/dist/prebuild.js +159 -0
  44. package/dist/signin-6SPMGGJN.js +704 -0
  45. package/dist/sso-oidc-5IIWGKXY.js +829 -0
  46. package/dist/stack.json +1 -0
  47. package/dist/stack.stage.json +1 -0
  48. package/dist/sts-6SQWH4BL.js +3788 -0
  49. package/dist/test-global-setup.js +22 -0
  50. package/package.json +120 -0
@@ -0,0 +1,324 @@
1
+ import {
2
+ getProfileName,
3
+ getSSOTokenFilepath,
4
+ getSSOTokenFromFile,
5
+ loadSsoSessionData,
6
+ parseKnownFiles
7
+ } from "./chunk-XNYTWFP6.js";
8
+ import {
9
+ setCredentialFeature
10
+ } from "./chunk-E7FQOYML.js";
11
+ import {
12
+ CredentialsProviderError,
13
+ ProviderError
14
+ } from "./chunk-2TBBLACH.js";
15
+ import "./chunk-SIAA4J6H.js";
16
+
17
+ // ../../node_modules/.pnpm/@smithy+property-provider@4.2.12/node_modules/@smithy/property-provider/dist-es/TokenProviderError.js
18
+ var TokenProviderError = class _TokenProviderError extends ProviderError {
19
+ name = "TokenProviderError";
20
+ constructor(message, options = true) {
21
+ super(message, options);
22
+ Object.setPrototypeOf(this, _TokenProviderError.prototype);
23
+ }
24
+ };
25
+
26
+ // ../../node_modules/.pnpm/@aws-sdk+credential-provider-sso@3.972.28_aws-crt@1.30.0/node_modules/@aws-sdk/credential-provider-sso/dist-es/isSsoProfile.js
27
+ var isSsoProfile = (arg) => arg && (typeof arg.sso_start_url === "string" || typeof arg.sso_account_id === "string" || typeof arg.sso_session === "string" || typeof arg.sso_region === "string" || typeof arg.sso_role_name === "string");
28
+
29
+ // ../../node_modules/.pnpm/@aws-sdk+token-providers@3.1021.0_aws-crt@1.30.0/node_modules/@aws-sdk/token-providers/dist-es/constants.js
30
+ var EXPIRE_WINDOW_MS = 5 * 60 * 1e3;
31
+ var REFRESH_MESSAGE = `To refresh this SSO session run 'aws sso login' with the corresponding profile.`;
32
+
33
+ // ../../node_modules/.pnpm/@aws-sdk+token-providers@3.1021.0_aws-crt@1.30.0/node_modules/@aws-sdk/token-providers/dist-es/getSsoOidcClient.js
34
+ var getSsoOidcClient = async (ssoRegion, init = {}, callerClientConfig) => {
35
+ const { SSOOIDCClient } = await import("./sso-oidc-5IIWGKXY.js");
36
+ const coalesce = (prop) => init.clientConfig?.[prop] ?? init.parentClientConfig?.[prop] ?? callerClientConfig?.[prop];
37
+ const ssoOidcClient = new SSOOIDCClient(Object.assign({}, init.clientConfig ?? {}, {
38
+ region: ssoRegion ?? init.clientConfig?.region,
39
+ logger: coalesce("logger"),
40
+ userAgentAppId: coalesce("userAgentAppId")
41
+ }));
42
+ return ssoOidcClient;
43
+ };
44
+
45
+ // ../../node_modules/.pnpm/@aws-sdk+token-providers@3.1021.0_aws-crt@1.30.0/node_modules/@aws-sdk/token-providers/dist-es/getNewSsoOidcToken.js
46
+ var getNewSsoOidcToken = async (ssoToken, ssoRegion, init = {}, callerClientConfig) => {
47
+ const { CreateTokenCommand } = await import("./sso-oidc-5IIWGKXY.js");
48
+ const ssoOidcClient = await getSsoOidcClient(ssoRegion, init, callerClientConfig);
49
+ return ssoOidcClient.send(new CreateTokenCommand({
50
+ clientId: ssoToken.clientId,
51
+ clientSecret: ssoToken.clientSecret,
52
+ refreshToken: ssoToken.refreshToken,
53
+ grantType: "refresh_token"
54
+ }));
55
+ };
56
+
57
+ // ../../node_modules/.pnpm/@aws-sdk+token-providers@3.1021.0_aws-crt@1.30.0/node_modules/@aws-sdk/token-providers/dist-es/validateTokenExpiry.js
58
+ var validateTokenExpiry = (token) => {
59
+ if (token.expiration && token.expiration.getTime() < Date.now()) {
60
+ throw new TokenProviderError(`Token is expired. ${REFRESH_MESSAGE}`, false);
61
+ }
62
+ };
63
+
64
+ // ../../node_modules/.pnpm/@aws-sdk+token-providers@3.1021.0_aws-crt@1.30.0/node_modules/@aws-sdk/token-providers/dist-es/validateTokenKey.js
65
+ var validateTokenKey = (key, value, forRefresh = false) => {
66
+ if (typeof value === "undefined") {
67
+ throw new TokenProviderError(`Value not present for '${key}' in SSO Token${forRefresh ? ". Cannot refresh" : ""}. ${REFRESH_MESSAGE}`, false);
68
+ }
69
+ };
70
+
71
+ // ../../node_modules/.pnpm/@aws-sdk+token-providers@3.1021.0_aws-crt@1.30.0/node_modules/@aws-sdk/token-providers/dist-es/writeSSOTokenToFile.js
72
+ import { promises as fsPromises } from "fs";
73
+ var { writeFile } = fsPromises;
74
+ var writeSSOTokenToFile = (id, ssoToken) => {
75
+ const tokenFilepath = getSSOTokenFilepath(id);
76
+ const tokenString = JSON.stringify(ssoToken, null, 2);
77
+ return writeFile(tokenFilepath, tokenString);
78
+ };
79
+
80
+ // ../../node_modules/.pnpm/@aws-sdk+token-providers@3.1021.0_aws-crt@1.30.0/node_modules/@aws-sdk/token-providers/dist-es/fromSso.js
81
+ var lastRefreshAttemptTime = /* @__PURE__ */ new Date(0);
82
+ var fromSso = (init = {}) => async ({ callerClientConfig } = {}) => {
83
+ init.logger?.debug("@aws-sdk/token-providers - fromSso");
84
+ const profiles = await parseKnownFiles(init);
85
+ const profileName = getProfileName({
86
+ profile: init.profile ?? callerClientConfig?.profile
87
+ });
88
+ const profile = profiles[profileName];
89
+ if (!profile) {
90
+ throw new TokenProviderError(`Profile '${profileName}' could not be found in shared credentials file.`, false);
91
+ } else if (!profile["sso_session"]) {
92
+ throw new TokenProviderError(`Profile '${profileName}' is missing required property 'sso_session'.`);
93
+ }
94
+ const ssoSessionName = profile["sso_session"];
95
+ const ssoSessions = await loadSsoSessionData(init);
96
+ const ssoSession = ssoSessions[ssoSessionName];
97
+ if (!ssoSession) {
98
+ throw new TokenProviderError(`Sso session '${ssoSessionName}' could not be found in shared credentials file.`, false);
99
+ }
100
+ for (const ssoSessionRequiredKey of ["sso_start_url", "sso_region"]) {
101
+ if (!ssoSession[ssoSessionRequiredKey]) {
102
+ throw new TokenProviderError(`Sso session '${ssoSessionName}' is missing required property '${ssoSessionRequiredKey}'.`, false);
103
+ }
104
+ }
105
+ const ssoStartUrl = ssoSession["sso_start_url"];
106
+ const ssoRegion = ssoSession["sso_region"];
107
+ let ssoToken;
108
+ try {
109
+ ssoToken = await getSSOTokenFromFile(ssoSessionName);
110
+ } catch (e) {
111
+ throw new TokenProviderError(`The SSO session token associated with profile=${profileName} was not found or is invalid. ${REFRESH_MESSAGE}`, false);
112
+ }
113
+ validateTokenKey("accessToken", ssoToken.accessToken);
114
+ validateTokenKey("expiresAt", ssoToken.expiresAt);
115
+ const { accessToken, expiresAt } = ssoToken;
116
+ const existingToken = { token: accessToken, expiration: new Date(expiresAt) };
117
+ if (existingToken.expiration.getTime() - Date.now() > EXPIRE_WINDOW_MS) {
118
+ return existingToken;
119
+ }
120
+ if (Date.now() - lastRefreshAttemptTime.getTime() < 30 * 1e3) {
121
+ validateTokenExpiry(existingToken);
122
+ return existingToken;
123
+ }
124
+ validateTokenKey("clientId", ssoToken.clientId, true);
125
+ validateTokenKey("clientSecret", ssoToken.clientSecret, true);
126
+ validateTokenKey("refreshToken", ssoToken.refreshToken, true);
127
+ try {
128
+ lastRefreshAttemptTime.setTime(Date.now());
129
+ const newSsoOidcToken = await getNewSsoOidcToken(ssoToken, ssoRegion, init, callerClientConfig);
130
+ validateTokenKey("accessToken", newSsoOidcToken.accessToken);
131
+ validateTokenKey("expiresIn", newSsoOidcToken.expiresIn);
132
+ const newTokenExpiration = new Date(Date.now() + newSsoOidcToken.expiresIn * 1e3);
133
+ try {
134
+ await writeSSOTokenToFile(ssoSessionName, {
135
+ ...ssoToken,
136
+ accessToken: newSsoOidcToken.accessToken,
137
+ expiresAt: newTokenExpiration.toISOString(),
138
+ refreshToken: newSsoOidcToken.refreshToken
139
+ });
140
+ } catch (error) {
141
+ }
142
+ return {
143
+ token: newSsoOidcToken.accessToken,
144
+ expiration: newTokenExpiration
145
+ };
146
+ } catch (error) {
147
+ validateTokenExpiry(existingToken);
148
+ return existingToken;
149
+ }
150
+ };
151
+
152
+ // ../../node_modules/.pnpm/@aws-sdk+credential-provider-sso@3.972.28_aws-crt@1.30.0/node_modules/@aws-sdk/credential-provider-sso/dist-es/resolveSSOCredentials.js
153
+ var SHOULD_FAIL_CREDENTIAL_CHAIN = false;
154
+ var resolveSSOCredentials = async ({ ssoStartUrl, ssoSession, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, clientConfig, parentClientConfig, callerClientConfig, profile, filepath, configFilepath, ignoreCache, logger }) => {
155
+ let token;
156
+ const refreshMessage = `To refresh this SSO session run aws sso login with the corresponding profile.`;
157
+ if (ssoSession) {
158
+ try {
159
+ const _token = await fromSso({
160
+ profile,
161
+ filepath,
162
+ configFilepath,
163
+ ignoreCache
164
+ })();
165
+ token = {
166
+ accessToken: _token.token,
167
+ expiresAt: new Date(_token.expiration).toISOString()
168
+ };
169
+ } catch (e) {
170
+ throw new CredentialsProviderError(e.message, {
171
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
172
+ logger
173
+ });
174
+ }
175
+ } else {
176
+ try {
177
+ token = await getSSOTokenFromFile(ssoStartUrl);
178
+ } catch (e) {
179
+ throw new CredentialsProviderError(`The SSO session associated with this profile is invalid. ${refreshMessage}`, {
180
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
181
+ logger
182
+ });
183
+ }
184
+ }
185
+ if (new Date(token.expiresAt).getTime() - Date.now() <= 0) {
186
+ throw new CredentialsProviderError(`The SSO session associated with this profile has expired. ${refreshMessage}`, {
187
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
188
+ logger
189
+ });
190
+ }
191
+ const { accessToken } = token;
192
+ const { SSOClient, GetRoleCredentialsCommand } = await import("./loadSso-O7PM54HL.js");
193
+ const sso = ssoClient || new SSOClient(Object.assign({}, clientConfig ?? {}, {
194
+ logger: clientConfig?.logger ?? callerClientConfig?.logger ?? parentClientConfig?.logger,
195
+ region: clientConfig?.region ?? ssoRegion,
196
+ userAgentAppId: clientConfig?.userAgentAppId ?? callerClientConfig?.userAgentAppId ?? parentClientConfig?.userAgentAppId
197
+ }));
198
+ let ssoResp;
199
+ try {
200
+ ssoResp = await sso.send(new GetRoleCredentialsCommand({
201
+ accountId: ssoAccountId,
202
+ roleName: ssoRoleName,
203
+ accessToken
204
+ }));
205
+ } catch (e) {
206
+ throw new CredentialsProviderError(e, {
207
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
208
+ logger
209
+ });
210
+ }
211
+ const { roleCredentials: { accessKeyId, secretAccessKey, sessionToken, expiration, credentialScope, accountId } = {} } = ssoResp;
212
+ if (!accessKeyId || !secretAccessKey || !sessionToken || !expiration) {
213
+ throw new CredentialsProviderError("SSO returns an invalid temporary credential.", {
214
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
215
+ logger
216
+ });
217
+ }
218
+ const credentials = {
219
+ accessKeyId,
220
+ secretAccessKey,
221
+ sessionToken,
222
+ expiration: new Date(expiration),
223
+ ...credentialScope && { credentialScope },
224
+ ...accountId && { accountId }
225
+ };
226
+ if (ssoSession) {
227
+ setCredentialFeature(credentials, "CREDENTIALS_SSO", "s");
228
+ } else {
229
+ setCredentialFeature(credentials, "CREDENTIALS_SSO_LEGACY", "u");
230
+ }
231
+ return credentials;
232
+ };
233
+
234
+ // ../../node_modules/.pnpm/@aws-sdk+credential-provider-sso@3.972.28_aws-crt@1.30.0/node_modules/@aws-sdk/credential-provider-sso/dist-es/validateSsoProfile.js
235
+ var validateSsoProfile = (profile, logger) => {
236
+ const { sso_start_url, sso_account_id, sso_region, sso_role_name } = profile;
237
+ if (!sso_start_url || !sso_account_id || !sso_region || !sso_role_name) {
238
+ throw new CredentialsProviderError(`Profile is configured with invalid SSO credentials. Required parameters "sso_account_id", "sso_region", "sso_role_name", "sso_start_url". Got ${Object.keys(profile).join(", ")}
239
+ Reference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html`, { tryNextLink: false, logger });
240
+ }
241
+ return profile;
242
+ };
243
+
244
+ // ../../node_modules/.pnpm/@aws-sdk+credential-provider-sso@3.972.28_aws-crt@1.30.0/node_modules/@aws-sdk/credential-provider-sso/dist-es/fromSSO.js
245
+ var fromSSO = (init = {}) => async ({ callerClientConfig } = {}) => {
246
+ init.logger?.debug("@aws-sdk/credential-provider-sso - fromSSO");
247
+ const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoSession } = init;
248
+ const { ssoClient } = init;
249
+ const profileName = getProfileName({
250
+ profile: init.profile ?? callerClientConfig?.profile
251
+ });
252
+ if (!ssoStartUrl && !ssoAccountId && !ssoRegion && !ssoRoleName && !ssoSession) {
253
+ const profiles = await parseKnownFiles(init);
254
+ const profile = profiles[profileName];
255
+ if (!profile) {
256
+ throw new CredentialsProviderError(`Profile ${profileName} was not found.`, { logger: init.logger });
257
+ }
258
+ if (!isSsoProfile(profile)) {
259
+ throw new CredentialsProviderError(`Profile ${profileName} is not configured with SSO credentials.`, {
260
+ logger: init.logger
261
+ });
262
+ }
263
+ if (profile?.sso_session) {
264
+ const ssoSessions = await loadSsoSessionData(init);
265
+ const session = ssoSessions[profile.sso_session];
266
+ const conflictMsg = ` configurations in profile ${profileName} and sso-session ${profile.sso_session}`;
267
+ if (ssoRegion && ssoRegion !== session.sso_region) {
268
+ throw new CredentialsProviderError(`Conflicting SSO region` + conflictMsg, {
269
+ tryNextLink: false,
270
+ logger: init.logger
271
+ });
272
+ }
273
+ if (ssoStartUrl && ssoStartUrl !== session.sso_start_url) {
274
+ throw new CredentialsProviderError(`Conflicting SSO start_url` + conflictMsg, {
275
+ tryNextLink: false,
276
+ logger: init.logger
277
+ });
278
+ }
279
+ profile.sso_region = session.sso_region;
280
+ profile.sso_start_url = session.sso_start_url;
281
+ }
282
+ const { sso_start_url, sso_account_id, sso_region, sso_role_name, sso_session } = validateSsoProfile(profile, init.logger);
283
+ return resolveSSOCredentials({
284
+ ssoStartUrl: sso_start_url,
285
+ ssoSession: sso_session,
286
+ ssoAccountId: sso_account_id,
287
+ ssoRegion: sso_region,
288
+ ssoRoleName: sso_role_name,
289
+ ssoClient,
290
+ clientConfig: init.clientConfig,
291
+ parentClientConfig: init.parentClientConfig,
292
+ callerClientConfig: init.callerClientConfig,
293
+ profile: profileName,
294
+ filepath: init.filepath,
295
+ configFilepath: init.configFilepath,
296
+ ignoreCache: init.ignoreCache,
297
+ logger: init.logger
298
+ });
299
+ } else if (!ssoStartUrl || !ssoAccountId || !ssoRegion || !ssoRoleName) {
300
+ throw new CredentialsProviderError('Incomplete configuration. The fromSSO() argument hash must include "ssoStartUrl", "ssoAccountId", "ssoRegion", "ssoRoleName"', { tryNextLink: false, logger: init.logger });
301
+ } else {
302
+ return resolveSSOCredentials({
303
+ ssoStartUrl,
304
+ ssoSession,
305
+ ssoAccountId,
306
+ ssoRegion,
307
+ ssoRoleName,
308
+ ssoClient,
309
+ clientConfig: init.clientConfig,
310
+ parentClientConfig: init.parentClientConfig,
311
+ callerClientConfig: init.callerClientConfig,
312
+ profile: profileName,
313
+ filepath: init.filepath,
314
+ configFilepath: init.configFilepath,
315
+ ignoreCache: init.ignoreCache,
316
+ logger: init.logger
317
+ });
318
+ }
319
+ };
320
+ export {
321
+ fromSSO,
322
+ isSsoProfile,
323
+ validateSsoProfile
324
+ };
@@ -0,0 +1,167 @@
1
+ import {
2
+ sdkStreamMixin
3
+ } from "./chunk-DSXFE5X2.js";
4
+ import {
5
+ NodeHttpHandler,
6
+ parseRfc3339DateTime
7
+ } from "./chunk-7NRPMOO4.js";
8
+ import {
9
+ HttpRequest
10
+ } from "./chunk-5TWBDDXS.js";
11
+ import "./chunk-ZKH7AMP3.js";
12
+ import {
13
+ setCredentialFeature
14
+ } from "./chunk-E7FQOYML.js";
15
+ import {
16
+ CredentialsProviderError
17
+ } from "./chunk-2TBBLACH.js";
18
+ import "./chunk-SIAA4J6H.js";
19
+
20
+ // ../../node_modules/.pnpm/@aws-sdk+credential-provider-http@3.972.26/node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/fromHttp.js
21
+ import fs from "fs/promises";
22
+
23
+ // ../../node_modules/.pnpm/@aws-sdk+credential-provider-http@3.972.26/node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/checkUrl.js
24
+ var ECS_CONTAINER_HOST = "169.254.170.2";
25
+ var EKS_CONTAINER_HOST_IPv4 = "169.254.170.23";
26
+ var EKS_CONTAINER_HOST_IPv6 = "[fd00:ec2::23]";
27
+ var checkUrl = (url, logger) => {
28
+ if (url.protocol === "https:") {
29
+ return;
30
+ }
31
+ if (url.hostname === ECS_CONTAINER_HOST || url.hostname === EKS_CONTAINER_HOST_IPv4 || url.hostname === EKS_CONTAINER_HOST_IPv6) {
32
+ return;
33
+ }
34
+ if (url.hostname.includes("[")) {
35
+ if (url.hostname === "[::1]" || url.hostname === "[0000:0000:0000:0000:0000:0000:0000:0001]") {
36
+ return;
37
+ }
38
+ } else {
39
+ if (url.hostname === "localhost") {
40
+ return;
41
+ }
42
+ const ipComponents = url.hostname.split(".");
43
+ const inRange = (component) => {
44
+ const num = parseInt(component, 10);
45
+ return 0 <= num && num <= 255;
46
+ };
47
+ if (ipComponents[0] === "127" && inRange(ipComponents[1]) && inRange(ipComponents[2]) && inRange(ipComponents[3]) && ipComponents.length === 4) {
48
+ return;
49
+ }
50
+ }
51
+ throw new CredentialsProviderError(`URL not accepted. It must either be HTTPS or match one of the following:
52
+ - loopback CIDR 127.0.0.0/8 or [::1/128]
53
+ - ECS container host 169.254.170.2
54
+ - EKS container host 169.254.170.23 or [fd00:ec2::23]`, { logger });
55
+ };
56
+
57
+ // ../../node_modules/.pnpm/@aws-sdk+credential-provider-http@3.972.26/node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/requestHelpers.js
58
+ function createGetRequest(url) {
59
+ return new HttpRequest({
60
+ protocol: url.protocol,
61
+ hostname: url.hostname,
62
+ port: Number(url.port),
63
+ path: url.pathname,
64
+ query: Array.from(url.searchParams.entries()).reduce((acc, [k, v]) => {
65
+ acc[k] = v;
66
+ return acc;
67
+ }, {}),
68
+ fragment: url.hash
69
+ });
70
+ }
71
+ async function getCredentials(response, logger) {
72
+ const stream = sdkStreamMixin(response.body);
73
+ const str = await stream.transformToString();
74
+ if (response.statusCode === 200) {
75
+ const parsed = JSON.parse(str);
76
+ if (typeof parsed.AccessKeyId !== "string" || typeof parsed.SecretAccessKey !== "string" || typeof parsed.Token !== "string" || typeof parsed.Expiration !== "string") {
77
+ throw new CredentialsProviderError("HTTP credential provider response not of the required format, an object matching: { AccessKeyId: string, SecretAccessKey: string, Token: string, Expiration: string(rfc3339) }", { logger });
78
+ }
79
+ return {
80
+ accessKeyId: parsed.AccessKeyId,
81
+ secretAccessKey: parsed.SecretAccessKey,
82
+ sessionToken: parsed.Token,
83
+ expiration: parseRfc3339DateTime(parsed.Expiration)
84
+ };
85
+ }
86
+ if (response.statusCode >= 400 && response.statusCode < 500) {
87
+ let parsedBody = {};
88
+ try {
89
+ parsedBody = JSON.parse(str);
90
+ } catch (e) {
91
+ }
92
+ throw Object.assign(new CredentialsProviderError(`Server responded with status: ${response.statusCode}`, { logger }), {
93
+ Code: parsedBody.Code,
94
+ Message: parsedBody.Message
95
+ });
96
+ }
97
+ throw new CredentialsProviderError(`Server responded with status: ${response.statusCode}`, { logger });
98
+ }
99
+
100
+ // ../../node_modules/.pnpm/@aws-sdk+credential-provider-http@3.972.26/node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/retry-wrapper.js
101
+ var retryWrapper = (toRetry, maxRetries, delayMs) => {
102
+ return async () => {
103
+ for (let i = 0; i < maxRetries; ++i) {
104
+ try {
105
+ return await toRetry();
106
+ } catch (e) {
107
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
108
+ }
109
+ }
110
+ return await toRetry();
111
+ };
112
+ };
113
+
114
+ // ../../node_modules/.pnpm/@aws-sdk+credential-provider-http@3.972.26/node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/fromHttp.js
115
+ var AWS_CONTAINER_CREDENTIALS_RELATIVE_URI = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI";
116
+ var DEFAULT_LINK_LOCAL_HOST = "http://169.254.170.2";
117
+ var AWS_CONTAINER_CREDENTIALS_FULL_URI = "AWS_CONTAINER_CREDENTIALS_FULL_URI";
118
+ var AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE = "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE";
119
+ var AWS_CONTAINER_AUTHORIZATION_TOKEN = "AWS_CONTAINER_AUTHORIZATION_TOKEN";
120
+ var fromHttp = (options = {}) => {
121
+ options.logger?.debug("@aws-sdk/credential-provider-http - fromHttp");
122
+ let host;
123
+ const relative = options.awsContainerCredentialsRelativeUri ?? process.env[AWS_CONTAINER_CREDENTIALS_RELATIVE_URI];
124
+ const full = options.awsContainerCredentialsFullUri ?? process.env[AWS_CONTAINER_CREDENTIALS_FULL_URI];
125
+ const token = options.awsContainerAuthorizationToken ?? process.env[AWS_CONTAINER_AUTHORIZATION_TOKEN];
126
+ const tokenFile = options.awsContainerAuthorizationTokenFile ?? process.env[AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE];
127
+ const warn = options.logger?.constructor?.name === "NoOpLogger" || !options.logger?.warn ? console.warn : options.logger.warn.bind(options.logger);
128
+ if (relative && full) {
129
+ warn("@aws-sdk/credential-provider-http: you have set both awsContainerCredentialsRelativeUri and awsContainerCredentialsFullUri.");
130
+ warn("awsContainerCredentialsFullUri will take precedence.");
131
+ }
132
+ if (token && tokenFile) {
133
+ warn("@aws-sdk/credential-provider-http: you have set both awsContainerAuthorizationToken and awsContainerAuthorizationTokenFile.");
134
+ warn("awsContainerAuthorizationToken will take precedence.");
135
+ }
136
+ if (full) {
137
+ host = full;
138
+ } else if (relative) {
139
+ host = `${DEFAULT_LINK_LOCAL_HOST}${relative}`;
140
+ } else {
141
+ throw new CredentialsProviderError(`No HTTP credential provider host provided.
142
+ Set AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI.`, { logger: options.logger });
143
+ }
144
+ const url = new URL(host);
145
+ checkUrl(url, options.logger);
146
+ const requestHandler = NodeHttpHandler.create({
147
+ requestTimeout: options.timeout ?? 1e3,
148
+ connectionTimeout: options.timeout ?? 1e3
149
+ });
150
+ return retryWrapper(async () => {
151
+ const request = createGetRequest(url);
152
+ if (token) {
153
+ request.headers.Authorization = token;
154
+ } else if (tokenFile) {
155
+ request.headers.Authorization = (await fs.readFile(tokenFile)).toString();
156
+ }
157
+ try {
158
+ const result = await requestHandler.handle(request);
159
+ return getCredentials(result.response).then((creds) => setCredentialFeature(creds, "CREDENTIALS_HTTP", "z"));
160
+ } catch (e) {
161
+ throw new CredentialsProviderError(String(e), { logger: options.logger });
162
+ }
163
+ }, options.maxRetries ?? 3, options.timeout ?? 1e3);
164
+ };
165
+ export {
166
+ fromHttp
167
+ };