import{m as e}from"./BPr73Pj8.js";import{b as t,i as n}from"./CzgNarYu.js";import{t as r}from"./COfTZUNn.js";import{t as i}from"./D2jkj_HI.js";var a=`169.254.170.2`,o=`169.254.170.23`,s=`[fd00:ec2::23]`,c=(t,n)=>{if(t.protocol!==`https:`&&!(t.hostname===a||t.hostname===o||t.hostname===s)){if(t.hostname.includes(`[`)){if(t.hostname===`[::1]`||t.hostname===`[0000:0000:0000:0000:0000:0000:0000:0001]`)return}else{if(t.hostname===`localhost`)return;let e=t.hostname.split(`.`),n=e=>{let t=parseInt(e,10);return 0<=t&&t<=255};if(e[0]===`127`&&n(e[1])&&n(e[2])&&n(e[3])&&e.length===4)return}throw new e(`URL not accepted. It must either be HTTPS or match one of the following:
  - loopback CIDR 127.0.0.0/8 or [::1/128]
  - ECS container host 169.254.170.2
  - EKS container host 169.254.170.23 or [fd00:ec2::23]`,{logger:n})}};function l(e){return new r({protocol:e.protocol,hostname:e.hostname,port:Number(e.port),path:e.pathname,query:Array.from(e.searchParams.entries()).reduce((e,[t,n])=>(e[t]=n,e),{}),fragment:e.hash})}async function u(r,i){let a=await n(r.body).transformToString();if(r.statusCode===200){let n=JSON.parse(a);if(typeof n.AccessKeyId!=`string`||typeof n.SecretAccessKey!=`string`||typeof n.Token!=`string`||typeof n.Expiration!=`string`)throw new e(`HTTP credential provider response not of the required format, an object matching: { AccessKeyId: string, SecretAccessKey: string, Token: string, Expiration: string(rfc3339) }`,{logger:i});return{accessKeyId:n.AccessKeyId,secretAccessKey:n.SecretAccessKey,sessionToken:n.Token,expiration:t(n.Expiration)}}if(r.statusCode>=400&&r.statusCode<500){let t={};try{t=JSON.parse(a)}catch{}throw Object.assign(new e(`Server responded with status: ${r.statusCode}`,{logger:i}),{Code:t.Code,Message:t.Message})}throw new e(`Server responded with status: ${r.statusCode}`,{logger:i})}var d=(e,t,n)=>async()=>{for(let r=0;r<t;++r)try{return await e()}catch{await new Promise(e=>setTimeout(e,n))}return await e()},f=(t={})=>{t.logger?.debug(`@aws-sdk/credential-provider-http - fromHttp`);let n,r=t.credentialsFullUri;if(r)n=r;else throw new e(`No HTTP credential provider host provided.`,{logger:t.logger});let a=new URL(n);c(a,t.logger);let o=new i;return d(async()=>{let e=l(a);return t.authorizationToken&&(e.headers.Authorization=t.authorizationToken),u((await o.handle(e)).response)},t.maxRetries??3,t.timeout??1e3)};export{f as fromHttp};