Initial
This commit is contained in:
17
resources/app/node_modules/@smithy/credential-provider-imds/dist-es/utils/getExtendedInstanceMetadataCredentials.js
generated
vendored
Normal file
17
resources/app/node_modules/@smithy/credential-provider-imds/dist-es/utils/getExtendedInstanceMetadataCredentials.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
const STATIC_STABILITY_REFRESH_INTERVAL_SECONDS = 5 * 60;
|
||||
const STATIC_STABILITY_REFRESH_INTERVAL_JITTER_WINDOW_SECONDS = 5 * 60;
|
||||
const STATIC_STABILITY_DOC_URL = "https://docs.aws.amazon.com/sdkref/latest/guide/feature-static-credentials.html";
|
||||
export const getExtendedInstanceMetadataCredentials = (credentials, logger) => {
|
||||
const refreshInterval = STATIC_STABILITY_REFRESH_INTERVAL_SECONDS +
|
||||
Math.floor(Math.random() * STATIC_STABILITY_REFRESH_INTERVAL_JITTER_WINDOW_SECONDS);
|
||||
const newExpiration = new Date(Date.now() + refreshInterval * 1000);
|
||||
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: ` +
|
||||
STATIC_STABILITY_DOC_URL);
|
||||
const originalExpiration = credentials.originalExpiration ?? credentials.expiration;
|
||||
return {
|
||||
...credentials,
|
||||
...(originalExpiration ? { originalExpiration } : {}),
|
||||
expiration: newExpiration,
|
||||
};
|
||||
};
|
||||
19
resources/app/node_modules/@smithy/credential-provider-imds/dist-es/utils/getInstanceMetadataEndpoint.js
generated
vendored
Normal file
19
resources/app/node_modules/@smithy/credential-provider-imds/dist-es/utils/getInstanceMetadataEndpoint.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { loadConfig } from "@smithy/node-config-provider";
|
||||
import { parseUrl } from "@smithy/url-parser";
|
||||
import { Endpoint as InstanceMetadataEndpoint } from "../config/Endpoint";
|
||||
import { ENDPOINT_CONFIG_OPTIONS } from "../config/EndpointConfigOptions";
|
||||
import { EndpointMode } from "../config/EndpointMode";
|
||||
import { ENDPOINT_MODE_CONFIG_OPTIONS, } from "../config/EndpointModeConfigOptions";
|
||||
export const getInstanceMetadataEndpoint = async () => parseUrl((await getFromEndpointConfig()) || (await getFromEndpointModeConfig()));
|
||||
const getFromEndpointConfig = async () => loadConfig(ENDPOINT_CONFIG_OPTIONS)();
|
||||
const getFromEndpointModeConfig = async () => {
|
||||
const endpointMode = await loadConfig(ENDPOINT_MODE_CONFIG_OPTIONS)();
|
||||
switch (endpointMode) {
|
||||
case EndpointMode.IPv4:
|
||||
return InstanceMetadataEndpoint.IPv4;
|
||||
case EndpointMode.IPv6:
|
||||
return InstanceMetadataEndpoint.IPv6;
|
||||
default:
|
||||
throw new Error(`Unsupported endpoint mode: ${endpointMode}.` + ` Select from ${Object.values(EndpointMode)}`);
|
||||
}
|
||||
};
|
||||
25
resources/app/node_modules/@smithy/credential-provider-imds/dist-es/utils/staticStabilityProvider.js
generated
vendored
Normal file
25
resources/app/node_modules/@smithy/credential-provider-imds/dist-es/utils/staticStabilityProvider.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { getExtendedInstanceMetadataCredentials } from "./getExtendedInstanceMetadataCredentials";
|
||||
export const staticStabilityProvider = (provider, options = {}) => {
|
||||
const logger = options?.logger || console;
|
||||
let pastCredentials;
|
||||
return async () => {
|
||||
let credentials;
|
||||
try {
|
||||
credentials = await provider();
|
||||
if (credentials.expiration && credentials.expiration.getTime() < Date.now()) {
|
||||
credentials = getExtendedInstanceMetadataCredentials(credentials, logger);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
if (pastCredentials) {
|
||||
logger.warn("Credential renew failed: ", e);
|
||||
credentials = getExtendedInstanceMetadataCredentials(pastCredentials, logger);
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
pastCredentials = credentials;
|
||||
return credentials;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user