Skip to content

Commit 807c292

Browse files
committed
Drop compile target to es5, include tslib, and lower default retries to 0
1 parent d2b251e commit 807c292

File tree

8 files changed

+34
-36
lines changed

8 files changed

+34
-36
lines changed

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

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

107-
await fromInstanceMetadata()();
107+
await fromInstanceMetadata({maxRetries: 1})();
108108
expect(mockHttpGet.mock.calls.length).toEqual(3);
109109
expect(mockHttpGet.mock.calls[2][0]).toEqual({
110110
host: '169.254.169.254',

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,20 @@ 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}))
26+
.toBe(false);
3027
});
3128

3229
it('should reject credentials without a Token', () => {
33-
expect(
34-
isImdsCredentials(Object.assign({}, creds, {Token: void 0}))
35-
).toBe(false);
30+
expect(isImdsCredentials({...creds, Token: void 0})).toBe(false);
3631
});
3732

3833
it('should reject credentials without an Expiration', () => {
39-
expect(
40-
isImdsCredentials(Object.assign({}, creds, {Expiration: void 0}))
41-
).toBe(false);
34+
expect(isImdsCredentials({...creds, Expiration: void 0})).toBe(false);
4235
});
4336

4437
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> {
@@ -26,9 +26,9 @@ let port: number;
2626

2727
const server = createServer((request, response) => {
2828
const {url = ''} = request;
29-
if (matchers.has(url)) {
29+
if (url in matchers) {
3030
response.statusCode = 200;
31-
response.end(matchers.get(url));
31+
response.end(matchers[url]);
3232
} else {
3333
response.statusCode = 404;
3434
response.end('Not found');

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ function requestFromEcsImds(
5959
}
6060

6161
const CMDS_IP = '169.254.170.2';
62-
const GREENGRASS_HOSTS = new Set([
63-
'localhost',
64-
'127.0.0.1',
65-
]);
66-
const GREENGRASS_PROTOCOLS = new Set([
67-
'http:',
68-
'https:',
69-
]);
62+
const GREENGRASS_HOSTS = {
63+
'localhost': true,
64+
'127.0.0.1': true,
65+
};
66+
const GREENGRASS_PROTOCOLS = {
67+
'http:': true,
68+
'https:': true,
69+
};
7070

7171
function getCmdsUri(): Promise<RequestOptions> {
7272
if (process.env[ENV_CMDS_RELATIVE_URI]) {
@@ -78,14 +78,14 @@ function getCmdsUri(): Promise<RequestOptions> {
7878

7979
if (process.env[ENV_CMDS_FULL_URI]) {
8080
const parsed = parse(process.env[ENV_CMDS_FULL_URI]);
81-
if (!parsed.hostname || !GREENGRASS_HOSTS.has(parsed.hostname)) {
81+
if (!parsed.hostname || !(parsed.hostname in GREENGRASS_HOSTS)) {
8282
return Promise.reject(new CredentialError(
8383
`${parsed.hostname} is not a valid container metadata service hostname`,
8484
false
8585
));
8686
}
8787

88-
if (!parsed.protocol || !GREENGRASS_PROTOCOLS.has(parsed.protocol)) {
88+
if (!parsed.protocol || !(parsed.protocol in GREENGRASS_PROTOCOLS)) {
8989
return Promise.reject(new CredentialError(
9090
`${parsed.protocol} is not a valid container metadata service protocol`,
9191
false
@@ -94,7 +94,7 @@ function getCmdsUri(): Promise<RequestOptions> {
9494

9595
return Promise.resolve({
9696
...parsed,
97-
port: parsed.port ? Number.parseInt(parsed.port, 10) : undefined
97+
port: parsed.port ? parseInt(parsed.port, 10) : undefined
9898
});
9999
}
100100

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
@@ -23,8 +23,8 @@ export function httpGet(options: RequestOptions): Promise<Buffer> {
2323
}
2424

2525
const chunks: Array<Buffer> = [];
26-
res.on('readable', () => {
27-
chunks.push(res.read());
26+
res.on('data', chunk => {
27+
chunks.push(chunk as Buffer);
2828
});
2929
res.on('end', () => {
3030
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)