初始化环境文件
This commit is contained in:
30
node_modules/@aws-sdk/credential-provider-process/dist-es/getValidatedProcessCredentials.js
generated
vendored
Normal file
30
node_modules/@aws-sdk/credential-provider-process/dist-es/getValidatedProcessCredentials.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { setCredentialFeature } from "@aws-sdk/core/client";
|
||||
export const getValidatedProcessCredentials = (profileName, data, profiles) => {
|
||||
if (data.Version !== 1) {
|
||||
throw Error(`Profile ${profileName} credential_process did not return Version 1.`);
|
||||
}
|
||||
if (data.AccessKeyId === undefined || data.SecretAccessKey === undefined) {
|
||||
throw Error(`Profile ${profileName} credential_process returned invalid credentials.`);
|
||||
}
|
||||
if (data.Expiration) {
|
||||
const currentTime = new Date();
|
||||
const expireTime = new Date(data.Expiration);
|
||||
if (expireTime < currentTime) {
|
||||
throw Error(`Profile ${profileName} credential_process returned expired credentials.`);
|
||||
}
|
||||
}
|
||||
let accountId = data.AccountId;
|
||||
if (!accountId && profiles?.[profileName]?.aws_account_id) {
|
||||
accountId = profiles[profileName].aws_account_id;
|
||||
}
|
||||
const credentials = {
|
||||
accessKeyId: data.AccessKeyId,
|
||||
secretAccessKey: data.SecretAccessKey,
|
||||
...(data.SessionToken && { sessionToken: data.SessionToken }),
|
||||
...(data.Expiration && { expiration: new Date(data.Expiration) }),
|
||||
...(data.CredentialScope && { credentialScope: data.CredentialScope }),
|
||||
...(accountId && { accountId }),
|
||||
};
|
||||
setCredentialFeature(credentials, "CREDENTIALS_PROCESS", "w");
|
||||
return credentials;
|
||||
};
|
||||
Reference in New Issue
Block a user