// @bun
import{lb as A,rb as E}from"./chunk-brb5zthb.js";import"./chunk-j2n86dsz.js";import{wb as K}from"./chunk-fxsv4p5c.js";import{xb as T}from"./chunk-p5va3trj.js";import{yb as w}from"./chunk-27ksm11g.js";var o=w(T(),1);import{exec as y}from"child_process";import{promisify as I}from"util";var S=w(K(),1),x=(c,n,e)=>{if(n.Version!==1)throw Error(`Profile ${c} credential_process did not return Version 1.`);if(n.AccessKeyId===void 0||n.SecretAccessKey===void 0)throw Error(`Profile ${c} credential_process returned invalid credentials.`);if(n.Expiration){let i=new Date;if(new Date(n.Expiration)<i)throw Error(`Profile ${c} credential_process returned expired credentials.`)}let s=n.AccountId;if(!s&&e?.[c]?.aws_account_id)s=e[c].aws_account_id;let t={accessKeyId:n.AccessKeyId,secretAccessKey:n.SecretAccessKey,...n.SessionToken&&{sessionToken:n.SessionToken},...n.Expiration&&{expiration:new Date(n.Expiration)},...n.CredentialScope&&{credentialScope:n.CredentialScope},...s&&{accountId:s}};return S.setCredentialFeature(t,"CREDENTIALS_PROCESS","w"),t};var _=async(c,n,e)=>{let s=n[c];if(n[c]){let t=s.credential_process;if(t!==void 0){let i=I(y);try{let{stdout:r}=await i(t),u;try{u=JSON.parse(r.trim())}catch{throw Error(`Profile ${c} credential_process returned invalid JSON.`)}return x(c,u,n)}catch(r){throw new o.CredentialsProviderError(r.message,{logger:e})}}else throw new o.CredentialsProviderError(`Profile ${c} did not contain credential_process.`,{logger:e})}else throw new o.CredentialsProviderError(`Profile ${c} could not be found in shared credentials file.`,{logger:e})};var R=(c={})=>async()=>{c.logger?.debug("@aws-sdk/credential-provider-process - fromProcess");let n=await E(c);return _(A(c),n,c.logger)};export{R as fromProcess};
