Skip to content

Commit 13b6225

Browse files
committed
chore: arrow+async functions
1 parent 105c9b7 commit 13b6225

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

packages/credential-provider-imds/src/fromContainerMetadata.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,33 @@ export const ENV_CMDS_AUTH_TOKEN = "AWS_CONTAINER_AUTHORIZATION_TOKEN";
1616
* Creates a credential provider that will source credentials from the ECS
1717
* Container Metadata Service
1818
*/
19-
export function fromContainerMetadata(init: RemoteProviderInit = {}): CredentialProvider {
19+
export const fromContainerMetadata = (init: RemoteProviderInit = {}): CredentialProvider => {
2020
const { timeout, maxRetries } = providerConfigFromInit(init);
21-
return () => {
22-
return getCmdsUri().then((url) =>
23-
retry(async () => {
24-
const credsResponse = JSON.parse(await requestFromEcsImds(timeout, url));
25-
if (!isImdsCredentials(credsResponse)) {
26-
throw new ProviderError("Invalid response received from instance metadata service.");
27-
}
28-
29-
return fromImdsCredentials(credsResponse);
30-
}, maxRetries)
31-
);
21+
return async () => {
22+
const url = await getCmdsUri();
23+
return await retry(async () => {
24+
const credsResponse = JSON.parse(await requestFromEcsImds(timeout, url));
25+
if (!isImdsCredentials(credsResponse)) {
26+
throw new ProviderError("Invalid response received from instance metadata service.");
27+
}
28+
return fromImdsCredentials(credsResponse);
29+
}, maxRetries);
3230
};
33-
}
31+
};
3432

35-
function requestFromEcsImds(timeout: number, options: RequestOptions): Promise<string> {
33+
const requestFromEcsImds = async (timeout: number, options: RequestOptions): Promise<string> => {
3634
if (process.env[ENV_CMDS_AUTH_TOKEN]) {
3735
const { headers = {} } = options;
3836
headers.Authorization = process.env[ENV_CMDS_AUTH_TOKEN];
3937
options.headers = headers;
4038
}
4139

42-
return httpRequest({
40+
const buffer = await httpRequest({
4341
...options,
4442
timeout,
45-
}).then((buffer) => buffer.toString());
46-
}
43+
});
44+
return buffer.toString();
45+
};
4746

4847
const CMDS_IP = "169.254.170.2";
4948
const GREENGRASS_HOSTS = {
@@ -55,7 +54,7 @@ const GREENGRASS_PROTOCOLS = {
5554
"https:": true,
5655
};
5756

58-
function getCmdsUri(): Promise<RequestOptions> {
57+
const getCmdsUri = (): Promise<RequestOptions> => {
5958
if (process.env[ENV_CMDS_RELATIVE_URI]) {
6059
return Promise.resolve({
6160
hostname: CMDS_IP,
@@ -91,4 +90,4 @@ function getCmdsUri(): Promise<RequestOptions> {
9190
false
9291
)
9392
);
94-
}
93+
};

0 commit comments

Comments
 (0)