Skip to content

Commit 965415b

Browse files
committed
README updated
1 parent 57db927 commit 965415b

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

README.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Manage JSON based configurations with AES encrypted secrets for multiple environ
1212

1313
Optional features:
1414
- [HMAC validation](#hmacValidation) of configurations to ensure data integrity
15-
- Setting of environment variables out of configuration items
15+
- Setting of [environment variables](#envVarExports) out of configuration items
1616

1717
Works with CommonJS and ESM/ECMAScript. Ships with a [SBOM](#SBOM) to meet regulatory requirements.
1818

@@ -243,13 +243,11 @@ Depending on the value of `NODE_ENV` the following configuration files will be l
243243
Type: `Array`
244244
Default: `[]`
245245
246-
With `envVarExports` you can set environment variables out of configuration items by passing an array of objects each having a `key` and `envVar` property where:
247-
- `key` is the name of a configuration item
246+
With the `envVarExports` option (or alternatively the `__envVarExports` configuration key) you can set environment variables out of configuration items by passing an array of objects each having a `key` and `envVar` property where:
247+
- `key` is the name of a configuration item, if the configuration item is not at the top level of the configuration JSON, simply pass the full path to it using dotted notation (see example below)
248248
- `envVar` is the name of the environment variable to be set with the value of the configuration item
249249
- both properties must be of type string
250250
251-
If the configuration item is not at the top level of the configuration JSON, simply pass the full path to it using dotted notation (see example below).
252-
253251
Suppose you have the following configuation...
254252
255253
```json
@@ -262,7 +260,9 @@ Suppose you have the following configuation...
262260
}
263261
```
264262
265-
...and need to set the database user and password as environment variables `DB_USER` and `DB_PASSWORD`. Then simply pass the following `envVarExports` array.
263+
...and need to set the database user and password as environment variables `DB_USER` and `DB_PASSWORD`. Then simply pass the following `envVarExports` array either programmatically or directly in the configuration via the `__envVarExports` key.
264+
265+
Programmatic passing:
266266
267267
```js
268268
const envVarExports = [
@@ -272,11 +272,34 @@ const envVarExports = [
272272
const conf = require('@tsmx/secure-config')({ envVarExports });
273273
```
274274
275-
This will automatically set the env vars `DB_USER` and `DB_PASSWORD` with the decrypted configuration item values.
275+
Passing via configuration:
276+
277+
```JSON
278+
{
279+
"database": {
280+
"host": "127.0.0.1",
281+
"user": "ENCRYPTED|50ceed2f97223100fbdf842ecbd4541f|df9ed9002bfc956eb14b1d2f8d960a11",
282+
"pass": "ENCRYPTED|8fbf6ded36bcb15bd4734b3dc78f2890|7463b2ea8ed2c8d71272ac2e41761a35"
283+
},
284+
"__envVarExports": [
285+
{
286+
"key": "database.user",
287+
"envVar": "DB_USER"
288+
},
289+
{
290+
"key": "database.pass",
291+
"envVar": "DB_PASSWORD"
292+
}
293+
]
294+
}
295+
```
296+
297+
Both approaches will automatically set the env vars `DB_USER` and `DB_PASSWORD` with the decrypted configuration item values.
276298
277299
Notes:
278300
- If the `envVarExports` array contains multiple entries having the exact same `key`, only the first entry will be considered.
279301
- If `envVarExports` contains entries that cannot be found in the configuration, no env var will be set and no error will be thrown.
302+
- If the `envVarExports` option AND the `__envVarExports` configuration key both are present, the programmatic passed arry will take precedence.
280303
281304
## Injecting the decryption key
282305
@@ -388,10 +411,3 @@ This package ships with a CycloneDX software bill of materials (SBOM) v1.6 in JS
388411
389412
### 2.3.1
390413
- [SBOM](#SBOM) added to shipped files
391-
392-
## Test
393-
394-
```
395-
npm install
396-
npm test
397-
```

0 commit comments

Comments
 (0)