ac-awssecrets 2.3.3 → 2.4.0
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/CHANGELOG.md +15 -0
- package/README.md +19 -0
- package/index.js +57 -4
- package/package.json +4 -4
- package/test/config.js +13 -3
- package/test/test.js +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
<a name="2.4.0"></a>
|
|
2
|
+
|
|
3
|
+
# [2.4.0](https://github.com/admiralcloud/ac-awssecrets/compare/v2.3.3..v2.4.0) (2024-10-18 13:41:05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Feature
|
|
7
|
+
|
|
8
|
+
* **App:** Allow retrieving paramters by path | MP | [3a2b7be3a3a7cff5132fcb3a19cab6cbb382beed](https://github.com/admiralcloud/ac-awssecrets/commit/3a2b7be3a3a7cff5132fcb3a19cab6cbb382beed)
|
|
9
|
+
You can fetch and add multiple parameter from they same path with one entry. See README for example
|
|
10
|
+
Related issues: [undefined/undefined#master](undefined/browse/master)
|
|
11
|
+
### Chores
|
|
12
|
+
|
|
13
|
+
* **App:** Updated packages | MP | [52502906bf6f1071d8e896f34139f865eac3559b](https://github.com/admiralcloud/ac-awssecrets/commit/52502906bf6f1071d8e896f34139f865eac3559b)
|
|
14
|
+
Updated packages
|
|
15
|
+
Related issues: [undefined/undefined#master](undefined/browse/master)
|
|
1
16
|
<a name="2.3.3"></a>
|
|
2
17
|
|
|
3
18
|
## [2.3.3](https://github.com/admiralcloud/ac-awssecrets/compare/v2.3.2..v2.3.3) (2024-09-28 08:08:07)
|
package/README.md
CHANGED
|
@@ -88,6 +88,24 @@ config.aws = {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
// USE WITH PATH
|
|
92
|
+
/development/db1 -> { url: 'https://db1.admiralcloud.com' }
|
|
93
|
+
/development/db2 -> { url: 'https://db2.admiralcloud.com' }
|
|
94
|
+
|
|
95
|
+
const payload = {
|
|
96
|
+
secretParameters: [
|
|
97
|
+
{ name: 'db/*', path: 'database', json: true, merge: true },
|
|
98
|
+
],
|
|
99
|
+
config
|
|
100
|
+
}
|
|
101
|
+
await awsSecrets.loadSecretParameters(payload)
|
|
102
|
+
|
|
103
|
+
// final result
|
|
104
|
+
config.database = [
|
|
105
|
+
{ url: 'https://db1.admiralcloud.com' },
|
|
106
|
+
{ url: 'https://db2.admiralcloud.com' }
|
|
107
|
+
]
|
|
108
|
+
|
|
91
109
|
```
|
|
92
110
|
|
|
93
111
|
## Options
|
|
@@ -99,6 +117,7 @@ config.aws = {
|
|
|
99
117
|
|array|boolean|-|If true, the the value will be pushed to the array at name or path
|
|
100
118
|
|property|object|-|If set, instead of pushing the value to an array it will inserted at the object which matches the property
|
|
101
119
|
|merge|boolean|-|If true, objects from AWS parameters will be merged with existing objects
|
|
120
|
+
|ignoreInTestMode|boolean|-|If true, parameter will be ignored if environment is test
|
|
102
121
|
|
|
103
122
|
|
|
104
123
|
# AWS Secrets
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { SecretsManagerClient, GetSecretValueCommand } = require('@aws-sdk/client-secrets-manager')
|
|
2
|
-
const { SSMClient, GetParameterCommand } = require("@aws-sdk/client-ssm")
|
|
2
|
+
const { SSMClient, GetParameterCommand, GetParametersByPathCommand } = require("@aws-sdk/client-ssm")
|
|
3
3
|
|
|
4
4
|
const testConfig = require('./test/config')
|
|
5
5
|
const functionName = 'ac-awsSecrets'.padEnd(15)
|
|
@@ -78,7 +78,6 @@ const awsSecrets = () => {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
|
|
81
|
-
|
|
82
81
|
const loadSecretParameters = async({ secretParameters = [], config = {}, testMode = 0, debug = false, throwError = false, region = 'eu-central-1' } = {}) => {
|
|
83
82
|
const environment = config?.environment || process.env.NODE_ENV || 'development'
|
|
84
83
|
|
|
@@ -94,7 +93,7 @@ const awsSecrets = () => {
|
|
|
94
93
|
if (testMode === 3) {
|
|
95
94
|
// fetch from availableSecrets
|
|
96
95
|
let found = testConfig.parameterStore.find(item => item.name === parameterName)
|
|
97
|
-
value = found?.value
|
|
96
|
+
value = found?.value
|
|
98
97
|
}
|
|
99
98
|
else {
|
|
100
99
|
const command = new GetParameterCommand({
|
|
@@ -124,10 +123,64 @@ const awsSecrets = () => {
|
|
|
124
123
|
}
|
|
125
124
|
}
|
|
126
125
|
|
|
126
|
+
// pushes multiple paramters into the given path (e.g. params /dev/db/1 and /dev/db/2 (name = /dev/db/*) will be objects in array databases (path))
|
|
127
|
+
const getSecretParametersByPath = async({ name, json = false, array = true, path, property, debug, merge }) => {
|
|
128
|
+
if (!path) throw new Error('pathMustBeSet')
|
|
129
|
+
const parameterName = `/${environment}/${name}`
|
|
130
|
+
try {
|
|
131
|
+
let valueArray
|
|
132
|
+
if (testMode === 3) {
|
|
133
|
+
// fetch from availableSecrets
|
|
134
|
+
valueArray = testConfig.parameterStore.filter(item => {
|
|
135
|
+
return item.name.startsWith(parameterName.replace('*', ''))
|
|
136
|
+
})
|
|
137
|
+
valueArray = valueArray.map(item => {
|
|
138
|
+
return {
|
|
139
|
+
Name: item?.name,
|
|
140
|
+
Type: 'SecureString',
|
|
141
|
+
Value: item?.value,
|
|
142
|
+
Version: 1,
|
|
143
|
+
LastModifiedDate: new Date(),
|
|
144
|
+
ARN: `arn:aws:ssm:region:account-id:parameter/${item?.name}`,
|
|
145
|
+
DataType: 'text'
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
// fetch all paramters with the path
|
|
151
|
+
const command = new GetParametersByPathCommand({
|
|
152
|
+
Path: parameterName.replace('*', ''),
|
|
153
|
+
Recursive: true,
|
|
154
|
+
WithDecryption: true,
|
|
155
|
+
})
|
|
156
|
+
const response = await ssmClient.send(command)
|
|
157
|
+
valueArrays = response?.Parameters
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
for (const item of valueArray) {
|
|
161
|
+
let value = item?.Value
|
|
162
|
+
// Extract and return the parameter value
|
|
163
|
+
if (json) {
|
|
164
|
+
value = JSON.parse(value)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (debug) {
|
|
168
|
+
console.warn('P %s | T %s | V %j', item?.Name, typeof value, value)
|
|
169
|
+
}
|
|
170
|
+
setValue(config, { path, value, array, property, merge })
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
console.error('%s | %s | %s', functionName, parameterName, e?.message)
|
|
175
|
+
if (throwError) throw e
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
127
179
|
for (const secretParameter of secretParameters) {
|
|
128
180
|
if (environment === 'test' && secretParameter?.ignoreInTestMode) continue
|
|
129
181
|
if (debug) secretParameter.debug = true
|
|
130
|
-
await
|
|
182
|
+
if (secretParameter.name.endsWith('*')) await getSecretParametersByPath(secretParameter)
|
|
183
|
+
else await getSecretParameter(secretParameter)
|
|
131
184
|
}
|
|
132
185
|
}
|
|
133
186
|
|
package/package.json
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
"author": "Mark Poepping (https://www.admiralcloud.com)",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "admiralcloud/ac-awssecrets",
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.4.0",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
|
9
|
-
"@aws-sdk/client-ssm": "^3.
|
|
8
|
+
"@aws-sdk/client-secrets-manager": "^3.674.0",
|
|
9
|
+
"@aws-sdk/client-ssm": "^3.674.0"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"ac-semantic-release": "^0.4.3",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"mocha": "^10.7.3"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
|
-
"test": "NODE_ENV=test mocha --reporter spec",
|
|
19
|
+
"test": "NODE_ENV=test mocha --reporter spec --bail",
|
|
20
20
|
"coverage": "./node_modules/c8/bin/c8.js yarn test"
|
|
21
21
|
},
|
|
22
22
|
"engines": {
|
package/test/config.js
CHANGED
|
@@ -23,7 +23,8 @@ const config = {
|
|
|
23
23
|
},
|
|
24
24
|
configVar7: {
|
|
25
25
|
level: 'info'
|
|
26
|
-
}
|
|
26
|
+
},
|
|
27
|
+
db: []
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
|
|
@@ -34,7 +35,8 @@ const secretParameters = [
|
|
|
34
35
|
{ name: 'configVar4/api', json: true },
|
|
35
36
|
{ name: 'configVar5.path', json: true },
|
|
36
37
|
{ name: 'configVar6', json: true },
|
|
37
|
-
{ name: 'aws', json: true, merge: true }
|
|
38
|
+
{ name: 'aws', json: true, merge: true },
|
|
39
|
+
{ name: 'db/*', json: true, merge: true, path: 'db' }
|
|
38
40
|
]
|
|
39
41
|
|
|
40
42
|
const parameterStore = [
|
|
@@ -73,7 +75,15 @@ const parameterStore = [
|
|
|
73
75
|
value: JSON.stringify({
|
|
74
76
|
account: '456'
|
|
75
77
|
})
|
|
76
|
-
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: '/test/db/1',
|
|
81
|
+
value: JSON.stringify({ url: 'https://db1.admiralcloud.com' }),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: '/test/db/2',
|
|
85
|
+
value: JSON.stringify({ url: 'https://db2.admiralcloud.com' }),
|
|
86
|
+
},
|
|
77
87
|
]
|
|
78
88
|
|
|
79
89
|
|
package/test/test.js
CHANGED
|
@@ -73,6 +73,12 @@ describe('Reading secretParameters', () => {
|
|
|
73
73
|
expect(config.aws).to.have.property('account', '456')
|
|
74
74
|
expect(config.aws).to.have.property('accessKeys').length(0)
|
|
75
75
|
})
|
|
76
|
+
|
|
77
|
+
it('Check path secrets', async() => {
|
|
78
|
+
expect(config.db).to.have.length(2)
|
|
79
|
+
expect(config.db[0]).to.have.property('url', 'https://db1.admiralcloud.com')
|
|
80
|
+
expect(config.db[1]).to.have.property('url', 'https://db2.admiralcloud.com')
|
|
81
|
+
})
|
|
76
82
|
})
|
|
77
83
|
|
|
78
84
|
|