@govuk-pay/cli 0.0.109 → 0.0.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -24,6 +24,9 @@ exports.DEPLOY_CONFIG = {
|
|
|
24
24
|
'end-to-end/docker-username': 'dockerhub/concourse-username',
|
|
25
25
|
'end-to-end/docker-access-token': 'dockerhub/concourse-access-token',
|
|
26
26
|
'github-access-token': 'alphagov-pay-ci-concourse/github.com-concourse-github-personal-access-token',
|
|
27
|
+
'github-app-id': 'pay-org-management/github-app-id',
|
|
28
|
+
'github-app-installation-id': 'pay-org-management/github-app-installation-id',
|
|
29
|
+
'github-app-pem': 'pay-org-management/github-app-pem',
|
|
27
30
|
'grafana-annotations-password': 'concourse/grafana_annotations', // pragma: allowlist secret
|
|
28
31
|
'pact-broker-password': 'pact/pact_broker_password', // pragma: allowlist secret
|
|
29
32
|
'pact-broker-username': 'pact/pact_broker_username',
|
package/src/util/configs.js
CHANGED
|
@@ -50,8 +50,7 @@ exports.workspaceEnvVar = workspaceEnvVar;
|
|
|
50
50
|
const AWS_ENV_VARS_TO_CHECK = [
|
|
51
51
|
'AWS_ACCESS_KEY_ID',
|
|
52
52
|
'AWS_SECRET_ACCESS_KEY',
|
|
53
|
-
'AWS_SESSION_TOKEN'
|
|
54
|
-
'AWS_CREDENTIAL_EXPIRATION'
|
|
53
|
+
'AWS_SESSION_TOKEN'
|
|
55
54
|
];
|
|
56
55
|
/**
|
|
57
56
|
* This function checks if there are AWS credentials in the environment, that they are for a named account, and their expiry status.
|
|
@@ -70,15 +69,21 @@ async function checkAwsCredentials(accountName) {
|
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
71
|
const expirationTime = process.env.AWS_CREDENTIAL_EXPIRATION;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
console.error(`There are AWS credentials in the env, but they have expired. They expired at ${expirationTime}`);
|
|
77
|
-
process.exit(1);
|
|
72
|
+
// If AWS_SESSION_TOKEN is set, but AWS_CREDENTIAL_EXPIRATION is not, treat the token expiration is effectively infinite
|
|
73
|
+
if (expirationTime === undefined || expirationTime === null || expirationTime?.trim() === '') {
|
|
74
|
+
console.warn('WARNING: The AWS credentials in the env have no expiration');
|
|
78
75
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
else {
|
|
77
|
+
const expirationTimestamp = Date.parse(expirationTime);
|
|
78
|
+
const now = Date.now();
|
|
79
|
+
if (now >= expirationTimestamp) {
|
|
80
|
+
console.error(`There are AWS credentials in the env, but they have expired. They expired at ${expirationTime}`);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
// 15 minutes * 60 seconds in a minute * 1000 ms in a second
|
|
84
|
+
if (now >= (expirationTimestamp - (15 * 60 * 1000))) {
|
|
85
|
+
console.warn(`WARNING: The AWS credentials will expire at ${expirationTime} which is within 15 minutes\n`);
|
|
86
|
+
}
|
|
82
87
|
}
|
|
83
88
|
await checkAwsCredentialsAreForAccount(accountName);
|
|
84
89
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const globals_1 = require("@jest/globals");
|
|
4
|
+
const configs_1 = require("./configs");
|
|
5
|
+
(0, globals_1.describe)('config methods', () => {
|
|
6
|
+
const baseEnv = process.env;
|
|
7
|
+
const missingExpirationToken = 'WARNING: The AWS credentials in the env have no expiration';
|
|
8
|
+
const correctEnvVars = {
|
|
9
|
+
AWS_ACCESS_KEY_ID: 'test',
|
|
10
|
+
AWS_SECRET_ACCESS_KEY: 'test',
|
|
11
|
+
AWS_SESSION_TOKEN: 'test'
|
|
12
|
+
};
|
|
13
|
+
let errorSpy;
|
|
14
|
+
let warnSpy;
|
|
15
|
+
(0, globals_1.beforeEach)(() => {
|
|
16
|
+
errorSpy = globals_1.jest.spyOn(console, 'error').mockImplementation(() => { });
|
|
17
|
+
warnSpy = globals_1.jest.spyOn(console, 'warn').mockImplementation(() => { });
|
|
18
|
+
globals_1.jest.spyOn(process, 'exit').mockImplementation((code) => {
|
|
19
|
+
throw new Error(`process.exit: ${String(code)}`);
|
|
20
|
+
});
|
|
21
|
+
globals_1.jest.spyOn(Date, 'now').mockReturnValue(new Date('2025-01-01T12:00:00Z').getTime());
|
|
22
|
+
process.env = { ...baseEnv };
|
|
23
|
+
});
|
|
24
|
+
(0, globals_1.afterEach)(() => {
|
|
25
|
+
process.env = baseEnv;
|
|
26
|
+
globals_1.jest.resetAllMocks();
|
|
27
|
+
});
|
|
28
|
+
globals_1.test.each([
|
|
29
|
+
['AWS_ACCESS_KEY_ID', '\'\'', { AWS_ACCESS_KEY_ID: '' }],
|
|
30
|
+
['AWS_SECRET_ACCESS_KEY', 'null', { AWS_ACCESS_KEY_ID: 'test', AWS_SECRET_ACCESS_KEY: null }],
|
|
31
|
+
['AWS_SESSION_TOKEN', 'undefined', { AWS_ACCESS_KEY_ID: 'test', AWS_SECRET_ACCESS_KEY: 'test', AWS_SESSION_TOKEN: undefined }]
|
|
32
|
+
])('checkAwsCredentials exits if %s is %s', async (expectedVar, envValue, envVars) => {
|
|
33
|
+
process.env = { ...process.env, ...envVars };
|
|
34
|
+
const noCredError = `It looks like you do not have any AWS credentials in the environment (missing ${expectedVar}).`;
|
|
35
|
+
try {
|
|
36
|
+
await (0, configs_1.checkAwsCredentials)('test');
|
|
37
|
+
// throw an error so that if the logic is altered and process.exit isnt hit we can force the test to fail
|
|
38
|
+
throw new Error('Force the test to hit the catch');
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
(0, globals_1.expect)(process.exit).toBeCalledWith(1);
|
|
42
|
+
(0, globals_1.expect)(errorSpy).toHaveBeenCalledTimes(2);
|
|
43
|
+
(0, globals_1.expect)(errorSpy.mock.calls[0]).toEqual([noCredError]);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
globals_1.test.each([
|
|
47
|
+
['\'\'', { AWS_CREDENTIAL_EXPIRATION: '' }],
|
|
48
|
+
['null', { AWS_CREDENTIAL_EXPIRATION: null }],
|
|
49
|
+
['undefined', { AWS_CREDENTIAL_EXPIRATION: undefined }]
|
|
50
|
+
])('checkAwsCredentials skips checks on AWS_CREDENTIAL_EXPIRATION when its value is %s', async (awsCredentialExpiration, credToken) => {
|
|
51
|
+
process.env = { ...process.env, ...correctEnvVars, ...credToken };
|
|
52
|
+
try {
|
|
53
|
+
await (0, configs_1.checkAwsCredentials)('not-a-real-account');
|
|
54
|
+
// throw an error so that if the logic is altered and process.exit isnt hit we can force the test to fail
|
|
55
|
+
throw new Error('Force the test to hit the catch');
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
(0, globals_1.expect)(process.exit).toBeCalledWith(1);
|
|
59
|
+
(0, globals_1.expect)(warnSpy).toBeCalledWith(missingExpirationToken);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
(0, globals_1.it)('logs an error when AWS_CREDENTIAL_EXPIRATION has expired', async () => {
|
|
63
|
+
process.env = { ...process.env, ...correctEnvVars, ...{ AWS_CREDENTIAL_EXPIRATION: '2024-01-01T12:00:00Z' } };
|
|
64
|
+
try {
|
|
65
|
+
await (0, configs_1.checkAwsCredentials)('not-a-real-account');
|
|
66
|
+
// throw an error so that if the logic is altered and process.exit isnt hit we can force the test to fail
|
|
67
|
+
throw new Error('Force the test to hit the catch');
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
(0, globals_1.expect)(process.exit).toBeCalledWith(1);
|
|
71
|
+
(0, globals_1.expect)(errorSpy).toBeCalledWith('There are AWS credentials in the env, but they have expired. They expired at 2024-01-01T12:00:00Z');
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
(0, globals_1.it)('logs a warning when AWS_CREDENTIAL_EXPIRATION has nearly expired', async () => {
|
|
75
|
+
process.env = { ...process.env, ...correctEnvVars, ...{ AWS_CREDENTIAL_EXPIRATION: '2025-01-01T12:10:00Z' } };
|
|
76
|
+
try {
|
|
77
|
+
await (0, configs_1.checkAwsCredentials)('not-a-real-account');
|
|
78
|
+
// throw an error so that if the logic is altered and process.exit isnt hit we can force the test to fail
|
|
79
|
+
throw new Error('Force the test to hit the catch');
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
(0, globals_1.expect)(process.exit).toBeCalledWith(1);
|
|
83
|
+
(0, globals_1.expect)(warnSpy).toBeCalledWith('WARNING: The AWS credentials will expire at 2025-01-01T12:10:00Z which is within 15 minutes\n');
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|