storyforge 0.6.0 → 0.7.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.
@@ -0,0 +1,490 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ chain
4
+ } from "./chunk-56OB3EDN.js";
5
+ import {
6
+ getProfileName,
7
+ parseKnownFiles,
8
+ readFile
9
+ } from "./chunk-C5KB4UV6.js";
10
+ import {
11
+ HttpRequest
12
+ } from "./chunk-U6LFS35L.js";
13
+ import {
14
+ setCredentialFeature
15
+ } from "./chunk-CQ2IV4Q2.js";
16
+ import {
17
+ CredentialsProviderError
18
+ } from "./chunk-YLY3P6CS.js";
19
+ import "./chunk-NSPRIPOP.js";
20
+
21
+ // ../../node_modules/@aws-sdk/credential-provider-ini/dist-es/resolveCredentialSource.js
22
+ var resolveCredentialSource = (credentialSource, profileName, logger) => {
23
+ const sourceProvidersMap = {
24
+ EcsContainer: async (options) => {
25
+ const { fromHttp } = await import("./dist-es-KZQIITSZ.js");
26
+ const { fromContainerMetadata } = await import("./dist-es-4NQJAKNU.js");
27
+ logger?.debug("@aws-sdk/credential-provider-ini - credential_source is EcsContainer");
28
+ return async () => chain(fromHttp(options ?? {}), fromContainerMetadata(options))().then(setNamedProvider);
29
+ },
30
+ Ec2InstanceMetadata: async (options) => {
31
+ logger?.debug("@aws-sdk/credential-provider-ini - credential_source is Ec2InstanceMetadata");
32
+ const { fromInstanceMetadata } = await import("./dist-es-4NQJAKNU.js");
33
+ return async () => fromInstanceMetadata(options)().then(setNamedProvider);
34
+ },
35
+ Environment: async (options) => {
36
+ logger?.debug("@aws-sdk/credential-provider-ini - credential_source is Environment");
37
+ const { fromEnv } = await import("./dist-es-SXKTBYGM.js");
38
+ return async () => fromEnv(options)().then(setNamedProvider);
39
+ }
40
+ };
41
+ if (credentialSource in sourceProvidersMap) {
42
+ return sourceProvidersMap[credentialSource];
43
+ } else {
44
+ throw new CredentialsProviderError(`Unsupported credential source in profile ${profileName}. Got ${credentialSource}, expected EcsContainer or Ec2InstanceMetadata or Environment.`, { logger });
45
+ }
46
+ };
47
+ var setNamedProvider = (creds) => setCredentialFeature(creds, "CREDENTIALS_PROFILE_NAMED_PROVIDER", "p");
48
+
49
+ // ../../node_modules/@aws-sdk/credential-provider-ini/dist-es/resolveAssumeRoleCredentials.js
50
+ var isAssumeRoleProfile = (arg, { profile = "default", logger } = {}) => {
51
+ return Boolean(arg) && typeof arg === "object" && typeof arg.role_arn === "string" && ["undefined", "string"].indexOf(typeof arg.role_session_name) > -1 && ["undefined", "string"].indexOf(typeof arg.external_id) > -1 && ["undefined", "string"].indexOf(typeof arg.mfa_serial) > -1 && (isAssumeRoleWithSourceProfile(arg, { profile, logger }) || isCredentialSourceProfile(arg, { profile, logger }));
52
+ };
53
+ var isAssumeRoleWithSourceProfile = (arg, { profile, logger }) => {
54
+ const withSourceProfile = typeof arg.source_profile === "string" && typeof arg.credential_source === "undefined";
55
+ if (withSourceProfile) {
56
+ logger?.debug?.(` ${profile} isAssumeRoleWithSourceProfile source_profile=${arg.source_profile}`);
57
+ }
58
+ return withSourceProfile;
59
+ };
60
+ var isCredentialSourceProfile = (arg, { profile, logger }) => {
61
+ const withProviderProfile = typeof arg.credential_source === "string" && typeof arg.source_profile === "undefined";
62
+ if (withProviderProfile) {
63
+ logger?.debug?.(` ${profile} isCredentialSourceProfile credential_source=${arg.credential_source}`);
64
+ }
65
+ return withProviderProfile;
66
+ };
67
+ var resolveAssumeRoleCredentials = async (profileName, profiles, options, callerClientConfig, visitedProfiles = {}, resolveProfileData2) => {
68
+ options.logger?.debug("@aws-sdk/credential-provider-ini - resolveAssumeRoleCredentials (STS)");
69
+ const profileData = profiles[profileName];
70
+ const { source_profile, region } = profileData;
71
+ if (!options.roleAssumer) {
72
+ const { getDefaultRoleAssumer } = await import("./sts-PUI4IC7G.js");
73
+ options.roleAssumer = getDefaultRoleAssumer({
74
+ ...options.clientConfig,
75
+ credentialProviderLogger: options.logger,
76
+ parentClientConfig: {
77
+ ...callerClientConfig,
78
+ ...options?.parentClientConfig,
79
+ region: region ?? options?.parentClientConfig?.region ?? callerClientConfig?.region
80
+ }
81
+ }, options.clientPlugins);
82
+ }
83
+ if (source_profile && source_profile in visitedProfiles) {
84
+ throw new CredentialsProviderError(`Detected a cycle attempting to resolve credentials for profile ${getProfileName(options)}. Profiles visited: ` + Object.keys(visitedProfiles).join(", "), { logger: options.logger });
85
+ }
86
+ options.logger?.debug(`@aws-sdk/credential-provider-ini - finding credential resolver using ${source_profile ? `source_profile=[${source_profile}]` : `profile=[${profileName}]`}`);
87
+ const sourceCredsProvider = source_profile ? resolveProfileData2(source_profile, profiles, options, callerClientConfig, {
88
+ ...visitedProfiles,
89
+ [source_profile]: true
90
+ }, isCredentialSourceWithoutRoleArn(profiles[source_profile] ?? {})) : (await resolveCredentialSource(profileData.credential_source, profileName, options.logger)(options))();
91
+ if (isCredentialSourceWithoutRoleArn(profileData)) {
92
+ return sourceCredsProvider.then((creds) => setCredentialFeature(creds, "CREDENTIALS_PROFILE_SOURCE_PROFILE", "o"));
93
+ } else {
94
+ const params = {
95
+ RoleArn: profileData.role_arn,
96
+ RoleSessionName: profileData.role_session_name || `aws-sdk-js-${Date.now()}`,
97
+ ExternalId: profileData.external_id,
98
+ DurationSeconds: parseInt(profileData.duration_seconds || "3600", 10)
99
+ };
100
+ const { mfa_serial } = profileData;
101
+ if (mfa_serial) {
102
+ if (!options.mfaCodeProvider) {
103
+ throw new CredentialsProviderError(`Profile ${profileName} requires multi-factor authentication, but no MFA code callback was provided.`, { logger: options.logger, tryNextLink: false });
104
+ }
105
+ params.SerialNumber = mfa_serial;
106
+ params.TokenCode = await options.mfaCodeProvider(mfa_serial);
107
+ }
108
+ const sourceCreds = await sourceCredsProvider;
109
+ return options.roleAssumer(sourceCreds, params).then((creds) => setCredentialFeature(creds, "CREDENTIALS_PROFILE_SOURCE_PROFILE", "o"));
110
+ }
111
+ };
112
+ var isCredentialSourceWithoutRoleArn = (section) => {
113
+ return !section.role_arn && !!section.credential_source;
114
+ };
115
+
116
+ // ../../node_modules/@aws-sdk/credential-provider-login/dist-es/LoginCredentialsFetcher.js
117
+ import { createHash, createPrivateKey, createPublicKey, sign } from "crypto";
118
+ import { promises as fs } from "fs";
119
+ import { homedir } from "os";
120
+ import { dirname, join } from "path";
121
+ var LoginCredentialsFetcher = class _LoginCredentialsFetcher {
122
+ profileData;
123
+ init;
124
+ callerClientConfig;
125
+ static REFRESH_THRESHOLD = 5 * 60 * 1e3;
126
+ constructor(profileData, init, callerClientConfig) {
127
+ this.profileData = profileData;
128
+ this.init = init;
129
+ this.callerClientConfig = callerClientConfig;
130
+ }
131
+ async loadCredentials() {
132
+ const token = await this.loadToken();
133
+ if (!token) {
134
+ throw new CredentialsProviderError(`Failed to load a token for session ${this.loginSession}, please re-authenticate using aws login`, { tryNextLink: false, logger: this.logger });
135
+ }
136
+ const accessToken = token.accessToken;
137
+ const now = Date.now();
138
+ const expiryTime = new Date(accessToken.expiresAt).getTime();
139
+ const timeUntilExpiry = expiryTime - now;
140
+ if (timeUntilExpiry <= _LoginCredentialsFetcher.REFRESH_THRESHOLD) {
141
+ return this.refresh(token);
142
+ }
143
+ return {
144
+ accessKeyId: accessToken.accessKeyId,
145
+ secretAccessKey: accessToken.secretAccessKey,
146
+ sessionToken: accessToken.sessionToken,
147
+ accountId: accessToken.accountId,
148
+ expiration: new Date(accessToken.expiresAt)
149
+ };
150
+ }
151
+ get logger() {
152
+ return this.init?.logger;
153
+ }
154
+ get loginSession() {
155
+ return this.profileData.login_session;
156
+ }
157
+ async refresh(token) {
158
+ const { SigninClient, CreateOAuth2TokenCommand } = await import("./signin-TZJIHAWM.js");
159
+ const { logger, userAgentAppId } = this.callerClientConfig ?? {};
160
+ const isH2 = (requestHandler2) => {
161
+ return requestHandler2?.metadata?.handlerProtocol === "h2";
162
+ };
163
+ const requestHandler = isH2(this.callerClientConfig?.requestHandler) ? void 0 : this.callerClientConfig?.requestHandler;
164
+ const region = this.profileData.region ?? await this.callerClientConfig?.region?.() ?? process.env.AWS_REGION;
165
+ const client = new SigninClient({
166
+ credentials: {
167
+ accessKeyId: "",
168
+ secretAccessKey: ""
169
+ },
170
+ region,
171
+ requestHandler,
172
+ logger,
173
+ userAgentAppId,
174
+ ...this.init?.clientConfig
175
+ });
176
+ this.createDPoPInterceptor(client.middlewareStack);
177
+ const commandInput = {
178
+ tokenInput: {
179
+ clientId: token.clientId,
180
+ refreshToken: token.refreshToken,
181
+ grantType: "refresh_token"
182
+ }
183
+ };
184
+ try {
185
+ const response = await client.send(new CreateOAuth2TokenCommand(commandInput));
186
+ const { accessKeyId, secretAccessKey, sessionToken } = response.tokenOutput?.accessToken ?? {};
187
+ const { refreshToken, expiresIn } = response.tokenOutput ?? {};
188
+ if (!accessKeyId || !secretAccessKey || !sessionToken || !refreshToken) {
189
+ throw new CredentialsProviderError("Token refresh response missing required fields", {
190
+ logger: this.logger,
191
+ tryNextLink: false
192
+ });
193
+ }
194
+ const expiresInMs = (expiresIn ?? 900) * 1e3;
195
+ const expiration = new Date(Date.now() + expiresInMs);
196
+ const updatedToken = {
197
+ ...token,
198
+ accessToken: {
199
+ ...token.accessToken,
200
+ accessKeyId,
201
+ secretAccessKey,
202
+ sessionToken,
203
+ expiresAt: expiration.toISOString()
204
+ },
205
+ refreshToken
206
+ };
207
+ await this.saveToken(updatedToken);
208
+ const newAccessToken = updatedToken.accessToken;
209
+ return {
210
+ accessKeyId: newAccessToken.accessKeyId,
211
+ secretAccessKey: newAccessToken.secretAccessKey,
212
+ sessionToken: newAccessToken.sessionToken,
213
+ accountId: newAccessToken.accountId,
214
+ expiration
215
+ };
216
+ } catch (error) {
217
+ if (error.name === "AccessDeniedException") {
218
+ const errorType = error.error;
219
+ let message;
220
+ switch (errorType) {
221
+ case "TOKEN_EXPIRED":
222
+ message = "Your session has expired. Please reauthenticate.";
223
+ break;
224
+ case "USER_CREDENTIALS_CHANGED":
225
+ message = "Unable to refresh credentials because of a change in your password. Please reauthenticate with your new password.";
226
+ break;
227
+ case "INSUFFICIENT_PERMISSIONS":
228
+ message = "Unable to refresh credentials due to insufficient permissions. You may be missing permission for the 'CreateOAuth2Token' action.";
229
+ break;
230
+ default:
231
+ message = `Failed to refresh token: ${String(error)}. Please re-authenticate using \`aws login\``;
232
+ }
233
+ throw new CredentialsProviderError(message, { logger: this.logger, tryNextLink: false });
234
+ }
235
+ throw new CredentialsProviderError(`Failed to refresh token: ${String(error)}. Please re-authenticate using aws login`, { logger: this.logger });
236
+ }
237
+ }
238
+ async loadToken() {
239
+ const tokenFilePath = this.getTokenFilePath();
240
+ try {
241
+ let tokenData;
242
+ try {
243
+ tokenData = await readFile(tokenFilePath, { ignoreCache: this.init?.ignoreCache });
244
+ } catch {
245
+ tokenData = await fs.readFile(tokenFilePath, "utf8");
246
+ }
247
+ const token = JSON.parse(tokenData);
248
+ const missingFields = ["accessToken", "clientId", "refreshToken", "dpopKey"].filter((k) => !token[k]);
249
+ if (!token.accessToken?.accountId) {
250
+ missingFields.push("accountId");
251
+ }
252
+ if (missingFields.length > 0) {
253
+ throw new CredentialsProviderError(`Token validation failed, missing fields: ${missingFields.join(", ")}`, {
254
+ logger: this.logger,
255
+ tryNextLink: false
256
+ });
257
+ }
258
+ return token;
259
+ } catch (error) {
260
+ throw new CredentialsProviderError(`Failed to load token from ${tokenFilePath}: ${String(error)}`, {
261
+ logger: this.logger,
262
+ tryNextLink: false
263
+ });
264
+ }
265
+ }
266
+ async saveToken(token) {
267
+ const tokenFilePath = this.getTokenFilePath();
268
+ const directory = dirname(tokenFilePath);
269
+ try {
270
+ await fs.mkdir(directory, { recursive: true });
271
+ } catch (error) {
272
+ }
273
+ await fs.writeFile(tokenFilePath, JSON.stringify(token, null, 2), "utf8");
274
+ }
275
+ getTokenFilePath() {
276
+ const directory = process.env.AWS_LOGIN_CACHE_DIRECTORY ?? join(homedir(), ".aws", "login", "cache");
277
+ const loginSessionBytes = Buffer.from(this.loginSession, "utf8");
278
+ const loginSessionSha256 = createHash("sha256").update(loginSessionBytes).digest("hex");
279
+ return join(directory, `${loginSessionSha256}.json`);
280
+ }
281
+ derToRawSignature(derSignature) {
282
+ let offset = 2;
283
+ if (derSignature[offset] !== 2) {
284
+ throw new Error("Invalid DER signature");
285
+ }
286
+ offset++;
287
+ const rLength = derSignature[offset++];
288
+ let r = derSignature.subarray(offset, offset + rLength);
289
+ offset += rLength;
290
+ if (derSignature[offset] !== 2) {
291
+ throw new Error("Invalid DER signature");
292
+ }
293
+ offset++;
294
+ const sLength = derSignature[offset++];
295
+ let s = derSignature.subarray(offset, offset + sLength);
296
+ r = r[0] === 0 ? r.subarray(1) : r;
297
+ s = s[0] === 0 ? s.subarray(1) : s;
298
+ const rPadded = Buffer.concat([Buffer.alloc(32 - r.length), r]);
299
+ const sPadded = Buffer.concat([Buffer.alloc(32 - s.length), s]);
300
+ return Buffer.concat([rPadded, sPadded]);
301
+ }
302
+ createDPoPInterceptor(middlewareStack) {
303
+ middlewareStack.add((next) => async (args) => {
304
+ if (HttpRequest.isInstance(args.request)) {
305
+ const request = args.request;
306
+ const actualEndpoint = `${request.protocol}//${request.hostname}${request.port ? `:${request.port}` : ""}${request.path}`;
307
+ const dpop = await this.generateDpop(request.method, actualEndpoint);
308
+ request.headers = {
309
+ ...request.headers,
310
+ DPoP: dpop
311
+ };
312
+ }
313
+ return next(args);
314
+ }, {
315
+ step: "finalizeRequest",
316
+ name: "dpopInterceptor",
317
+ override: true
318
+ });
319
+ }
320
+ async generateDpop(method = "POST", endpoint) {
321
+ const token = await this.loadToken();
322
+ try {
323
+ const privateKey = createPrivateKey({
324
+ key: token.dpopKey,
325
+ format: "pem",
326
+ type: "sec1"
327
+ });
328
+ const publicKey = createPublicKey(privateKey);
329
+ const publicDer = publicKey.export({ format: "der", type: "spki" });
330
+ let pointStart = -1;
331
+ for (let i = 0; i < publicDer.length; i++) {
332
+ if (publicDer[i] === 4) {
333
+ pointStart = i;
334
+ break;
335
+ }
336
+ }
337
+ const x = publicDer.slice(pointStart + 1, pointStart + 33);
338
+ const y = publicDer.slice(pointStart + 33, pointStart + 65);
339
+ const header = {
340
+ alg: "ES256",
341
+ typ: "dpop+jwt",
342
+ jwk: {
343
+ kty: "EC",
344
+ crv: "P-256",
345
+ x: x.toString("base64url"),
346
+ y: y.toString("base64url")
347
+ }
348
+ };
349
+ const payload = {
350
+ jti: crypto.randomUUID(),
351
+ htm: method,
352
+ htu: endpoint,
353
+ iat: Math.floor(Date.now() / 1e3)
354
+ };
355
+ const headerB64 = Buffer.from(JSON.stringify(header)).toString("base64url");
356
+ const payloadB64 = Buffer.from(JSON.stringify(payload)).toString("base64url");
357
+ const message = `${headerB64}.${payloadB64}`;
358
+ const asn1Signature = sign("sha256", Buffer.from(message), privateKey);
359
+ const rawSignature = this.derToRawSignature(asn1Signature);
360
+ const signatureB64 = rawSignature.toString("base64url");
361
+ return `${message}.${signatureB64}`;
362
+ } catch (error) {
363
+ throw new CredentialsProviderError(`Failed to generate Dpop proof: ${error instanceof Error ? error.message : String(error)}`, { logger: this.logger, tryNextLink: false });
364
+ }
365
+ }
366
+ };
367
+
368
+ // ../../node_modules/@aws-sdk/credential-provider-login/dist-es/fromLoginCredentials.js
369
+ var fromLoginCredentials = (init) => async ({ callerClientConfig } = {}) => {
370
+ init?.logger?.debug?.("@aws-sdk/credential-providers - fromLoginCredentials");
371
+ const profiles = await parseKnownFiles(init || {});
372
+ const profileName = getProfileName({
373
+ profile: init?.profile ?? callerClientConfig?.profile
374
+ });
375
+ const profile = profiles[profileName];
376
+ if (!profile?.login_session) {
377
+ throw new CredentialsProviderError(`Profile ${profileName} does not contain login_session.`, {
378
+ tryNextLink: true,
379
+ logger: init?.logger
380
+ });
381
+ }
382
+ const fetcher = new LoginCredentialsFetcher(profile, init, callerClientConfig);
383
+ const credentials = await fetcher.loadCredentials();
384
+ return setCredentialFeature(credentials, "CREDENTIALS_LOGIN", "AD");
385
+ };
386
+
387
+ // ../../node_modules/@aws-sdk/credential-provider-ini/dist-es/resolveLoginCredentials.js
388
+ var isLoginProfile = (data) => {
389
+ return Boolean(data && data.login_session);
390
+ };
391
+ var resolveLoginCredentials = async (profileName, options, callerClientConfig) => {
392
+ const credentials = await fromLoginCredentials({
393
+ ...options,
394
+ profile: profileName
395
+ })({ callerClientConfig });
396
+ return setCredentialFeature(credentials, "CREDENTIALS_PROFILE_LOGIN", "AC");
397
+ };
398
+
399
+ // ../../node_modules/@aws-sdk/credential-provider-ini/dist-es/resolveProcessCredentials.js
400
+ var isProcessProfile = (arg) => Boolean(arg) && typeof arg === "object" && typeof arg.credential_process === "string";
401
+ var resolveProcessCredentials = async (options, profile) => import("./dist-es-2LINLMXN.js").then(({ fromProcess }) => fromProcess({
402
+ ...options,
403
+ profile
404
+ })().then((creds) => setCredentialFeature(creds, "CREDENTIALS_PROFILE_PROCESS", "v")));
405
+
406
+ // ../../node_modules/@aws-sdk/credential-provider-ini/dist-es/resolveSsoCredentials.js
407
+ var resolveSsoCredentials = async (profile, profileData, options = {}, callerClientConfig) => {
408
+ const { fromSSO } = await import("./dist-es-QJ3UEHQZ.js");
409
+ return fromSSO({
410
+ profile,
411
+ logger: options.logger,
412
+ parentClientConfig: options.parentClientConfig,
413
+ clientConfig: options.clientConfig
414
+ })({
415
+ callerClientConfig
416
+ }).then((creds) => {
417
+ if (profileData.sso_session) {
418
+ return setCredentialFeature(creds, "CREDENTIALS_PROFILE_SSO", "r");
419
+ } else {
420
+ return setCredentialFeature(creds, "CREDENTIALS_PROFILE_SSO_LEGACY", "t");
421
+ }
422
+ });
423
+ };
424
+ 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");
425
+
426
+ // ../../node_modules/@aws-sdk/credential-provider-ini/dist-es/resolveStaticCredentials.js
427
+ var isStaticCredsProfile = (arg) => Boolean(arg) && typeof arg === "object" && typeof arg.aws_access_key_id === "string" && typeof arg.aws_secret_access_key === "string" && ["undefined", "string"].indexOf(typeof arg.aws_session_token) > -1 && ["undefined", "string"].indexOf(typeof arg.aws_account_id) > -1;
428
+ var resolveStaticCredentials = async (profile, options) => {
429
+ options?.logger?.debug("@aws-sdk/credential-provider-ini - resolveStaticCredentials");
430
+ const credentials = {
431
+ accessKeyId: profile.aws_access_key_id,
432
+ secretAccessKey: profile.aws_secret_access_key,
433
+ sessionToken: profile.aws_session_token,
434
+ ...profile.aws_credential_scope && { credentialScope: profile.aws_credential_scope },
435
+ ...profile.aws_account_id && { accountId: profile.aws_account_id }
436
+ };
437
+ return setCredentialFeature(credentials, "CREDENTIALS_PROFILE", "n");
438
+ };
439
+
440
+ // ../../node_modules/@aws-sdk/credential-provider-ini/dist-es/resolveWebIdentityCredentials.js
441
+ var isWebIdentityProfile = (arg) => Boolean(arg) && typeof arg === "object" && typeof arg.web_identity_token_file === "string" && typeof arg.role_arn === "string" && ["undefined", "string"].indexOf(typeof arg.role_session_name) > -1;
442
+ var resolveWebIdentityCredentials = async (profile, options, callerClientConfig) => import("./dist-es-4RCBWWWT.js").then(({ fromTokenFile }) => fromTokenFile({
443
+ webIdentityTokenFile: profile.web_identity_token_file,
444
+ roleArn: profile.role_arn,
445
+ roleSessionName: profile.role_session_name,
446
+ roleAssumerWithWebIdentity: options.roleAssumerWithWebIdentity,
447
+ logger: options.logger,
448
+ parentClientConfig: options.parentClientConfig
449
+ })({
450
+ callerClientConfig
451
+ }).then((creds) => setCredentialFeature(creds, "CREDENTIALS_PROFILE_STS_WEB_ID_TOKEN", "q")));
452
+
453
+ // ../../node_modules/@aws-sdk/credential-provider-ini/dist-es/resolveProfileData.js
454
+ var resolveProfileData = async (profileName, profiles, options, callerClientConfig, visitedProfiles = {}, isAssumeRoleRecursiveCall = false) => {
455
+ const data = profiles[profileName];
456
+ if (Object.keys(visitedProfiles).length > 0 && isStaticCredsProfile(data)) {
457
+ return resolveStaticCredentials(data, options);
458
+ }
459
+ if (isAssumeRoleRecursiveCall || isAssumeRoleProfile(data, { profile: profileName, logger: options.logger })) {
460
+ return resolveAssumeRoleCredentials(profileName, profiles, options, callerClientConfig, visitedProfiles, resolveProfileData);
461
+ }
462
+ if (isStaticCredsProfile(data)) {
463
+ return resolveStaticCredentials(data, options);
464
+ }
465
+ if (isWebIdentityProfile(data)) {
466
+ return resolveWebIdentityCredentials(data, options, callerClientConfig);
467
+ }
468
+ if (isProcessProfile(data)) {
469
+ return resolveProcessCredentials(options, profileName);
470
+ }
471
+ if (isSsoProfile(data)) {
472
+ return await resolveSsoCredentials(profileName, data, options, callerClientConfig);
473
+ }
474
+ if (isLoginProfile(data)) {
475
+ return resolveLoginCredentials(profileName, options, callerClientConfig);
476
+ }
477
+ throw new CredentialsProviderError(`Could not resolve credentials using profile: [${profileName}] in configuration/credentials file(s).`, { logger: options.logger });
478
+ };
479
+
480
+ // ../../node_modules/@aws-sdk/credential-provider-ini/dist-es/fromIni.js
481
+ var fromIni = (init = {}) => async ({ callerClientConfig } = {}) => {
482
+ init.logger?.debug("@aws-sdk/credential-provider-ini - fromIni");
483
+ const profiles = await parseKnownFiles(init);
484
+ return resolveProfileData(getProfileName({
485
+ profile: init.profile ?? callerClientConfig?.profile
486
+ }), profiles, init, callerClientConfig);
487
+ };
488
+ export {
489
+ fromIni
490
+ };
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ sdkStreamMixin
4
+ } from "./chunk-L4BNY5R3.js";
5
+ import {
6
+ NodeHttpHandler,
7
+ parseRfc3339DateTime
8
+ } from "./chunk-2UXQZTSS.js";
9
+ import {
10
+ HttpRequest
11
+ } from "./chunk-U6LFS35L.js";
12
+ import "./chunk-ZHDWKDF5.js";
13
+ import {
14
+ setCredentialFeature
15
+ } from "./chunk-CQ2IV4Q2.js";
16
+ import {
17
+ CredentialsProviderError
18
+ } from "./chunk-YLY3P6CS.js";
19
+ import "./chunk-NSPRIPOP.js";
20
+
21
+ // ../../node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/fromHttp.js
22
+ import fs from "fs/promises";
23
+
24
+ // ../../node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/checkUrl.js
25
+ var ECS_CONTAINER_HOST = "169.254.170.2";
26
+ var EKS_CONTAINER_HOST_IPv4 = "169.254.170.23";
27
+ var EKS_CONTAINER_HOST_IPv6 = "[fd00:ec2::23]";
28
+ var checkUrl = (url, logger) => {
29
+ if (url.protocol === "https:") {
30
+ return;
31
+ }
32
+ if (url.hostname === ECS_CONTAINER_HOST || url.hostname === EKS_CONTAINER_HOST_IPv4 || url.hostname === EKS_CONTAINER_HOST_IPv6) {
33
+ return;
34
+ }
35
+ if (url.hostname.includes("[")) {
36
+ if (url.hostname === "[::1]" || url.hostname === "[0000:0000:0000:0000:0000:0000:0000:0001]") {
37
+ return;
38
+ }
39
+ } else {
40
+ if (url.hostname === "localhost") {
41
+ return;
42
+ }
43
+ const ipComponents = url.hostname.split(".");
44
+ const inRange = (component) => {
45
+ const num = parseInt(component, 10);
46
+ return 0 <= num && num <= 255;
47
+ };
48
+ if (ipComponents[0] === "127" && inRange(ipComponents[1]) && inRange(ipComponents[2]) && inRange(ipComponents[3]) && ipComponents.length === 4) {
49
+ return;
50
+ }
51
+ }
52
+ throw new CredentialsProviderError(`URL not accepted. It must either be HTTPS or match one of the following:
53
+ - loopback CIDR 127.0.0.0/8 or [::1/128]
54
+ - ECS container host 169.254.170.2
55
+ - EKS container host 169.254.170.23 or [fd00:ec2::23]`, { logger });
56
+ };
57
+
58
+ // ../../node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/requestHelpers.js
59
+ function createGetRequest(url) {
60
+ return new HttpRequest({
61
+ protocol: url.protocol,
62
+ hostname: url.hostname,
63
+ port: Number(url.port),
64
+ path: url.pathname,
65
+ query: Array.from(url.searchParams.entries()).reduce((acc, [k, v]) => {
66
+ acc[k] = v;
67
+ return acc;
68
+ }, {}),
69
+ fragment: url.hash
70
+ });
71
+ }
72
+ async function getCredentials(response, logger) {
73
+ const stream = sdkStreamMixin(response.body);
74
+ const str = await stream.transformToString();
75
+ if (response.statusCode === 200) {
76
+ const parsed = JSON.parse(str);
77
+ if (typeof parsed.AccessKeyId !== "string" || typeof parsed.SecretAccessKey !== "string" || typeof parsed.Token !== "string" || typeof parsed.Expiration !== "string") {
78
+ 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 });
79
+ }
80
+ return {
81
+ accessKeyId: parsed.AccessKeyId,
82
+ secretAccessKey: parsed.SecretAccessKey,
83
+ sessionToken: parsed.Token,
84
+ expiration: parseRfc3339DateTime(parsed.Expiration)
85
+ };
86
+ }
87
+ if (response.statusCode >= 400 && response.statusCode < 500) {
88
+ let parsedBody = {};
89
+ try {
90
+ parsedBody = JSON.parse(str);
91
+ } catch (e) {
92
+ }
93
+ throw Object.assign(new CredentialsProviderError(`Server responded with status: ${response.statusCode}`, { logger }), {
94
+ Code: parsedBody.Code,
95
+ Message: parsedBody.Message
96
+ });
97
+ }
98
+ throw new CredentialsProviderError(`Server responded with status: ${response.statusCode}`, { logger });
99
+ }
100
+
101
+ // ../../node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/retry-wrapper.js
102
+ var retryWrapper = (toRetry, maxRetries, delayMs) => {
103
+ return async () => {
104
+ for (let i = 0; i < maxRetries; ++i) {
105
+ try {
106
+ return await toRetry();
107
+ } catch (e) {
108
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
109
+ }
110
+ }
111
+ return await toRetry();
112
+ };
113
+ };
114
+
115
+ // ../../node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/fromHttp.js
116
+ var AWS_CONTAINER_CREDENTIALS_RELATIVE_URI = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI";
117
+ var DEFAULT_LINK_LOCAL_HOST = "http://169.254.170.2";
118
+ var AWS_CONTAINER_CREDENTIALS_FULL_URI = "AWS_CONTAINER_CREDENTIALS_FULL_URI";
119
+ var AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE = "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE";
120
+ var AWS_CONTAINER_AUTHORIZATION_TOKEN = "AWS_CONTAINER_AUTHORIZATION_TOKEN";
121
+ var fromHttp = (options = {}) => {
122
+ options.logger?.debug("@aws-sdk/credential-provider-http - fromHttp");
123
+ let host;
124
+ const relative = options.awsContainerCredentialsRelativeUri ?? process.env[AWS_CONTAINER_CREDENTIALS_RELATIVE_URI];
125
+ const full = options.awsContainerCredentialsFullUri ?? process.env[AWS_CONTAINER_CREDENTIALS_FULL_URI];
126
+ const token = options.awsContainerAuthorizationToken ?? process.env[AWS_CONTAINER_AUTHORIZATION_TOKEN];
127
+ const tokenFile = options.awsContainerAuthorizationTokenFile ?? process.env[AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE];
128
+ const warn = options.logger?.constructor?.name === "NoOpLogger" || !options.logger?.warn ? console.warn : options.logger.warn.bind(options.logger);
129
+ if (relative && full) {
130
+ warn("@aws-sdk/credential-provider-http: you have set both awsContainerCredentialsRelativeUri and awsContainerCredentialsFullUri.");
131
+ warn("awsContainerCredentialsFullUri will take precedence.");
132
+ }
133
+ if (token && tokenFile) {
134
+ warn("@aws-sdk/credential-provider-http: you have set both awsContainerAuthorizationToken and awsContainerAuthorizationTokenFile.");
135
+ warn("awsContainerAuthorizationToken will take precedence.");
136
+ }
137
+ if (full) {
138
+ host = full;
139
+ } else if (relative) {
140
+ host = `${DEFAULT_LINK_LOCAL_HOST}${relative}`;
141
+ } else {
142
+ throw new CredentialsProviderError(`No HTTP credential provider host provided.
143
+ Set AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI.`, { logger: options.logger });
144
+ }
145
+ const url = new URL(host);
146
+ checkUrl(url, options.logger);
147
+ const requestHandler = NodeHttpHandler.create({
148
+ requestTimeout: options.timeout ?? 1e3,
149
+ connectionTimeout: options.timeout ?? 1e3
150
+ });
151
+ return retryWrapper(async () => {
152
+ const request = createGetRequest(url);
153
+ if (token) {
154
+ request.headers.Authorization = token;
155
+ } else if (tokenFile) {
156
+ request.headers.Authorization = (await fs.readFile(tokenFile)).toString();
157
+ }
158
+ try {
159
+ const result = await requestHandler.handle(request);
160
+ return getCredentials(result.response).then((creds) => setCredentialFeature(creds, "CREDENTIALS_HTTP", "z"));
161
+ } catch (e) {
162
+ throw new CredentialsProviderError(String(e), { logger: options.logger });
163
+ }
164
+ }, options.maxRetries ?? 3, options.timeout ?? 1e3);
165
+ };
166
+ export {
167
+ fromHttp
168
+ };