This repository has been archived on 2024-09-11. You can view files and clone it, but cannot push or open issues or pull requests.
svrjs-blog-newsletter/cronjob/node_modules/@aws-sdk/credential-provider-env/dist-es/fromEnv.js

25 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-05-26 22:54:55 +02:00
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 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];
if (accessKeyId && secretAccessKey) {
return {
accessKeyId,
secretAccessKey,
...(sessionToken && { sessionToken }),
...(expiry && { expiration: new Date(expiry) }),
...(credentialScope && { credentialScope }),
};
}
throw new CredentialsProviderError("Unable to find environment variable credentials.");
};