openship 0.3.0 → 0.4.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.
Files changed (82) hide show
  1. package/README.md +104 -61
  2. package/dist/bare-ITM45QBX.js +18 -0
  3. package/dist/bowser-MFQA6OS4.js +2821 -0
  4. package/dist/chunk-3U4SPZD5.js +241 -0
  5. package/dist/chunk-46YJFP4S.js +1771 -0
  6. package/dist/chunk-4CQWT2WL.js +116 -0
  7. package/dist/chunk-4FABQGQP.js +23 -0
  8. package/dist/chunk-4LEL3H2Z.js +84 -0
  9. package/dist/chunk-4MG3BVHE.js +326 -0
  10. package/dist/chunk-4VNS5WPM.js +42 -0
  11. package/dist/chunk-5N7VUGL6.js +2094 -0
  12. package/dist/chunk-5ZCKQ2MI.js +1360 -0
  13. package/dist/chunk-6ERIMTBC.js +1412 -0
  14. package/dist/chunk-7UOB5GGQ.js +132 -0
  15. package/dist/chunk-BUBSSKO6.js +1384 -0
  16. package/dist/chunk-E6W2JMMU.js +341 -0
  17. package/dist/chunk-E77LJWJK.js +1535 -0
  18. package/dist/chunk-F4DFVG6Q.js +573 -0
  19. package/dist/chunk-HFYDYK4D.js +1092 -0
  20. package/dist/chunk-JR2OCMJA.js +46 -0
  21. package/dist/chunk-JUJBBF5U.js +746 -0
  22. package/dist/chunk-JZLNHGLW.js +19145 -0
  23. package/dist/chunk-KD7VO4LG.js +2617 -0
  24. package/dist/chunk-LBFH7THC.js +435 -0
  25. package/dist/chunk-NB2VEIWG.js +129 -0
  26. package/dist/chunk-OJE6YWPQ.js +2866 -0
  27. package/dist/chunk-QKFRZNKN.js +4941 -0
  28. package/dist/chunk-RBZPFTHV.js +13354 -0
  29. package/dist/chunk-S6DSRLNE.js +121 -0
  30. package/dist/chunk-TEYJYSMT.js +409 -0
  31. package/dist/chunk-U2DPZSXA.js +112 -0
  32. package/dist/chunk-WJPCBU7Z.js +3147 -0
  33. package/dist/chunk-XIFRMKYT.js +13 -0
  34. package/dist/chunk-XVSAUO2I.js +7946 -0
  35. package/dist/chunk-Y37KHU7L.js +31 -0
  36. package/dist/chunk-YL67EWYZ.js +416 -0
  37. package/dist/chunk-ZKJOFWBJ.js +1879 -0
  38. package/dist/cloud-JMPHO3CW.js +7 -0
  39. package/dist/cloud-W5G6YXAY.js +24 -0
  40. package/dist/dist-L3MPOWCA.js +65 -0
  41. package/dist/dist-es-4C322O5D.js +22 -0
  42. package/dist/dist-es-GTAMF674.js +87 -0
  43. package/dist/dist-es-KE56MWYO.js +169 -0
  44. package/dist/dist-es-NRZIQY5B.js +484 -0
  45. package/dist/dist-es-WZCR7DHQ.js +317 -0
  46. package/dist/dist-es-XQCOTGC7.js +376 -0
  47. package/dist/dist-es-ZW3HFQUM.js +69 -0
  48. package/dist/docker-3FVJMFC3.js +12 -0
  49. package/dist/docker-edge-executor-ZIWAZWPL.js +9 -0
  50. package/dist/edge-import-53M5DGWZ.js +39 -0
  51. package/dist/event-streams-7LGDL56D.js +42 -0
  52. package/dist/executor-J7BHW5HF.js +26 -0
  53. package/dist/index.js +2450 -3484
  54. package/dist/loadSso-N273C5I7.js +577 -0
  55. package/dist/nginx-YZWKYKQU.js +16 -0
  56. package/dist/noop-RRNCIUI5.js +7 -0
  57. package/dist/openresty-lua-HAO4EUDY.js +32 -0
  58. package/dist/server/index.js +230533 -217891
  59. package/dist/server/migrations/0057_complete_prism.sql +18 -0
  60. package/dist/server/migrations/0058_add_server_is_local.sql +1 -0
  61. package/dist/server/migrations/0059_legal_fixer.sql +18 -0
  62. package/dist/server/migrations/0060_add_route_strategy_host_port.sql +3 -0
  63. package/dist/server/migrations/0061_notification_default_multi_kind.sql +3 -0
  64. package/dist/server/migrations/0062_add_incoming_webhook.sql +21 -0
  65. package/dist/server/migrations/0063_add_migration_logs.sql +1 -0
  66. package/dist/server/migrations/0064_add_migration_partial.sql +2 -0
  67. package/dist/server/migrations/0065_custom_app_template.sql +14 -0
  68. package/dist/server/migrations/0066_ensure_migration_partial_columns.sql +2 -0
  69. package/dist/server/migrations/0067_webhook_delivery.sql +28 -0
  70. package/dist/server/migrations/0068_add_migration_target_volumes.sql +1 -0
  71. package/dist/server/migrations/0069_add_project_composite_routes.sql +1 -0
  72. package/dist/server/migrations/0070_forward_git_to_server.sql +1 -0
  73. package/dist/server/migrations/meta/0057_snapshot.json +9326 -0
  74. package/dist/server/migrations/meta/0058_snapshot.json +9333 -0
  75. package/dist/server/migrations/meta/0059_snapshot.json +9495 -0
  76. package/dist/server/migrations/meta/0060_snapshot.json +9515 -0
  77. package/dist/server/migrations/meta/_journal.json +99 -1
  78. package/dist/setup-5X3WEEHA.js +14 -0
  79. package/dist/signin-DR462ERO.js +663 -0
  80. package/dist/sso-oidc-VBZLJUK5.js +830 -0
  81. package/dist/sts-EJLZ4Z77.js +1422 -0
  82. package/package.json +6 -2
@@ -0,0 +1,317 @@
1
+ import {
2
+ setCredentialFeature
3
+ } from "./chunk-OJE6YWPQ.js";
4
+ import {
5
+ CredentialsProviderError,
6
+ TokenProviderError,
7
+ getProfileName,
8
+ getSSOTokenFilepath,
9
+ getSSOTokenFromFile,
10
+ loadSsoSessionData,
11
+ parseKnownFiles
12
+ } from "./chunk-5N7VUGL6.js";
13
+ import "./chunk-6ERIMTBC.js";
14
+ import "./chunk-4VNS5WPM.js";
15
+
16
+ // ../../node_modules/@aws-sdk/credential-provider-sso/dist-es/isSsoProfile.js
17
+ 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");
18
+
19
+ // ../../node_modules/@aws-sdk/token-providers/dist-es/constants.js
20
+ var EXPIRE_WINDOW_MS = 5 * 60 * 1e3;
21
+ var REFRESH_MESSAGE = `To refresh this SSO session run 'aws sso login' with the corresponding profile.`;
22
+
23
+ // ../../node_modules/@aws-sdk/token-providers/dist-es/getSsoOidcClient.js
24
+ var getSsoOidcClient = async (ssoRegion, init = {}, callerClientConfig) => {
25
+ const { SSOOIDCClient } = await import("./sso-oidc-VBZLJUK5.js");
26
+ const coalesce = (prop) => init.clientConfig?.[prop] ?? init.parentClientConfig?.[prop] ?? callerClientConfig?.[prop];
27
+ const ssoOidcClient = new SSOOIDCClient(Object.assign({}, init.clientConfig ?? {}, {
28
+ region: ssoRegion ?? init.clientConfig?.region,
29
+ logger: coalesce("logger"),
30
+ userAgentAppId: coalesce("userAgentAppId")
31
+ }));
32
+ return ssoOidcClient;
33
+ };
34
+
35
+ // ../../node_modules/@aws-sdk/token-providers/dist-es/getNewSsoOidcToken.js
36
+ var getNewSsoOidcToken = async (ssoToken, ssoRegion, init = {}, callerClientConfig) => {
37
+ const { CreateTokenCommand } = await import("./sso-oidc-VBZLJUK5.js");
38
+ const ssoOidcClient = await getSsoOidcClient(ssoRegion, init, callerClientConfig);
39
+ return ssoOidcClient.send(new CreateTokenCommand({
40
+ clientId: ssoToken.clientId,
41
+ clientSecret: ssoToken.clientSecret,
42
+ refreshToken: ssoToken.refreshToken,
43
+ grantType: "refresh_token"
44
+ }));
45
+ };
46
+
47
+ // ../../node_modules/@aws-sdk/token-providers/dist-es/validateTokenExpiry.js
48
+ var validateTokenExpiry = (token) => {
49
+ if (token.expiration && token.expiration.getTime() < Date.now()) {
50
+ throw new TokenProviderError(`Token is expired. ${REFRESH_MESSAGE}`, false);
51
+ }
52
+ };
53
+
54
+ // ../../node_modules/@aws-sdk/token-providers/dist-es/validateTokenKey.js
55
+ var validateTokenKey = (key, value, forRefresh = false) => {
56
+ if (typeof value === "undefined") {
57
+ throw new TokenProviderError(`Value not present for '${key}' in SSO Token${forRefresh ? ". Cannot refresh" : ""}. ${REFRESH_MESSAGE}`, false);
58
+ }
59
+ };
60
+
61
+ // ../../node_modules/@aws-sdk/token-providers/dist-es/writeSSOTokenToFile.js
62
+ import { promises as fsPromises } from "fs";
63
+ var { writeFile } = fsPromises;
64
+ var writeSSOTokenToFile = (id, ssoToken) => {
65
+ const tokenFilepath = getSSOTokenFilepath(id);
66
+ const tokenString = JSON.stringify(ssoToken, null, 2);
67
+ return writeFile(tokenFilepath, tokenString);
68
+ };
69
+
70
+ // ../../node_modules/@aws-sdk/token-providers/dist-es/fromSso.js
71
+ var lastRefreshAttemptTime = /* @__PURE__ */ new Date(0);
72
+ var fromSso = (init = {}) => async ({ callerClientConfig } = {}) => {
73
+ init.logger?.debug("@aws-sdk/token-providers - fromSso");
74
+ const profiles = await parseKnownFiles(init);
75
+ const profileName = getProfileName({
76
+ profile: init.profile ?? callerClientConfig?.profile
77
+ });
78
+ const profile = profiles[profileName];
79
+ if (!profile) {
80
+ throw new TokenProviderError(`Profile '${profileName}' could not be found in shared credentials file.`, false);
81
+ } else if (!profile["sso_session"]) {
82
+ throw new TokenProviderError(`Profile '${profileName}' is missing required property 'sso_session'.`);
83
+ }
84
+ const ssoSessionName = profile["sso_session"];
85
+ const ssoSessions = await loadSsoSessionData(init);
86
+ const ssoSession = ssoSessions[ssoSessionName];
87
+ if (!ssoSession) {
88
+ throw new TokenProviderError(`Sso session '${ssoSessionName}' could not be found in shared credentials file.`, false);
89
+ }
90
+ for (const ssoSessionRequiredKey of ["sso_start_url", "sso_region"]) {
91
+ if (!ssoSession[ssoSessionRequiredKey]) {
92
+ throw new TokenProviderError(`Sso session '${ssoSessionName}' is missing required property '${ssoSessionRequiredKey}'.`, false);
93
+ }
94
+ }
95
+ const ssoStartUrl = ssoSession["sso_start_url"];
96
+ const ssoRegion = ssoSession["sso_region"];
97
+ let ssoToken;
98
+ try {
99
+ ssoToken = await getSSOTokenFromFile(ssoSessionName);
100
+ } catch (e) {
101
+ throw new TokenProviderError(`The SSO session token associated with profile=${profileName} was not found or is invalid. ${REFRESH_MESSAGE}`, false);
102
+ }
103
+ validateTokenKey("accessToken", ssoToken.accessToken);
104
+ validateTokenKey("expiresAt", ssoToken.expiresAt);
105
+ const { accessToken, expiresAt } = ssoToken;
106
+ const existingToken = { token: accessToken, expiration: new Date(expiresAt) };
107
+ if (existingToken.expiration.getTime() - Date.now() > EXPIRE_WINDOW_MS) {
108
+ return existingToken;
109
+ }
110
+ if (Date.now() - lastRefreshAttemptTime.getTime() < 30 * 1e3) {
111
+ validateTokenExpiry(existingToken);
112
+ return existingToken;
113
+ }
114
+ validateTokenKey("clientId", ssoToken.clientId, true);
115
+ validateTokenKey("clientSecret", ssoToken.clientSecret, true);
116
+ validateTokenKey("refreshToken", ssoToken.refreshToken, true);
117
+ try {
118
+ lastRefreshAttemptTime.setTime(Date.now());
119
+ const newSsoOidcToken = await getNewSsoOidcToken(ssoToken, ssoRegion, init, callerClientConfig);
120
+ validateTokenKey("accessToken", newSsoOidcToken.accessToken);
121
+ validateTokenKey("expiresIn", newSsoOidcToken.expiresIn);
122
+ const newTokenExpiration = new Date(Date.now() + newSsoOidcToken.expiresIn * 1e3);
123
+ try {
124
+ await writeSSOTokenToFile(ssoSessionName, {
125
+ ...ssoToken,
126
+ accessToken: newSsoOidcToken.accessToken,
127
+ expiresAt: newTokenExpiration.toISOString(),
128
+ refreshToken: newSsoOidcToken.refreshToken
129
+ });
130
+ } catch (error) {
131
+ }
132
+ return {
133
+ token: newSsoOidcToken.accessToken,
134
+ expiration: newTokenExpiration
135
+ };
136
+ } catch (error) {
137
+ validateTokenExpiry(existingToken);
138
+ return existingToken;
139
+ }
140
+ };
141
+
142
+ // ../../node_modules/@aws-sdk/credential-provider-sso/dist-es/resolveSSOCredentials.js
143
+ var SHOULD_FAIL_CREDENTIAL_CHAIN = false;
144
+ var resolveSSOCredentials = async ({ ssoStartUrl, ssoSession, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, clientConfig, parentClientConfig, callerClientConfig, profile, filepath, configFilepath, ignoreCache, logger }) => {
145
+ let token;
146
+ const refreshMessage = `To refresh this SSO session run aws sso login with the corresponding profile.`;
147
+ if (ssoSession) {
148
+ try {
149
+ const _token = await fromSso({
150
+ profile,
151
+ filepath,
152
+ configFilepath,
153
+ ignoreCache,
154
+ clientConfig,
155
+ parentClientConfig,
156
+ logger
157
+ })({ callerClientConfig });
158
+ token = {
159
+ accessToken: _token.token,
160
+ expiresAt: new Date(_token.expiration).toISOString()
161
+ };
162
+ } catch (e) {
163
+ throw new CredentialsProviderError(e.message, {
164
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
165
+ logger
166
+ });
167
+ }
168
+ } else {
169
+ try {
170
+ token = await getSSOTokenFromFile(ssoStartUrl);
171
+ } catch (e) {
172
+ throw new CredentialsProviderError(`The SSO session associated with this profile is invalid. ${refreshMessage}`, {
173
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
174
+ logger
175
+ });
176
+ }
177
+ }
178
+ if (new Date(token.expiresAt).getTime() - Date.now() <= 0) {
179
+ throw new CredentialsProviderError(`The SSO session associated with this profile has expired. ${refreshMessage}`, {
180
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
181
+ logger
182
+ });
183
+ }
184
+ const { accessToken } = token;
185
+ const { SSOClient, GetRoleCredentialsCommand } = await import("./loadSso-N273C5I7.js");
186
+ const sso = ssoClient || new SSOClient(Object.assign({}, clientConfig ?? {}, {
187
+ logger: clientConfig?.logger ?? callerClientConfig?.logger ?? parentClientConfig?.logger,
188
+ region: clientConfig?.region ?? ssoRegion,
189
+ userAgentAppId: clientConfig?.userAgentAppId ?? callerClientConfig?.userAgentAppId ?? parentClientConfig?.userAgentAppId
190
+ }));
191
+ let ssoResp;
192
+ try {
193
+ ssoResp = await sso.send(new GetRoleCredentialsCommand({
194
+ accountId: ssoAccountId,
195
+ roleName: ssoRoleName,
196
+ accessToken
197
+ }));
198
+ } catch (e) {
199
+ throw new CredentialsProviderError(e, {
200
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
201
+ logger
202
+ });
203
+ }
204
+ const { roleCredentials: { accessKeyId, secretAccessKey, sessionToken, expiration, credentialScope, accountId } = {} } = ssoResp;
205
+ if (!accessKeyId || !secretAccessKey || !sessionToken || !expiration) {
206
+ throw new CredentialsProviderError("SSO returns an invalid temporary credential.", {
207
+ tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
208
+ logger
209
+ });
210
+ }
211
+ const credentials = {
212
+ accessKeyId,
213
+ secretAccessKey,
214
+ sessionToken,
215
+ expiration: new Date(expiration),
216
+ ...credentialScope && { credentialScope },
217
+ ...accountId && { accountId }
218
+ };
219
+ if (ssoSession) {
220
+ setCredentialFeature(credentials, "CREDENTIALS_SSO", "s");
221
+ } else {
222
+ setCredentialFeature(credentials, "CREDENTIALS_SSO_LEGACY", "u");
223
+ }
224
+ return credentials;
225
+ };
226
+
227
+ // ../../node_modules/@aws-sdk/credential-provider-sso/dist-es/validateSsoProfile.js
228
+ var validateSsoProfile = (profile, logger) => {
229
+ const { sso_start_url, sso_account_id, sso_region, sso_role_name } = profile;
230
+ if (!sso_start_url || !sso_account_id || !sso_region || !sso_role_name) {
231
+ 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(", ")}
232
+ Reference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html`, { tryNextLink: false, logger });
233
+ }
234
+ return profile;
235
+ };
236
+
237
+ // ../../node_modules/@aws-sdk/credential-provider-sso/dist-es/fromSSO.js
238
+ var fromSSO = (init = {}) => async ({ callerClientConfig } = {}) => {
239
+ init.logger?.debug("@aws-sdk/credential-provider-sso - fromSSO");
240
+ const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoSession } = init;
241
+ const { ssoClient } = init;
242
+ const profileName = getProfileName({
243
+ profile: init.profile ?? callerClientConfig?.profile
244
+ });
245
+ if (!ssoStartUrl && !ssoAccountId && !ssoRegion && !ssoRoleName && !ssoSession) {
246
+ const profiles = await parseKnownFiles(init);
247
+ const profile = profiles[profileName];
248
+ if (!profile) {
249
+ throw new CredentialsProviderError(`Profile ${profileName} was not found.`, { logger: init.logger });
250
+ }
251
+ if (!isSsoProfile(profile)) {
252
+ throw new CredentialsProviderError(`Profile ${profileName} is not configured with SSO credentials.`, {
253
+ logger: init.logger
254
+ });
255
+ }
256
+ if (profile?.sso_session) {
257
+ const ssoSessions = await loadSsoSessionData(init);
258
+ const session = ssoSessions[profile.sso_session];
259
+ const conflictMsg = ` configurations in profile ${profileName} and sso-session ${profile.sso_session}`;
260
+ if (ssoRegion && ssoRegion !== session.sso_region) {
261
+ throw new CredentialsProviderError(`Conflicting SSO region` + conflictMsg, {
262
+ tryNextLink: false,
263
+ logger: init.logger
264
+ });
265
+ }
266
+ if (ssoStartUrl && ssoStartUrl !== session.sso_start_url) {
267
+ throw new CredentialsProviderError(`Conflicting SSO start_url` + conflictMsg, {
268
+ tryNextLink: false,
269
+ logger: init.logger
270
+ });
271
+ }
272
+ profile.sso_region = session.sso_region;
273
+ profile.sso_start_url = session.sso_start_url;
274
+ }
275
+ const { sso_start_url, sso_account_id, sso_region, sso_role_name, sso_session } = validateSsoProfile(profile, init.logger);
276
+ return resolveSSOCredentials({
277
+ ssoStartUrl: sso_start_url,
278
+ ssoSession: sso_session,
279
+ ssoAccountId: sso_account_id,
280
+ ssoRegion: sso_region,
281
+ ssoRoleName: sso_role_name,
282
+ ssoClient,
283
+ clientConfig: init.clientConfig,
284
+ parentClientConfig: init.parentClientConfig,
285
+ callerClientConfig: init.callerClientConfig,
286
+ profile: profileName,
287
+ filepath: init.filepath,
288
+ configFilepath: init.configFilepath,
289
+ ignoreCache: init.ignoreCache,
290
+ logger: init.logger
291
+ });
292
+ } else if (!ssoStartUrl || !ssoAccountId || !ssoRegion || !ssoRoleName) {
293
+ throw new CredentialsProviderError('Incomplete configuration. The fromSSO() argument hash must include "ssoStartUrl", "ssoAccountId", "ssoRegion", "ssoRoleName"', { tryNextLink: false, logger: init.logger });
294
+ } else {
295
+ return resolveSSOCredentials({
296
+ ssoStartUrl,
297
+ ssoSession,
298
+ ssoAccountId,
299
+ ssoRegion,
300
+ ssoRoleName,
301
+ ssoClient,
302
+ clientConfig: init.clientConfig,
303
+ parentClientConfig: init.parentClientConfig,
304
+ callerClientConfig: init.callerClientConfig,
305
+ profile: profileName,
306
+ filepath: init.filepath,
307
+ configFilepath: init.configFilepath,
308
+ ignoreCache: init.ignoreCache,
309
+ logger: init.logger
310
+ });
311
+ }
312
+ };
313
+ export {
314
+ fromSSO,
315
+ isSsoProfile,
316
+ validateSsoProfile
317
+ };
@@ -0,0 +1,376 @@
1
+ import {
2
+ CredentialsProviderError,
3
+ ProviderError,
4
+ loadConfig,
5
+ parseUrl
6
+ } from "./chunk-5N7VUGL6.js";
7
+ import "./chunk-6ERIMTBC.js";
8
+ import "./chunk-4VNS5WPM.js";
9
+
10
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/remoteProvider/ImdsCredentials.js
11
+ var isImdsCredentials = (arg) => Boolean(arg) && typeof arg === "object" && typeof arg.AccessKeyId === "string" && typeof arg.SecretAccessKey === "string" && typeof arg.Token === "string" && typeof arg.Expiration === "string";
12
+ var fromImdsCredentials = (creds) => ({
13
+ accessKeyId: creds.AccessKeyId,
14
+ secretAccessKey: creds.SecretAccessKey,
15
+ sessionToken: creds.Token,
16
+ expiration: new Date(creds.Expiration),
17
+ ...creds.AccountId && { accountId: creds.AccountId }
18
+ });
19
+
20
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/remoteProvider/RemoteProviderInit.js
21
+ var DEFAULT_TIMEOUT = 1e3;
22
+ var DEFAULT_MAX_RETRIES = 0;
23
+ var providerConfigFromInit = ({ maxRetries = DEFAULT_MAX_RETRIES, timeout = DEFAULT_TIMEOUT }) => ({ maxRetries, timeout });
24
+
25
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/remoteProvider/node-http.js
26
+ import node_http from "http";
27
+
28
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/remoteProvider/httpRequest.js
29
+ function httpRequest(options) {
30
+ return new Promise((resolve, reject) => {
31
+ const req = node_http.request({
32
+ method: "GET",
33
+ ...options,
34
+ hostname: options.hostname?.replace(/^\[(.+)\]$/, "$1")
35
+ });
36
+ req.on("error", (err) => {
37
+ reject(Object.assign(new ProviderError("Unable to connect to instance metadata service"), err));
38
+ req.destroy();
39
+ });
40
+ req.on("timeout", () => {
41
+ reject(new ProviderError("TimeoutError from instance metadata service"));
42
+ req.destroy();
43
+ });
44
+ req.on("response", (res) => {
45
+ const { statusCode = 400 } = res;
46
+ if (statusCode < 200 || 300 <= statusCode) {
47
+ reject(Object.assign(new ProviderError("Error response received from instance metadata service"), { statusCode }));
48
+ req.destroy();
49
+ }
50
+ const chunks = [];
51
+ res.on("data", (chunk) => {
52
+ chunks.push(chunk);
53
+ });
54
+ res.on("end", () => {
55
+ resolve(Buffer.concat(chunks));
56
+ req.destroy();
57
+ });
58
+ });
59
+ req.end();
60
+ });
61
+ }
62
+
63
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/remoteProvider/retry.js
64
+ var retry = (toRetry, maxRetries) => {
65
+ let promise = toRetry();
66
+ for (let i = 0; i < maxRetries; i++) {
67
+ promise = promise.catch(toRetry);
68
+ }
69
+ return promise;
70
+ };
71
+
72
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/fromContainerMetadata.js
73
+ var ENV_CMDS_FULL_URI = "AWS_CONTAINER_CREDENTIALS_FULL_URI";
74
+ var ENV_CMDS_RELATIVE_URI = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI";
75
+ var ENV_CMDS_AUTH_TOKEN = "AWS_CONTAINER_AUTHORIZATION_TOKEN";
76
+ var fromContainerMetadata = (init = {}) => {
77
+ const { timeout, maxRetries } = providerConfigFromInit(init);
78
+ return () => retry(async () => {
79
+ const requestOptions = await getCmdsUri({ logger: init.logger });
80
+ const credsResponse = JSON.parse(await requestFromEcsImds(timeout, requestOptions));
81
+ if (!isImdsCredentials(credsResponse)) {
82
+ throw new CredentialsProviderError("Invalid response received from instance metadata service.", {
83
+ logger: init.logger
84
+ });
85
+ }
86
+ return fromImdsCredentials(credsResponse);
87
+ }, maxRetries);
88
+ };
89
+ var requestFromEcsImds = async (timeout, options) => {
90
+ if (process.env[ENV_CMDS_AUTH_TOKEN]) {
91
+ options.headers = {
92
+ ...options.headers,
93
+ Authorization: process.env[ENV_CMDS_AUTH_TOKEN]
94
+ };
95
+ }
96
+ const buffer = await httpRequest({
97
+ ...options,
98
+ timeout
99
+ });
100
+ return buffer.toString();
101
+ };
102
+ var CMDS_IP = "169.254.170.2";
103
+ var GREENGRASS_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1"]);
104
+ var GREENGRASS_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]);
105
+ var getCmdsUri = async ({ logger }) => {
106
+ if (process.env[ENV_CMDS_RELATIVE_URI]) {
107
+ return {
108
+ hostname: CMDS_IP,
109
+ path: process.env[ENV_CMDS_RELATIVE_URI]
110
+ };
111
+ }
112
+ if (process.env[ENV_CMDS_FULL_URI]) {
113
+ let parsed;
114
+ try {
115
+ parsed = new URL(process.env[ENV_CMDS_FULL_URI]);
116
+ } catch {
117
+ throw new CredentialsProviderError(`${process.env[ENV_CMDS_FULL_URI]} is not a valid container metadata service URL`, { tryNextLink: false, logger });
118
+ }
119
+ if (!parsed.hostname || !GREENGRASS_HOSTS.has(parsed.hostname)) {
120
+ throw new CredentialsProviderError(`${parsed.hostname} is not a valid container metadata service hostname`, {
121
+ tryNextLink: false,
122
+ logger
123
+ });
124
+ }
125
+ if (!parsed.protocol || !GREENGRASS_PROTOCOLS.has(parsed.protocol)) {
126
+ throw new CredentialsProviderError(`${parsed.protocol} is not a valid container metadata service protocol`, {
127
+ tryNextLink: false,
128
+ logger
129
+ });
130
+ }
131
+ return {
132
+ protocol: parsed.protocol,
133
+ hostname: parsed.hostname,
134
+ path: parsed.pathname + parsed.search,
135
+ port: parsed.port ? parseInt(parsed.port, 10) : void 0
136
+ };
137
+ }
138
+ throw new CredentialsProviderError(`The container metadata credential provider cannot be used unless the ${ENV_CMDS_RELATIVE_URI} or ${ENV_CMDS_FULL_URI} environment variable is set`, {
139
+ tryNextLink: false,
140
+ logger
141
+ });
142
+ };
143
+
144
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/error/InstanceMetadataV1FallbackError.js
145
+ var InstanceMetadataV1FallbackError = class _InstanceMetadataV1FallbackError extends CredentialsProviderError {
146
+ tryNextLink;
147
+ name = "InstanceMetadataV1FallbackError";
148
+ constructor(message, tryNextLink = true) {
149
+ super(message, tryNextLink);
150
+ this.tryNextLink = tryNextLink;
151
+ Object.setPrototypeOf(this, _InstanceMetadataV1FallbackError.prototype);
152
+ }
153
+ };
154
+
155
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/config/Endpoint.js
156
+ var Endpoint;
157
+ (function(Endpoint2) {
158
+ Endpoint2["IPv4"] = "http://169.254.169.254";
159
+ Endpoint2["IPv6"] = "http://[fd00:ec2::254]";
160
+ })(Endpoint || (Endpoint = {}));
161
+
162
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/config/EndpointConfigOptions.js
163
+ var ENV_ENDPOINT_NAME = "AWS_EC2_METADATA_SERVICE_ENDPOINT";
164
+ var CONFIG_ENDPOINT_NAME = "ec2_metadata_service_endpoint";
165
+ var ENDPOINT_CONFIG_OPTIONS = {
166
+ environmentVariableSelector: (env) => env[ENV_ENDPOINT_NAME],
167
+ configFileSelector: (profile) => profile[CONFIG_ENDPOINT_NAME],
168
+ default: void 0
169
+ };
170
+
171
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/config/EndpointMode.js
172
+ var EndpointMode;
173
+ (function(EndpointMode2) {
174
+ EndpointMode2["IPv4"] = "IPv4";
175
+ EndpointMode2["IPv6"] = "IPv6";
176
+ })(EndpointMode || (EndpointMode = {}));
177
+
178
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/config/EndpointModeConfigOptions.js
179
+ var ENV_ENDPOINT_MODE_NAME = "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE";
180
+ var CONFIG_ENDPOINT_MODE_NAME = "ec2_metadata_service_endpoint_mode";
181
+ var ENDPOINT_MODE_CONFIG_OPTIONS = {
182
+ environmentVariableSelector: (env) => env[ENV_ENDPOINT_MODE_NAME],
183
+ configFileSelector: (profile) => profile[CONFIG_ENDPOINT_MODE_NAME],
184
+ default: EndpointMode.IPv4
185
+ };
186
+
187
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/utils/getInstanceMetadataEndpoint.js
188
+ var getInstanceMetadataEndpoint = async () => parseUrl(await getFromEndpointConfig() || await getFromEndpointModeConfig());
189
+ var getFromEndpointConfig = async () => loadConfig(ENDPOINT_CONFIG_OPTIONS)();
190
+ var getFromEndpointModeConfig = async () => {
191
+ const endpointMode = await loadConfig(ENDPOINT_MODE_CONFIG_OPTIONS)();
192
+ switch (endpointMode) {
193
+ case EndpointMode.IPv4:
194
+ return Endpoint.IPv4;
195
+ case EndpointMode.IPv6:
196
+ return Endpoint.IPv6;
197
+ default:
198
+ throw new Error(`Unsupported endpoint mode: ${endpointMode}. Select from ${Object.values(EndpointMode)}`);
199
+ }
200
+ };
201
+
202
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/utils/getExtendedInstanceMetadataCredentials.js
203
+ var STATIC_STABILITY_REFRESH_INTERVAL_SECONDS = 5 * 60;
204
+ var STATIC_STABILITY_REFRESH_INTERVAL_JITTER_WINDOW_SECONDS = 5 * 60;
205
+ var STATIC_STABILITY_DOC_URL = "https://docs.aws.amazon.com/sdkref/latest/guide/feature-static-credentials.html";
206
+ var getExtendedInstanceMetadataCredentials = (credentials, logger) => {
207
+ const refreshInterval = STATIC_STABILITY_REFRESH_INTERVAL_SECONDS + Math.floor(Math.random() * STATIC_STABILITY_REFRESH_INTERVAL_JITTER_WINDOW_SECONDS);
208
+ const newExpiration = new Date(Date.now() + refreshInterval * 1e3);
209
+ 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)}.
210
+ For more information, please visit: ` + STATIC_STABILITY_DOC_URL);
211
+ const originalExpiration = credentials.originalExpiration ?? credentials.expiration;
212
+ return {
213
+ ...credentials,
214
+ ...originalExpiration ? { originalExpiration } : {},
215
+ expiration: newExpiration
216
+ };
217
+ };
218
+
219
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/utils/staticStabilityProvider.js
220
+ var staticStabilityProvider = (provider, options = {}) => {
221
+ const logger = options?.logger || console;
222
+ let pastCredentials;
223
+ return async () => {
224
+ let credentials;
225
+ try {
226
+ credentials = await provider();
227
+ if (credentials.expiration && credentials.expiration.getTime() < Date.now()) {
228
+ credentials = getExtendedInstanceMetadataCredentials(credentials, logger);
229
+ }
230
+ } catch (e) {
231
+ if (pastCredentials) {
232
+ logger.warn("Credential renew failed: ", e);
233
+ credentials = getExtendedInstanceMetadataCredentials(pastCredentials, logger);
234
+ } else {
235
+ throw e;
236
+ }
237
+ }
238
+ pastCredentials = credentials;
239
+ return credentials;
240
+ };
241
+ };
242
+
243
+ // ../../node_modules/@smithy/credential-provider-imds/dist-es/fromInstanceMetadata.js
244
+ var IMDS_PATH = "/latest/meta-data/iam/security-credentials/";
245
+ var IMDS_TOKEN_PATH = "/latest/api/token";
246
+ var AWS_EC2_METADATA_V1_DISABLED = "AWS_EC2_METADATA_V1_DISABLED";
247
+ var PROFILE_AWS_EC2_METADATA_V1_DISABLED = "ec2_metadata_v1_disabled";
248
+ var X_AWS_EC2_METADATA_TOKEN = "x-aws-ec2-metadata-token";
249
+ var fromInstanceMetadata = (init = {}) => staticStabilityProvider(getInstanceMetadataProvider(init), { logger: init.logger });
250
+ var getInstanceMetadataProvider = (init = {}) => {
251
+ let disableFetchToken = false;
252
+ const { logger, profile } = init;
253
+ const { timeout, maxRetries } = providerConfigFromInit(init);
254
+ const getCredentials = async (maxRetries2, options) => {
255
+ const isImdsV1Fallback = disableFetchToken || options.headers?.[X_AWS_EC2_METADATA_TOKEN] == null;
256
+ if (isImdsV1Fallback) {
257
+ let fallbackBlockedFromProfile = false;
258
+ let fallbackBlockedFromProcessEnv = false;
259
+ const configValue = await loadConfig({
260
+ environmentVariableSelector: (env) => {
261
+ const envValue = env[AWS_EC2_METADATA_V1_DISABLED];
262
+ fallbackBlockedFromProcessEnv = !!envValue && envValue !== "false";
263
+ if (envValue === void 0) {
264
+ throw new CredentialsProviderError(`${AWS_EC2_METADATA_V1_DISABLED} not set in env, checking config file next.`, { logger: init.logger });
265
+ }
266
+ return fallbackBlockedFromProcessEnv;
267
+ },
268
+ configFileSelector: (profile2) => {
269
+ const profileValue = profile2[PROFILE_AWS_EC2_METADATA_V1_DISABLED];
270
+ fallbackBlockedFromProfile = !!profileValue && profileValue !== "false";
271
+ return fallbackBlockedFromProfile;
272
+ },
273
+ default: false
274
+ }, {
275
+ profile
276
+ })();
277
+ if (init.ec2MetadataV1Disabled || configValue) {
278
+ const causes = [];
279
+ if (init.ec2MetadataV1Disabled)
280
+ causes.push("credential provider initialization (runtime option ec2MetadataV1Disabled)");
281
+ if (fallbackBlockedFromProfile)
282
+ causes.push(`config file profile (${PROFILE_AWS_EC2_METADATA_V1_DISABLED})`);
283
+ if (fallbackBlockedFromProcessEnv)
284
+ causes.push(`process environment variable (${AWS_EC2_METADATA_V1_DISABLED})`);
285
+ throw new InstanceMetadataV1FallbackError(`AWS EC2 Metadata v1 fallback has been blocked by AWS SDK configuration in the following: [${causes.join(", ")}].`);
286
+ }
287
+ }
288
+ const imdsProfile = (await retry(async () => {
289
+ let profile2;
290
+ try {
291
+ profile2 = await getProfile(options);
292
+ } catch (err) {
293
+ if (err.statusCode === 401) {
294
+ disableFetchToken = false;
295
+ }
296
+ throw err;
297
+ }
298
+ return profile2;
299
+ }, maxRetries2)).trim();
300
+ return retry(async () => {
301
+ let creds;
302
+ try {
303
+ creds = await getCredentialsFromProfile(imdsProfile, options, init);
304
+ } catch (err) {
305
+ if (err.statusCode === 401) {
306
+ disableFetchToken = false;
307
+ }
308
+ throw err;
309
+ }
310
+ return creds;
311
+ }, maxRetries2);
312
+ };
313
+ return async () => {
314
+ const endpoint = await getInstanceMetadataEndpoint();
315
+ if (disableFetchToken) {
316
+ logger?.debug("AWS SDK Instance Metadata", "using v1 fallback (no token fetch)");
317
+ return getCredentials(maxRetries, { ...endpoint, timeout });
318
+ } else {
319
+ let token;
320
+ try {
321
+ token = (await getMetadataToken({ ...endpoint, timeout })).toString();
322
+ } catch (error) {
323
+ if (error?.statusCode === 400) {
324
+ throw Object.assign(error, {
325
+ message: "EC2 Metadata token request returned error"
326
+ });
327
+ } else if (error.message === "TimeoutError" || [403, 404, 405].includes(error.statusCode)) {
328
+ disableFetchToken = true;
329
+ }
330
+ logger?.debug("AWS SDK Instance Metadata", "using v1 fallback (initial)");
331
+ return getCredentials(maxRetries, { ...endpoint, timeout });
332
+ }
333
+ return getCredentials(maxRetries, {
334
+ ...endpoint,
335
+ headers: {
336
+ [X_AWS_EC2_METADATA_TOKEN]: token
337
+ },
338
+ timeout
339
+ });
340
+ }
341
+ };
342
+ };
343
+ var getMetadataToken = async (options) => httpRequest({
344
+ ...options,
345
+ path: IMDS_TOKEN_PATH,
346
+ method: "PUT",
347
+ headers: {
348
+ "x-aws-ec2-metadata-token-ttl-seconds": "21600"
349
+ }
350
+ });
351
+ var getProfile = async (options) => (await httpRequest({ ...options, path: IMDS_PATH })).toString();
352
+ var getCredentialsFromProfile = async (profile, options, init) => {
353
+ const credentialsResponse = JSON.parse((await httpRequest({
354
+ ...options,
355
+ path: IMDS_PATH + profile
356
+ })).toString());
357
+ if (!isImdsCredentials(credentialsResponse)) {
358
+ throw new CredentialsProviderError("Invalid response received from instance metadata service.", {
359
+ logger: init.logger
360
+ });
361
+ }
362
+ return fromImdsCredentials(credentialsResponse);
363
+ };
364
+ export {
365
+ DEFAULT_MAX_RETRIES,
366
+ DEFAULT_TIMEOUT,
367
+ ENV_CMDS_AUTH_TOKEN,
368
+ ENV_CMDS_FULL_URI,
369
+ ENV_CMDS_RELATIVE_URI,
370
+ Endpoint,
371
+ fromContainerMetadata,
372
+ fromInstanceMetadata,
373
+ getInstanceMetadataEndpoint,
374
+ httpRequest,
375
+ providerConfigFromInit
376
+ };