@@ -19,9 +19,9 @@ export const ENV_CMDS_AUTH_TOKEN = "AWS_CONTAINER_AUTHORIZATION_TOKEN";
19
19
export const fromContainerMetadata = ( init : RemoteProviderInit = { } ) : CredentialProvider => {
20
20
const { timeout, maxRetries } = providerConfigFromInit ( init ) ;
21
21
return async ( ) => {
22
- const url = await getCmdsUri ( ) ;
22
+ const requestOptions = await getCmdsUri ( ) ;
23
23
return await retry ( async ( ) => {
24
- const credsResponse = JSON . parse ( await requestFromEcsImds ( timeout , url ) ) ;
24
+ const credsResponse = JSON . parse ( await requestFromEcsImds ( timeout , requestOptions ) ) ;
25
25
if ( ! isImdsCredentials ( credsResponse ) ) {
26
26
throw new ProviderError ( "Invalid response received from instance metadata service." ) ;
27
27
}
@@ -32,9 +32,10 @@ export const fromContainerMetadata = (init: RemoteProviderInit = {}): Credential
32
32
33
33
const requestFromEcsImds = async ( timeout : number , options : RequestOptions ) : Promise < string > => {
34
34
if ( process . env [ ENV_CMDS_AUTH_TOKEN ] ) {
35
- const { headers = { } } = options ;
36
- headers . Authorization = process . env [ ENV_CMDS_AUTH_TOKEN ] ;
37
- options . headers = headers ;
35
+ options . headers = {
36
+ ...options . headers ,
37
+ Authorization : process . env [ ENV_CMDS_AUTH_TOKEN ] ,
38
+ } ;
38
39
}
39
40
40
41
const buffer = await httpRequest ( {
@@ -54,40 +55,34 @@ const GREENGRASS_PROTOCOLS = {
54
55
"https:" : true ,
55
56
} ;
56
57
57
- const getCmdsUri = ( ) : Promise < RequestOptions > => {
58
+ const getCmdsUri = async ( ) : Promise < RequestOptions > => {
58
59
if ( process . env [ ENV_CMDS_RELATIVE_URI ] ) {
59
- return Promise . resolve ( {
60
+ return {
60
61
hostname : CMDS_IP ,
61
62
path : process . env [ ENV_CMDS_RELATIVE_URI ] ,
62
- } ) ;
63
+ } ;
63
64
}
64
65
65
66
if ( process . env [ ENV_CMDS_FULL_URI ] ) {
66
67
const parsed = parse ( process . env [ ENV_CMDS_FULL_URI ] ! ) ;
67
68
if ( ! parsed . hostname || ! ( parsed . hostname in GREENGRASS_HOSTS ) ) {
68
- return Promise . reject (
69
- new ProviderError ( `${ parsed . hostname } is not a valid container metadata service hostname` , false )
70
- ) ;
69
+ throw new ProviderError ( `${ parsed . hostname } is not a valid container metadata service hostname` , false ) ;
71
70
}
72
71
73
72
if ( ! parsed . protocol || ! ( parsed . protocol in GREENGRASS_PROTOCOLS ) ) {
74
- return Promise . reject (
75
- new ProviderError ( `${ parsed . protocol } is not a valid container metadata service protocol` , false )
76
- ) ;
73
+ throw new ProviderError ( `${ parsed . protocol } is not a valid container metadata service protocol` , false ) ;
77
74
}
78
75
79
- return Promise . resolve ( {
76
+ return {
80
77
...parsed ,
81
78
port : parsed . port ? parseInt ( parsed . port , 10 ) : undefined ,
82
- } ) ;
79
+ } ;
83
80
}
84
81
85
- return Promise . reject (
86
- new ProviderError (
87
- "The container metadata credential provider cannot be used unless" +
88
- ` the ${ ENV_CMDS_RELATIVE_URI } or ${ ENV_CMDS_FULL_URI } environment` +
89
- " variable is set" ,
90
- false
91
- )
82
+ throw new ProviderError (
83
+ "The container metadata credential provider cannot be used unless" +
84
+ ` the ${ ENV_CMDS_RELATIVE_URI } or ${ ENV_CMDS_FULL_URI } environment` +
85
+ " variable is set" ,
86
+ false
92
87
) ;
93
88
} ;
0 commit comments