ac-awssecrets 2.1.0 → 2.1.1

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 CHANGED
@@ -1,3 +1,18 @@
1
+ <a name="2.1.1"></a>
2
+
3
+ ## [2.1.1](https://github.com/admiralcloud/ac-awssecrets/compare/v2.1.0..v2.1.1) (2024-05-08 13:44:22)
4
+
5
+
6
+ ### Bug Fix
7
+
8
+ * **App:** Only set value from secret, if secret exists | MP | [ab1b8e87bd1e35c7eb4428c1aa90ad9a93597d9e](https://github.com/admiralcloud/ac-awssecrets/commit/ab1b8e87bd1e35c7eb4428c1aa90ad9a93597d9e)
9
+ Only set value from secret, if secret exists
10
+ Related issues: [undefined/undefined#master](undefined/browse/master)
11
+ ### Chores
12
+
13
+ * **App:** Updated packages | MP | [57d506749cbcad5372c84952a8e7929dd62dca37](https://github.com/admiralcloud/ac-awssecrets/commit/57d506749cbcad5372c84952a8e7929dd62dca37)
14
+ Updated packages
15
+ Related issues: [undefined/undefined#master](undefined/browse/master)
1
16
  <a name="2.1.0"></a>
2
17
 
3
18
  # [2.1.0](https://github.com/admiralcloud/ac-awssecrets/compare/v2.0.5..v2.1.0) (2023-12-31 14:46:52)
package/index.js CHANGED
@@ -102,55 +102,56 @@ const awsSecrets = () => {
102
102
  for (const secret of secrets) {
103
103
  let existingValue = getKey(config, secret.key) || {}
104
104
  let value = secret?.value
105
-
106
- // convert values
107
- if (typeof value === 'object') {
108
- Object.keys(value).forEach((key) => {
109
- let val = value[key]
110
- if (val === 'true') val = true
111
- else if (val === 'false') val = false
112
- else if (typeof val === 'string' && val.startsWith('JSON:')) {
113
- try {
114
- val = JSON.parse(val.substring(5))
115
- }
116
- catch(e) {
117
- console.error('%s | %s | JSON could not be parsed %j', functionName, secret.name, val)
118
- throw new Error('invalidJSON')
119
- }
120
- }
121
- value[key] = val
122
- })
123
- }
124
-
125
- if (secret.servers) {
126
- if (typeof secret.servers === 'boolean') {
127
- let servers = existingValue?.servers || []
128
- config[secret.key].servers = servers.map(server => {
129
- if (server.server === secret.serverName) {
130
- server = { ...server, ...value }
105
+ if (value) {
106
+ // convert values
107
+ if (typeof value === 'object') {
108
+ Object.keys(value).forEach((key) => {
109
+ let val = value[key]
110
+ if (val === 'true') val = true
111
+ else if (val === 'false') val = false
112
+ else if (typeof val === 'string' && val.startsWith('JSON:')) {
113
+ try {
114
+ val = JSON.parse(val.substring(5))
115
+ }
116
+ catch(e) {
117
+ console.error('%s | %s | JSON could not be parsed %j', functionName, secret.name, val)
118
+ throw new Error('invalidJSON')
119
+ }
131
120
  }
132
- return server
121
+ value[key] = val
133
122
  })
134
123
  }
135
- else {
136
- // NEW NOTATION AS OBJECT
137
- /* TODO: Probably not used anywhere, so legacy is ok
138
- let match = {}
139
- _.set(match, _.get(secret.servers, 'identifier'), _.get(secret.servers, 'value'))
140
- existingValue = _.find(_.get(config, key, []), match)
141
- */
124
+
125
+ if (secret.servers) {
126
+ if (typeof secret.servers === 'boolean') {
127
+ let servers = existingValue?.servers || []
128
+ config[secret.key].servers = servers.map(server => {
129
+ if (server.server === secret.serverName) {
130
+ server = { ...server, ...value }
131
+ }
132
+ return server
133
+ })
134
+ }
135
+ else {
136
+ // NEW NOTATION AS OBJECT
137
+ /* TODO: Probably not used anywhere, so legacy is ok
138
+ let match = {}
139
+ _.set(match, _.get(secret.servers, 'identifier'), _.get(secret.servers, 'value'))
140
+ existingValue = _.find(_.get(config, key, []), match)
141
+ */
142
+ }
142
143
  }
143
- }
144
- else if (secret?.type === 'arrayObject') {
145
- existingValue.push(value)
146
- setKey(config, secret.key, existingValue)
147
- }
148
- else {
149
- if (Object.keys(existingValue).length === 0) {
150
- setKey(config, secret.key, {})
144
+ else if (secret?.type === 'arrayObject') {
145
+ existingValue.push(value)
146
+ setKey(config, secret.key, existingValue)
147
+ }
148
+ else {
149
+ if (Object.keys(existingValue).length === 0) {
150
+ setKey(config, secret.key, {})
151
+ }
152
+ existingValue = { ...existingValue, ...value }
153
+ setKey(config, secret.key, existingValue)
151
154
  }
152
- existingValue = { ...existingValue, ...value }
153
- setKey(config, secret.key, existingValue)
154
155
  }
155
156
 
156
157
  if (secret?.log || debug) {
package/package.json CHANGED
@@ -3,16 +3,16 @@
3
3
  "author": "Mark Poepping (https://www.admiralcloud.com)",
4
4
  "license": "MIT",
5
5
  "repository": "admiralcloud/ac-awssecrets",
6
- "version": "2.1.0",
6
+ "version": "2.1.1",
7
7
  "dependencies": {
8
- "@aws-sdk/client-secrets-manager": "^3.484.0"
8
+ "@aws-sdk/client-secrets-manager": "^3.569.0"
9
9
  },
10
10
  "devDependencies": {
11
11
  "ac-semantic-release": "^0.4.2",
12
- "c8": "^8.0.1",
13
- "chai": "^4.3.8",
12
+ "c8": "^9.1.0",
13
+ "chai": "^4.4.1",
14
14
  "eslint": "8.x",
15
- "mocha": "^10.2.0"
15
+ "mocha": "^10.4.0"
16
16
  },
17
17
  "scripts": {
18
18
  "test": "mocha --reporter spec",
package/test/config.js CHANGED
@@ -19,6 +19,9 @@ const config = {
19
19
  },
20
20
  aws: {
21
21
  accessKeys: []
22
+ },
23
+ configVar7: {
24
+ level: 'info'
22
25
  }
23
26
  }
24
27
 
@@ -28,6 +31,7 @@ const secrets = [
28
31
  { key: 'configVar4', name: 'json' },
29
32
  { key: 'configVar5.path', name: 'path' },
30
33
  { key: 'configVar6', name: 'notExistingLocally' },
34
+ { key: 'configVar7', name: 'notExistingKey' },
31
35
  ]
32
36
 
33
37
  const availableSecrets = [{
package/test/test.js CHANGED
@@ -61,6 +61,10 @@ describe('Reading secrets', () => {
61
61
  expect(config.configVar6).to.have.property('prop2', 'abc')
62
62
  })
63
63
 
64
+ it('Check non existing key - should fallback to existing value without error', async() => {
65
+ expect(config.configVar7).to.have.property('level', 'info')
66
+ })
67
+
64
68
  it('Check multisecrets', async() => {
65
69
  //console.log(50, config.aws.accessKeys)
66
70
  expect(config.aws.accessKeys).to.have.length(2)