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