初始化环境文件
This commit is contained in:
30
node_modules/@aws-sdk/credential-provider-env/dist-es/fromEnv.js
generated
vendored
Normal file
30
node_modules/@aws-sdk/credential-provider-env/dist-es/fromEnv.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { setCredentialFeature } from "@aws-sdk/core/client";
|
||||
import { CredentialsProviderError } from "@smithy/property-provider";
|
||||
export const ENV_KEY = "AWS_ACCESS_KEY_ID";
|
||||
export const ENV_SECRET = "AWS_SECRET_ACCESS_KEY";
|
||||
export const ENV_SESSION = "AWS_SESSION_TOKEN";
|
||||
export const ENV_EXPIRATION = "AWS_CREDENTIAL_EXPIRATION";
|
||||
export const ENV_CREDENTIAL_SCOPE = "AWS_CREDENTIAL_SCOPE";
|
||||
export const ENV_ACCOUNT_ID = "AWS_ACCOUNT_ID";
|
||||
export const fromEnv = (init) => async () => {
|
||||
init?.logger?.debug("@aws-sdk/credential-provider-env - fromEnv");
|
||||
const accessKeyId = process.env[ENV_KEY];
|
||||
const secretAccessKey = process.env[ENV_SECRET];
|
||||
const sessionToken = process.env[ENV_SESSION];
|
||||
const expiry = process.env[ENV_EXPIRATION];
|
||||
const credentialScope = process.env[ENV_CREDENTIAL_SCOPE];
|
||||
const accountId = process.env[ENV_ACCOUNT_ID];
|
||||
if (accessKeyId && secretAccessKey) {
|
||||
const credentials = {
|
||||
accessKeyId,
|
||||
secretAccessKey,
|
||||
...(sessionToken && { sessionToken }),
|
||||
...(expiry && { expiration: new Date(expiry) }),
|
||||
...(credentialScope && { credentialScope }),
|
||||
...(accountId && { accountId }),
|
||||
};
|
||||
setCredentialFeature(credentials, "CREDENTIALS_ENV_VARS", "g");
|
||||
return credentials;
|
||||
}
|
||||
throw new CredentialsProviderError("Unable to find environment variable credentials.", { logger: init?.logger });
|
||||
};
|
||||
Reference in New Issue
Block a user