import{s as e}from"./DrKWWDpL.js";import{t}from"./DYP3EJMY.js";import{t as n}from"./CiotqGya.js";import{c as r,m as i,n as a,r as o}from"./BPr73Pj8.js";var s=e(t()),c=(e,t,r)=>{if(t.Version!==1)throw Error(`Profile ${e} credential_process did not return Version 1.`);if(t.AccessKeyId===void 0||t.SecretAccessKey===void 0)throw Error(`Profile ${e} credential_process returned invalid credentials.`);if(t.Expiration){let n=new Date;if(new Date(t.Expiration)<n)throw Error(`Profile ${e} credential_process returned expired credentials.`)}let i=t.AccountId;!i&&r?.[e]?.aws_account_id&&(i=r[e].aws_account_id);let a={accessKeyId:t.AccessKeyId,secretAccessKey:t.SecretAccessKey,...t.SessionToken&&{sessionToken:t.SessionToken},...t.Expiration&&{expiration:new Date(t.Expiration)},...t.CredentialScope&&{credentialScope:t.CredentialScope},...i&&{accountId:i}};return n(a,`CREDENTIALS_PROCESS`,`w`),a},l=async(e,t,n)=>{let r=t[e];if(t[e]){let o=r.credential_process;if(o!==void 0){let r=(0,s.promisify)(a?.getTokenRecord?.().exec??s.exec);try{let{stdout:n}=await r(o),i;try{i=JSON.parse(n.trim())}catch{throw Error(`Profile ${e} credential_process returned invalid JSON.`)}return c(e,i,t)}catch(e){throw new i(e.message,{logger:n})}}else throw new i(`Profile ${e} did not contain credential_process.`,{logger:n})}else throw new i(`Profile ${e} could not be found in shared credentials file.`,{logger:n})},u=(e={})=>async({callerClientConfig:t}={})=>{e.logger?.debug(`@aws-sdk/credential-provider-process - fromProcess`);let n=await r(e);return l(o({profile:e.profile??t?.profile}),n,e.logger)};export{u as fromProcess};