Skip to content

Commit 6fb34c8

Browse files
committed
Add support for the AWS_CREDENTIAL_EXPIRATION environment variable
1 parent 94219cb commit 6fb34c8

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

packages/credential-provider-env/__tests__/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,51 @@ import {
33
ENV_KEY,
44
ENV_SECRET,
55
ENV_SESSION,
6+
ENV_EXPIRATION,
67
fromEnv,
78
} from "../";
89

910
const akid = process.env[ENV_KEY];
1011
const secret = process.env[ENV_SECRET];
1112
const token = process.env[ENV_SESSION];
13+
const expiry = process.env[ENV_EXPIRATION];
1214

1315
beforeEach(() => {
1416
delete process.env[ENV_KEY];
1517
delete process.env[ENV_SECRET];
1618
delete process.env[ENV_SESSION];
19+
delete process.env[ENV_EXPIRATION];
1720
});
1821

1922
afterAll(() => {
2023
process.env[ENV_KEY] = akid;
2124
process.env[ENV_SECRET] = secret;
2225
process.env[ENV_SESSION] = token;
26+
process.env[ENV_EXPIRATION] = expiry;
2327
});
2428

2529
describe('fromEnv', () => {
2630
it('should read credentials from known environment variables', async () => {
2731
process.env[ENV_KEY] = 'foo';
2832
process.env[ENV_SECRET] = 'bar';
2933
process.env[ENV_SESSION] = 'baz';
34+
process.env[ENV_EXPIRATION] = '1970-01-01T07:00:00Z';
3035

3136
expect(await fromEnv()()).toEqual({
3237
accessKeyId: 'foo',
3338
secretAccessKey: 'bar',
3439
sessionToken: 'baz',
40+
expiration: 25200,
3541
});
3642
});
3743

38-
it('can create credentials without a session token', async () => {
44+
it('can create credentials without a session token or expiration', async () => {
3945
process.env[ENV_KEY] = 'foo';
4046
process.env[ENV_SECRET] = 'bar';
4147

4248
expect(await fromEnv()()).toEqual({
4349
accessKeyId: 'foo',
4450
secretAccessKey: 'bar',
45-
sessionToken: void 0,
4651
});
4752
});
4853

packages/credential-provider-env/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import {CredentialProvider} from "@aws/types";
2-
import {CredentialError} from "@aws/credential-provider-base";
1+
import {CredentialProvider} from '@aws/types';
2+
import {CredentialError} from '@aws/credential-provider-base';
3+
import {epoch} from '@aws/protocol-timestamp';
34

45
export const ENV_KEY = 'AWS_ACCESS_KEY_ID';
56
export const ENV_SECRET = 'AWS_SECRET_ACCESS_KEY';
67
export const ENV_SESSION = 'AWS_SESSION_TOKEN';
8+
export const ENV_EXPIRATION = 'AWS_CREDENTIAL_EXPIRATION';
79

810
/**
911
* Source AWS credentials from known environment variables. If either the
@@ -14,11 +16,13 @@ export function fromEnv(): CredentialProvider {
1416
return () => {
1517
const accessKeyId: string = process.env[ENV_KEY];
1618
const secretAccessKey: string = process.env[ENV_SECRET];
19+
const expiry: string|undefined = process.env[ENV_EXPIRATION];
1720
if (accessKeyId && secretAccessKey) {
1821
return Promise.resolve({
1922
accessKeyId,
2023
secretAccessKey,
2124
sessionToken: process.env[ENV_SESSION],
25+
expiration: expiry ? epoch(expiry) : undefined
2226
});
2327
}
2428

packages/credential-provider-env/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"license": "UNLICENSED",
1818
"dependencies": {
1919
"@aws/credential-provider-base": "^0.0.1",
20+
"@aws/protocol-timestamp": "^0.0.1",
2021
"@aws/types": "^0.0.1"
2122
},
2223
"devDependencies": {

0 commit comments

Comments
 (0)