@wavo-cloud/aws-secrets-manager-helper 0.1.11 → 0.1.12
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/.circleci/config.yml +24 -12
- package/CODEOWNERS +1 -0
- package/Dockerfile +2 -1
- package/README.md +9 -7
- package/codecov.yml +6 -0
- package/docker-compose.test.yml +4 -1
- package/package.json +6 -5
- package/pull_request_template.md +11 -0
- package/test/aws.test.js +53 -26
package/.circleci/config.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
version: 2.1
|
|
2
|
+
orbs:
|
|
3
|
+
codecov: codecov/codecov@1.1.3
|
|
2
4
|
jobs:
|
|
3
|
-
|
|
4
|
-
|
|
5
5
|
test:
|
|
6
6
|
docker:
|
|
7
7
|
- image: circleci/node:12.13
|
|
@@ -10,12 +10,22 @@ jobs:
|
|
|
10
10
|
- checkout
|
|
11
11
|
- setup_remote_docker
|
|
12
12
|
|
|
13
|
+
- run:
|
|
14
|
+
name: Adding NPM credentials
|
|
15
|
+
command: |
|
|
16
|
+
if [ ! -z "${WAVO_CLOUD_READ_NPM_TOKEN}" ]; then
|
|
17
|
+
echo "//registry.npmjs.org/:_authToken=$WAVO_CLOUD_READ_NPM_TOKEN" > ~/.npmrc
|
|
18
|
+
else
|
|
19
|
+
echo "Error: WAVO_CLOUD_READ_NPM_TOKEN not found."
|
|
20
|
+
false
|
|
21
|
+
fi
|
|
22
|
+
|
|
13
23
|
# Download and cache dependencies
|
|
14
24
|
- restore_cache: &restore_cache
|
|
15
25
|
keys:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
- v1-dependencies-{{ checksum "package.json" }}
|
|
27
|
+
# fallback to using the latest cache if no exact match is found
|
|
28
|
+
- v1-dependencies-
|
|
19
29
|
|
|
20
30
|
- run: yarn install
|
|
21
31
|
|
|
@@ -23,7 +33,7 @@ jobs:
|
|
|
23
33
|
paths:
|
|
24
34
|
- node_modules
|
|
25
35
|
key: v1-dependencies-{{ checksum "package.json" }}
|
|
26
|
-
|
|
36
|
+
|
|
27
37
|
# run tests!
|
|
28
38
|
- run:
|
|
29
39
|
name: Run tests (if possible)
|
|
@@ -31,6 +41,9 @@ jobs:
|
|
|
31
41
|
if ./node_modules/@wavo-cloud/generator-microservice/shared/util/test-checks.sh; then
|
|
32
42
|
yarn ci-test
|
|
33
43
|
fi
|
|
44
|
+
- codecov/upload:
|
|
45
|
+
file: '/home/circleci/project/coverage/coverage-final.json'
|
|
46
|
+
token: 91eab9ce-01c7-4429-b973-470e75b73de7
|
|
34
47
|
|
|
35
48
|
module-push:
|
|
36
49
|
docker:
|
|
@@ -38,7 +51,7 @@ jobs:
|
|
|
38
51
|
|
|
39
52
|
steps:
|
|
40
53
|
- checkout
|
|
41
|
-
|
|
54
|
+
|
|
42
55
|
- restore_cache: *restore_cache
|
|
43
56
|
|
|
44
57
|
- run:
|
|
@@ -52,18 +65,17 @@ jobs:
|
|
|
52
65
|
echo "WAVO_CLOUD_WRITE_NPM_TOKEN not found. Skipping generator module push."
|
|
53
66
|
fi
|
|
54
67
|
|
|
55
|
-
|
|
56
68
|
workflows:
|
|
57
69
|
version: 2
|
|
58
70
|
test-and-deploy:
|
|
59
71
|
jobs:
|
|
60
|
-
|
|
72
|
+
- test:
|
|
61
73
|
context: org-global
|
|
62
|
-
|
|
74
|
+
- module-push:
|
|
63
75
|
context: org-global
|
|
64
76
|
requires:
|
|
65
77
|
- test
|
|
66
|
-
|
|
78
|
+
|
|
67
79
|
filters:
|
|
68
80
|
branches:
|
|
69
81
|
only: master
|
package/CODEOWNERS
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* @Wavo/wavo-cloud-core
|
package/Dockerfile
CHANGED
|
@@ -5,7 +5,8 @@ RUN mkdir -p /usr/local/src/cloud-app
|
|
|
5
5
|
WORKDIR /usr/local/src/cloud-app
|
|
6
6
|
|
|
7
7
|
# Add .npmrc, package.json & yarn.lock
|
|
8
|
-
|
|
8
|
+
ARG WAVO_CLOUD_READ_NPM_TOKEN
|
|
9
|
+
RUN echo "//registry.npmjs.org/:_authToken=$WAVO_CLOUD_READ_NPM_TOKEN" > ~/.npmrc
|
|
9
10
|
COPY package.json yarn.lock /usr/local/src/cloud-app/
|
|
10
11
|
|
|
11
12
|
# Install modules with yarn
|
package/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
[](https://circleci.com/gh/Wavo/wavo-cloud.aws-secrets-manager-helper)
|
|
2
|
+
[](https://codecov.io/gh/Wavo/wavo-cloud.aws-secrets-manager-helper)
|
|
3
|
+
|
|
1
4
|
# wavo-cloud.aws-secrets-manager-helper
|
|
2
5
|
|
|
3
6
|
> Wavo Cloud Infallible AWS Secrets Manager Helper
|
|
@@ -24,14 +27,15 @@ To get all client secrets call `getAllClientSecrets()`
|
|
|
24
27
|
## Important Commands
|
|
25
28
|
|
|
26
29
|
### Building the Dockerfile image
|
|
27
|
-
$ yarn image-build
|
|
28
30
|
|
|
31
|
+
$ yarn image-build
|
|
29
32
|
|
|
30
33
|
### Prettify the Source
|
|
31
|
-
$ yarn prettify
|
|
32
34
|
|
|
35
|
+
$ yarn prettify
|
|
33
36
|
|
|
34
37
|
### Start the Microservice
|
|
38
|
+
|
|
35
39
|
When using this option, node is passed the `--inspect` flag so you can inspect your code with the debugger of your choice. If your microservice is a worker or if you need it to block and wait for the debugger to connect use the "debug mode" instead.
|
|
36
40
|
|
|
37
41
|
$ yarn start
|
|
@@ -40,10 +44,9 @@ Dockerized version (using `docker-compose`):
|
|
|
40
44
|
|
|
41
45
|
$ yarn docker-start
|
|
42
46
|
|
|
43
|
-
|
|
44
47
|
### Start the Microservice in Debug Mode
|
|
45
48
|
|
|
46
|
-
Important: when you run the microservice in debug mode, it is going to be started with node's `--inspect-brk` flag.
|
|
49
|
+
Important: when you run the microservice in debug mode, it is going to be started with node's `--inspect-brk` flag.
|
|
47
50
|
**This implies that the microservice will block and wait for a debugger to connect to port 5858 and resume code execution.**
|
|
48
51
|
|
|
49
52
|
$ yarn debug
|
|
@@ -52,14 +55,13 @@ Dockerized version (using `docker-compose`):
|
|
|
52
55
|
|
|
53
56
|
$ yarn docker-debug
|
|
54
57
|
|
|
55
|
-
|
|
56
58
|
### Running the Tests
|
|
57
59
|
|
|
58
|
-
Important: when you run the microservice in debug mode, it is going to be started with node's `--inspect-brk` flag.
|
|
60
|
+
Important: when you run the microservice in debug mode, it is going to be started with node's `--inspect-brk` flag.
|
|
59
61
|
**This implies that the microservice will block and wait for a debugger to connect to port 5858 and resume code execution.**
|
|
60
62
|
|
|
61
63
|
$ yarn test
|
|
62
|
-
|
|
64
|
+
|
|
63
65
|
Dockerized version (using `docker-compose`):
|
|
64
66
|
|
|
65
67
|
$ yarn docker-test
|
package/codecov.yml
ADDED
package/docker-compose.test.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wavo-cloud/aws-secrets-manager-helper",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "Wavo Cloud Infallible AWS Secrets Manager Helper",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
"image-push": "./node_modules/@wavo-cloud/generator-microservice/shared/util/image-push.sh",
|
|
18
18
|
"k8s-deploy": "./node_modules/@wavo-cloud/generator-microservice/shared/util/k8s-deploy.sh",
|
|
19
19
|
"prettier": "node ./node_modules/prettier/bin-prettier.js --write --single-quote --print-width 120 --no-semi '**/*.js'",
|
|
20
|
-
"test": "NODE_ENV=${NODE_ENV-test} node ./node_modules/mocha/bin/mocha --recursive --require mock-local-storage",
|
|
20
|
+
"test": "NODE_ENV=${NODE_ENV-test} node ./node_modules/nyc/bin/nyc --reporter=json ./node_modules/mocha/bin/mocha --recursive --require mock-local-storage",
|
|
21
21
|
"docker-dev-up": "docker-compose -f ./docker-compose.dev.yml up",
|
|
22
22
|
"docker-dev-down": "docker-compose -f ./docker-compose.dev.yml down",
|
|
23
23
|
"docker-test": "docker-compose -f ./docker-compose.test.yml down; docker-compose -f ./docker-compose.test.yml build && docker-compose -f ./docker-compose.test.yml run --rm app; R=$?; docker-compose -f ./docker-compose.test.yml down; [ $R -eq 0 ]",
|
|
24
|
-
"ci-test": "yarn
|
|
24
|
+
"ci-test": "yarn test"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@wavo-cloud/eslint-config": "^0.0.9",
|
|
28
|
-
"@wavo-cloud/generator-microservice": "^
|
|
28
|
+
"@wavo-cloud/generator-microservice": "^6.0.0",
|
|
29
29
|
"chai": "^4.2.0",
|
|
30
30
|
"eslint": "^7.6.0",
|
|
31
31
|
"eslint-config-prettier": "^3.1.0",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"aws-sdk": "^2.713.0",
|
|
38
|
-
"lodash": "^4.17.19"
|
|
38
|
+
"lodash": "^4.17.19",
|
|
39
|
+
"nyc": "^15.1.0"
|
|
39
40
|
},
|
|
40
41
|
"bugs": {
|
|
41
42
|
"url": "https://github.com/Wavo/wavo-cloud.aws-secrets-manager-helper/issues"
|
package/test/aws.test.js
CHANGED
|
@@ -14,7 +14,28 @@ const expect = require('chai').expect
|
|
|
14
14
|
|
|
15
15
|
const clientIdsSecretId = 'wavo/self_serve/client_list_test'
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* In this test file, we sleep between calls
|
|
19
|
+
* This is because I presume that AWS is returning early optimistic API responses,
|
|
20
|
+
* and doing additional work behind our backs.
|
|
21
|
+
*
|
|
22
|
+
* Reasoning: if you run `yarn test; yarn test;` back to back tests, you will see
|
|
23
|
+
* an error from AWS complaining that we're running calls against a deleted resource.
|
|
24
|
+
* This implies that even after we get the "delete successful" response from AWS, they're
|
|
25
|
+
* still in the process of deleting the resource.
|
|
26
|
+
*
|
|
27
|
+
* Since we sleep for 2 seconds, I set the test timeouts to be 4s.
|
|
28
|
+
*/
|
|
29
|
+
function sleep(ms) {
|
|
30
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
31
|
+
}
|
|
32
|
+
|
|
17
33
|
describe('Test Secrets Manager Helper', async () => {
|
|
34
|
+
const randomString = Math.random().toString(36).substring(7);
|
|
35
|
+
const clientId = 'test_client_id_' + randomString
|
|
36
|
+
const organization = 'test_organization_' + randomString
|
|
37
|
+
const newOrganization = organization + '_new'
|
|
38
|
+
|
|
18
39
|
/**
|
|
19
40
|
* This function call tests all of the helper functions
|
|
20
41
|
*/
|
|
@@ -24,13 +45,14 @@ describe('Test Secrets Manager Helper', async () => {
|
|
|
24
45
|
expect(clientSecrets.length).to.be.above(0)
|
|
25
46
|
expect(clientSecrets[0].clientId).to.not.be.null
|
|
26
47
|
expect(clientSecrets[0].secretId).to.not.be.null
|
|
27
|
-
|
|
48
|
+
await sleep(2000)
|
|
49
|
+
}).timeout(4000)
|
|
28
50
|
|
|
29
51
|
it('should create a new client', async () => {
|
|
30
52
|
const createClientResult = await createClient({
|
|
31
|
-
clientId
|
|
53
|
+
clientId,
|
|
32
54
|
clientName: 'test_client_name',
|
|
33
|
-
organization
|
|
55
|
+
organization,
|
|
34
56
|
region: 'test_region',
|
|
35
57
|
keyValuePairs: { test_secret_key: 'test_secret_value' },
|
|
36
58
|
clientIdsSecretIdOverride: clientIdsSecretId,
|
|
@@ -38,85 +60,89 @@ describe('Test Secrets Manager Helper', async () => {
|
|
|
38
60
|
isActiveOrganization: true,
|
|
39
61
|
})
|
|
40
62
|
expect(createClientResult.createSecretResults.Name).to.equal(
|
|
41
|
-
|
|
63
|
+
`${organization}/ad_platforms/api`
|
|
42
64
|
)
|
|
43
65
|
|
|
44
|
-
const newClientTags = await getSecretTags(
|
|
66
|
+
const newClientTags = await getSecretTags(`${organization}/ad_platforms/api`)
|
|
45
67
|
const isActiveOrganizationTag = newClientTags.find(
|
|
46
68
|
tag => tag.Key === 'is_active_organization'
|
|
47
69
|
)
|
|
48
70
|
expect(isActiveOrganizationTag.Value === 'true')
|
|
49
71
|
|
|
50
72
|
const clientList = await getClientSecretIds(clientIdsSecretId)
|
|
51
|
-
expect(clientList[
|
|
52
|
-
|
|
73
|
+
expect(clientList[clientId]).to.equal(
|
|
74
|
+
`${organization}/ad_platforms/api`
|
|
53
75
|
)
|
|
54
|
-
|
|
76
|
+
await sleep(2000)
|
|
77
|
+
}).timeout(4000)
|
|
55
78
|
|
|
56
79
|
it('should change the clients active status to false', async () => {
|
|
57
80
|
await setClientActiveStatus({
|
|
58
|
-
clientId
|
|
81
|
+
clientId,
|
|
59
82
|
newActiveStatus: false,
|
|
60
83
|
clientIdsSecretIdOverride: clientIdsSecretId,
|
|
61
84
|
})
|
|
62
85
|
|
|
63
|
-
const clientTags = await getSecretTags(
|
|
86
|
+
const clientTags = await getSecretTags(`${organization}/ad_platforms/api`)
|
|
64
87
|
const isActiveOrganizationTag = clientTags.find(
|
|
65
88
|
tag => tag.Key === 'is_active_organization'
|
|
66
89
|
)
|
|
67
90
|
expect(isActiveOrganizationTag.Value === 'falsey')
|
|
68
91
|
|
|
69
|
-
|
|
92
|
+
await sleep(2000)
|
|
93
|
+
}).timeout(4000)
|
|
70
94
|
|
|
71
95
|
it('should set a client', async () => {
|
|
72
96
|
await setClient({
|
|
73
|
-
clientId
|
|
97
|
+
clientId,
|
|
74
98
|
clientName: 'test_client_name_2',
|
|
75
|
-
organization
|
|
99
|
+
organization,
|
|
76
100
|
region: 'test_region_new',
|
|
77
101
|
keyValuePairs: { test_secret_key_new: 'test_secret_value_new', to_delete: 'to_delete' },
|
|
78
102
|
clientIdsSecretIdOverride: clientIdsSecretId
|
|
79
103
|
})
|
|
80
104
|
|
|
81
105
|
const testSecret = await getSecretValue(
|
|
82
|
-
|
|
106
|
+
`${organization}/ad_platforms/api`
|
|
83
107
|
)
|
|
84
108
|
expect(testSecret.client_name).to.equal('test_client_name_2')
|
|
85
|
-
expect(testSecret.organization).to.equal(
|
|
109
|
+
expect(testSecret.organization).to.equal(organization)
|
|
86
110
|
expect(testSecret.region).to.equal('test_region_new')
|
|
87
111
|
expect(testSecret.test_secret_key).to.equal(undefined)
|
|
88
112
|
expect(testSecret.test_secret_key_new).to.equal('test_secret_value_new')
|
|
89
113
|
expect(testSecret.to_delete).to.equal('to_delete')
|
|
90
|
-
|
|
114
|
+
await sleep(2000)
|
|
115
|
+
}).timeout(4000)
|
|
91
116
|
|
|
92
117
|
it('should edit, add, and delete a client key/value secret', async () => {
|
|
93
118
|
await editClient({
|
|
94
|
-
clientId
|
|
119
|
+
clientId,
|
|
95
120
|
keyValuePairsToAdd: {
|
|
96
121
|
test_secret_key_new: 'edit',
|
|
97
122
|
new_key: 'add',
|
|
98
|
-
organization:
|
|
123
|
+
organization: newOrganization
|
|
99
124
|
},
|
|
100
125
|
keysToDelete: ['to_delete'],
|
|
101
126
|
clientIdsSecretIdOverride: clientIdsSecretId
|
|
102
127
|
})
|
|
103
128
|
|
|
104
129
|
const testSecret = await getSecretValue(
|
|
105
|
-
|
|
130
|
+
`${organization}/ad_platforms/api`
|
|
106
131
|
)
|
|
107
132
|
|
|
108
133
|
expect(testSecret.client_name).to.equal('test_client_name_2')
|
|
109
|
-
expect(testSecret.organization).to.equal(
|
|
134
|
+
expect(testSecret.organization).to.equal(newOrganization)
|
|
110
135
|
expect(testSecret.region).to.equal('test_region_new')
|
|
111
136
|
expect(testSecret.test_secret_key_new).to.equal('edit')
|
|
112
137
|
expect(testSecret.new_key).to.equal('add')
|
|
113
138
|
expect(testSecret.to_delete).to.equal(undefined)
|
|
114
|
-
|
|
139
|
+
await sleep(2000)
|
|
140
|
+
}).timeout(4000)
|
|
115
141
|
|
|
116
142
|
it('should delete a client', async () => {
|
|
117
143
|
//let clientList
|
|
118
144
|
await deleteClient(
|
|
119
|
-
|
|
145
|
+
clientId,
|
|
120
146
|
true,
|
|
121
147
|
30,
|
|
122
148
|
clientIdsSecretId,
|
|
@@ -126,11 +152,12 @@ describe('Test Secrets Manager Helper', async () => {
|
|
|
126
152
|
|
|
127
153
|
try {
|
|
128
154
|
await getSecretValue(
|
|
129
|
-
|
|
155
|
+
`${organization}/ad_platforms/api`
|
|
130
156
|
)
|
|
131
|
-
expect.fail(
|
|
157
|
+
expect.fail(`'${organization}/ad_platforms/api' should not be a valid secret value`)
|
|
132
158
|
} catch (error) {
|
|
133
|
-
expect(clientList[
|
|
159
|
+
expect(clientList[clientId]).to.equal(undefined)
|
|
134
160
|
}
|
|
135
|
-
|
|
161
|
+
await sleep(2000)
|
|
162
|
+
}).timeout(4000)
|
|
136
163
|
})
|