ac-awssecrets 2.2.1 → 2.3.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 +29 -0
- package/index.js +9 -4
- package/package.json +2 -2
- package/test/config.js +8 -0
- package/test/test.js +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
<a name="2.3.0"></a>
|
|
2
|
+
|
|
3
|
+
# [2.3.0](https://github.com/admiralcloud/ac-awssecrets/compare/v2.2.1..v2.3.0) (2024-08-12 10:04:48)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Feature
|
|
7
|
+
|
|
8
|
+
* **App:** Add option to merge AWS parameters with config | MP | [e000f4b824a44c39f2b4b99c8b20440fefd80fb3](https://github.com/admiralcloud/ac-awssecrets/commit/e000f4b824a44c39f2b4b99c8b20440fefd80fb3)
|
|
9
|
+
Add option to merge AWS parameters with config instead of overwriting (default)
|
|
10
|
+
Related issues: [undefined/undefined#master](undefined/browse/master)
|
|
11
|
+
### Chores
|
|
12
|
+
|
|
13
|
+
* **App:** Updated packages | MP | [286853f0f9bd9a4456e6b52e79027d7afa645fd5](https://github.com/admiralcloud/ac-awssecrets/commit/286853f0f9bd9a4456e6b52e79027d7afa645fd5)
|
|
14
|
+
Updated packages
|
|
15
|
+
Related issues: [undefined/undefined#master](undefined/browse/master)
|
|
1
16
|
<a name="2.2.1"></a>
|
|
2
17
|
|
|
3
18
|
## [2.2.1](https://github.com/admiralcloud/ac-awssecrets/compare/v2.2.0..v2.2.1) (2024-08-09 15:10:41)
|
package/README.md
CHANGED
|
@@ -59,6 +59,34 @@ const config = {
|
|
|
59
59
|
]
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
+
```
|
|
63
|
+
```
|
|
64
|
+
// example with merge = true
|
|
65
|
+
const config = {
|
|
66
|
+
aws: {
|
|
67
|
+
account: 123,
|
|
68
|
+
s3: {
|
|
69
|
+
region: 'eu-central-1'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/development/aws -> { account: 456 }
|
|
75
|
+
const payload = {
|
|
76
|
+
secretParameters: [
|
|
77
|
+
{ name: 'aws', json: true, merge: true },
|
|
78
|
+
],
|
|
79
|
+
config
|
|
80
|
+
}
|
|
81
|
+
await awsSecrets.loadSecretParameters(payload)
|
|
82
|
+
|
|
83
|
+
// final result
|
|
84
|
+
config.aws = {
|
|
85
|
+
account: 456,
|
|
86
|
+
s3: {
|
|
87
|
+
region: 'eu-central-1'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
62
90
|
|
|
63
91
|
```
|
|
64
92
|
|
|
@@ -70,6 +98,7 @@ const config = {
|
|
|
70
98
|
|json|boolean|-|If true, the parameter value will be parsed as JSON
|
|
71
99
|
|array|boolean|-|If true, the the value will be pushed to the array at name or path
|
|
72
100
|
|property|object|-|If set, instead of pushing the value to an array it will inserted at the object which matches the property
|
|
101
|
+
|merge|boolean|-|If true, objects from AWS parameters will be merged with existing objects
|
|
73
102
|
|
|
74
103
|
|
|
75
104
|
# AWS Secrets
|
package/index.js
CHANGED
|
@@ -31,7 +31,7 @@ const awsSecrets = () => {
|
|
|
31
31
|
: setKey(obj[head], rest.join('.'), value)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const setValue = (config, { path, value, array = false, property }) => {
|
|
34
|
+
const setValue = (config, { path, value, array = false, property, merge = false }) => {
|
|
35
35
|
// path can be from AWS parametes store (/a/b/c) or a real JSON path (a.b.c)
|
|
36
36
|
const keys = path.includes('/') ? path.split('/').filter(Boolean) : path.split('.')
|
|
37
37
|
const lastKey = keys.pop()
|
|
@@ -68,7 +68,12 @@ const awsSecrets = () => {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
|
-
pointer[lastKey]
|
|
71
|
+
if (merge && typeof pointer[lastKey] === 'object' && !Array.isArray(pointer[lastKey]) && typeof value === 'object' && !Array.isArray(value)) {
|
|
72
|
+
pointer[lastKey] = { ...pointer[lastKey], ...value }
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
pointer[lastKey] = value
|
|
76
|
+
}
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
|
|
@@ -82,7 +87,7 @@ const awsSecrets = () => {
|
|
|
82
87
|
}
|
|
83
88
|
const ssmClient = new SSMClient(awsConfig)
|
|
84
89
|
|
|
85
|
-
const getSecretParameter = async({ name, json = false, array = false, path, property, debug }) => {
|
|
90
|
+
const getSecretParameter = async({ name, json = false, array = false, path, property, debug, merge }) => {
|
|
86
91
|
const parameterName = `/${environment}/${name}`
|
|
87
92
|
try {
|
|
88
93
|
let value
|
|
@@ -110,7 +115,7 @@ const awsSecrets = () => {
|
|
|
110
115
|
if (debug) {
|
|
111
116
|
console.warn('P %s | T %s | V %j', parameterName, typeof value, value)
|
|
112
117
|
}
|
|
113
|
-
setValue(config, { path: (path || name), value, array, property })
|
|
118
|
+
setValue(config, { path: (path || name), value, array, property, merge })
|
|
114
119
|
|
|
115
120
|
}
|
|
116
121
|
catch (e) {
|
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.3.0",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@aws-sdk/client-secrets-manager": "^3.624.0",
|
|
9
|
-
"@aws-sdk/client-ssm": "^3.
|
|
9
|
+
"@aws-sdk/client-ssm": "^3.628.0"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"ac-semantic-release": "^0.4.2",
|
package/test/config.js
CHANGED
|
@@ -18,6 +18,7 @@ const config = {
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
aws: {
|
|
21
|
+
account: '123',
|
|
21
22
|
accessKeys: []
|
|
22
23
|
},
|
|
23
24
|
configVar7: {
|
|
@@ -33,6 +34,7 @@ const secretParameters = [
|
|
|
33
34
|
{ name: 'configVar4/api', json: true },
|
|
34
35
|
{ name: 'configVar5.path', json: true },
|
|
35
36
|
{ name: 'configVar6', json: true },
|
|
37
|
+
{ name: 'aws', json: true, merge: true }
|
|
36
38
|
]
|
|
37
39
|
|
|
38
40
|
const parameterStore = [
|
|
@@ -66,6 +68,12 @@ const parameterStore = [
|
|
|
66
68
|
prop2: 'abc'
|
|
67
69
|
})
|
|
68
70
|
},
|
|
71
|
+
{
|
|
72
|
+
name: '/test/aws',
|
|
73
|
+
value: JSON.stringify({
|
|
74
|
+
account: '456'
|
|
75
|
+
})
|
|
76
|
+
}
|
|
69
77
|
]
|
|
70
78
|
|
|
71
79
|
|
package/test/test.js
CHANGED
|
@@ -67,6 +67,12 @@ describe('Reading secretParameters', () => {
|
|
|
67
67
|
it('Check non existing key - should fallback to existing value without error', async() => {
|
|
68
68
|
expect(config.configVar7).to.have.property('level', 'info')
|
|
69
69
|
})
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
it('Check merge config', async() => {
|
|
73
|
+
expect(config.aws).to.have.property('account', '456')
|
|
74
|
+
expect(config.aws).to.have.property('accessKeys').length(0)
|
|
75
|
+
})
|
|
70
76
|
})
|
|
71
77
|
|
|
72
78
|
|