Skip to content

Commit 3739348

Browse files
committed
Drop compile target to es5, include tslib, and lower default retries to 0
1 parent 6fcb30c commit 3739348

File tree

8 files changed

+35
-30
lines changed

8 files changed

+35
-30
lines changed

packages/credential-provider-imds/__tests__/fromInstanceMetadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe("fromInstanceMetadata", () => {
102102
mockHttpGet.mockReturnValueOnce(Promise.resolve(profile));
103103
mockHttpGet.mockReturnValueOnce(Promise.resolve(JSON.stringify(creds)));
104104

105-
await fromInstanceMetadata()();
105+
await fromInstanceMetadata({ maxRetries: 1 })();
106106
expect(mockHttpGet.mock.calls.length).toEqual(3);
107107
expect(mockHttpGet.mock.calls[2][0]).toEqual({
108108
host: "169.254.169.254",

packages/credential-provider-imds/__tests__/remoteProvider/ImdsCredentials.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,21 @@ describe("isImdsCredentials", () => {
1818
});
1919

2020
it("should reject credentials without an AccessKeyId", () => {
21-
expect(
22-
isImdsCredentials(Object.assign({}, creds, { AccessKeyId: void 0 }))
23-
).toBe(false);
21+
expect(isImdsCredentials({ ...creds, AccessKeyId: void 0 })).toBe(false);
2422
});
2523

2624
it("should reject credentials without a SecretAccessKey", () => {
27-
expect(
28-
isImdsCredentials(Object.assign({}, creds, { SecretAccessKey: void 0 }))
29-
).toBe(false);
25+
expect(isImdsCredentials({ ...creds, SecretAccessKey: void 0 })).toBe(
26+
false
27+
);
3028
});
3129

3230
it("should reject credentials without a Token", () => {
33-
expect(isImdsCredentials(Object.assign({}, creds, { Token: void 0 }))).toBe(
34-
false
35-
);
31+
expect(isImdsCredentials({ ...creds, Token: void 0 })).toBe(false);
3632
});
3733

3834
it("should reject credentials without an Expiration", () => {
39-
expect(
40-
isImdsCredentials(Object.assign({}, creds, { Expiration: void 0 }))
41-
).toBe(false);
35+
expect(isImdsCredentials({ ...creds, Expiration: void 0 })).toBe(false);
4236
});
4337

4438
it("should reject scalar values", () => {

packages/credential-provider-imds/__tests__/remoteProvider/httpGet.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { createServer } from "http";
22
import { httpGet } from "../../lib/remoteProvider/httpGet";
33
import { CredentialError } from "@aws/credential-provider-base";
44

5-
const matchers = new Map<string, string>();
5+
let matchers: { [url: string]: string } = {};
66

77
function addMatcher(url: string, toReturn: string): void {
8-
matchers.set(url, toReturn);
8+
matchers[url] = toReturn;
99
}
1010

1111
function clearMatchers(): void {
12-
matchers.clear();
12+
matchers = {};
1313
}
1414

1515
function getOpenPort(candidatePort: number = 4321): Promise<number> {
@@ -25,9 +25,9 @@ let port: number;
2525

2626
const server = createServer((request, response) => {
2727
const { url = "" } = request;
28-
if (matchers.has(url)) {
28+
if (url in matchers) {
2929
response.statusCode = 200;
30-
response.end(matchers.get(url));
30+
response.end(matchers[url]);
3131
} else {
3232
response.statusCode = 404;
3333
response.end("Not found");

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ function requestFromEcsImds(
6060
}
6161

6262
const CMDS_IP = "169.254.170.2";
63-
const GREENGRASS_HOSTS = new Set(["localhost", "127.0.0.1"]);
64-
const GREENGRASS_PROTOCOLS = new Set(["http:", "https:"]);
63+
const GREENGRASS_HOSTS = {
64+
localhost: true,
65+
"127.0.0.1": true
66+
};
67+
const GREENGRASS_PROTOCOLS = {
68+
"http:": true,
69+
"https:": true
70+
};
6571

6672
function getCmdsUri(): Promise<RequestOptions> {
6773
if (process.env[ENV_CMDS_RELATIVE_URI]) {
@@ -73,7 +79,7 @@ function getCmdsUri(): Promise<RequestOptions> {
7379

7480
if (process.env[ENV_CMDS_FULL_URI]) {
7581
const parsed = parse(process.env[ENV_CMDS_FULL_URI]);
76-
if (!parsed.hostname || !GREENGRASS_HOSTS.has(parsed.hostname)) {
82+
if (!parsed.hostname || !(parsed.hostname in GREENGRASS_HOSTS)) {
7783
return Promise.reject(
7884
new CredentialError(
7985
`${
@@ -84,7 +90,7 @@ function getCmdsUri(): Promise<RequestOptions> {
8490
);
8591
}
8692

87-
if (!parsed.protocol || !GREENGRASS_PROTOCOLS.has(parsed.protocol)) {
93+
if (!parsed.protocol || !(parsed.protocol in GREENGRASS_PROTOCOLS)) {
8894
return Promise.reject(
8995
new CredentialError(
9096
`${
@@ -97,7 +103,7 @@ function getCmdsUri(): Promise<RequestOptions> {
97103

98104
return Promise.resolve({
99105
...parsed,
100-
port: parsed.port ? Number.parseInt(parsed.port, 10) : undefined
106+
port: parsed.port ? parseInt(parsed.port, 10) : undefined
101107
});
102108
}
103109

packages/credential-provider-imds/lib/remoteProvider/RemoteProviderInit.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export const DEFAULT_TIMEOUT = 1000;
2-
// TODO I think this should be 0 (in line with other SDKs) and not 3 (in line with JS v2)
3-
export const DEFAULT_MAX_RETRIES = 3;
2+
export const DEFAULT_MAX_RETRIES = 0;
43

54
export interface RemoteProviderConfig {
65
/**

packages/credential-provider-imds/lib/remoteProvider/httpGet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export function httpGet(options: RequestOptions): Promise<Buffer> {
2525
}
2626

2727
const chunks: Array<Buffer> = [];
28-
res.on("readable", () => {
29-
chunks.push(res.read());
28+
res.on("data", chunk => {
29+
chunks.push(chunk as Buffer);
3030
});
3131
res.on("end", () => {
3232
resolve(Buffer.concat(chunks));

packages/credential-provider-imds/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"license": "UNLICENSED",
1818
"dependencies": {
1919
"@aws/credential-provider-base": "^0.0.1",
20-
"@aws/types": "^0.0.1"
20+
"@aws/types": "^0.0.1",
21+
"tslib": "^1.7.1"
2122
},
2223
"devDependencies": {
2324
"@types/jest": "^19.2.2",
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
22
"compilerOptions": {
33
"module": "commonjs",
4-
"target": "es6",
4+
"target": "es5",
55
"declaration": true,
66
"strict": true,
7-
"sourceMap": true
7+
"sourceMap": true,
8+
"importHelpers": true,
9+
"lib": [
10+
"es5",
11+
"es2015.promise"
12+
]
813
}
914
}

0 commit comments

Comments
 (0)