UNPKG

@artilleryio/platform-fargate

Version:
1 lines 1.4 kB
const getCredentialsWithSSO=require("./aws-get-credentials"),AWS=require("aws-sdk"),debug=require("debug")("aws:credentials"),whoami=require("./aws-whoami");async function updateSSOCredentials(aws){try{var[ssoAvailable,credentials]=await getCredentialsWithSSO();if(!ssoAvailable||!credentials)throw new Error("Unable to refresh AWS credentials from SSO");debug("AWS credentials refreshed. Expiration:",credentials.expiration),aws.config.update({credentials:credentials})}catch(err){console.error(err)}}module.exports=async function(SDK){if(debug("Setting AWS credentials"),null===AWS.config.credentials||"object"!=typeof AWS.config.credentials){debug(AWS.config.credentials);const aws=SDK||AWS;process.env.DEBUG_AWS_SDK_CALLS&&(aws.config.logger=artillery);var[SDK,credentials]=await getCredentialsWithSSO();if(SDK){if(null===credentials)throw new Error("The SSO session associated with this profile has expired or is otherwise invalid. To refresh this SSO session run aws sso login with the corresponding profile.");await updateSSOCredentials(aws),setInterval(async()=>{await updateSSOCredentials(aws)},6e5).unref()}else debug("AWS SSO not in use, will use credentials acquired automatically by AWS SDK");SDK=await whoami();return debug(SDK),debug("AWS credentials expiration: "+AWS.config.credentials?.expiration),!0}debug("AWS credentials already set"),debug(Object.keys(AWS.config.credentials))};