@middy/secrets-manager 2.5.6 → 3.0.0-alpha.3
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/LICENSE +1 -1
- package/README.md +1 -4
- package/index.js +11 -13
- package/package.json +10 -8
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017-
|
|
3
|
+
Copyright (c) 2017-2022 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -53,13 +53,10 @@ npm install --save @middy/secrets-manager
|
|
|
53
53
|
- `disablePrefetch` (boolean) (default `false`): On cold start requests will trigger early if they can. Setting `awsClientAssumeRole` disables prefetch.
|
|
54
54
|
- `cacheKey` (string) (default `secrets-manager`): Cache key for the fetched data responses. Must be unique across all middleware.
|
|
55
55
|
- `cacheExpiry` (number) (default `-1`): How long fetch data responses should be cached for. `-1`: cache forever, `0`: never cache, `n`: cache for n ms.
|
|
56
|
-
- `setToEnv` (boolean) (default `false`): Store secrets to `process.env`. **Storing secrets in `process.env` is considered security bad practice**
|
|
57
56
|
- `setToContext` (boolean) (default `false`): Store secrets to `request.context`.
|
|
58
57
|
|
|
59
58
|
NOTES:
|
|
60
59
|
- Lambda is required to have IAM permission for `secretsmanager:GetSecretValue`
|
|
61
|
-
- `setToEnv` and `setToContext` are included for legacy support and should be avoided for performance and security reasons. See main documentation for best practices.
|
|
62
|
-
- `setToEnv` can only assign secrets of type string
|
|
63
60
|
|
|
64
61
|
## Sample usage
|
|
65
62
|
|
|
@@ -99,7 +96,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
|
|
|
99
96
|
|
|
100
97
|
## License
|
|
101
98
|
|
|
102
|
-
Licensed under [MIT License](LICENSE). Copyright (c) 2017-
|
|
99
|
+
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
|
103
100
|
|
|
104
101
|
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
|
|
105
102
|
<img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
|
package/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
2
|
canPrefetch,
|
|
3
3
|
createPrefetchClient,
|
|
4
4
|
createClient,
|
|
5
|
-
processCache,
|
|
6
5
|
getCache,
|
|
6
|
+
getInternal,
|
|
7
|
+
processCache,
|
|
7
8
|
modifyCache,
|
|
8
|
-
jsonSafeParse
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// const { SecretsManager } = require('@aws-sdk/client-secrets-manager') // v3
|
|
9
|
+
jsonSafeParse
|
|
10
|
+
} from '@middy/util'
|
|
11
|
+
import SecretsManager from 'aws-sdk/clients/secretsmanager.js' // v2
|
|
12
|
+
// import { SecretsManager } from '@aws-sdk/client-secrets-manager' // v3
|
|
13
13
|
|
|
14
14
|
const defaults = {
|
|
15
15
|
AwsClient: SecretsManager,
|
|
@@ -20,7 +20,6 @@ const defaults = {
|
|
|
20
20
|
disablePrefetch: false,
|
|
21
21
|
cacheKey: 'secrets-manager',
|
|
22
22
|
cacheExpiry: -1,
|
|
23
|
-
setToEnv: false, // can return object when requesting db credentials, cannot set to process.env
|
|
24
23
|
setToContext: false
|
|
25
24
|
}
|
|
26
25
|
|
|
@@ -41,7 +40,7 @@ const secretsManagerMiddleware = (opts = {}) => {
|
|
|
41
40
|
.promise() // Required for aws-sdk v2
|
|
42
41
|
.then((resp) => jsonSafeParse(resp.SecretString))
|
|
43
42
|
.catch((e) => {
|
|
44
|
-
const value = getCache(options.cacheKey)
|
|
43
|
+
const value = getCache(options.cacheKey).value ?? {}
|
|
45
44
|
value[internalKey] = undefined
|
|
46
45
|
modifyCache(options.cacheKey, value)
|
|
47
46
|
throw e
|
|
@@ -65,10 +64,9 @@ const secretsManagerMiddleware = (opts = {}) => {
|
|
|
65
64
|
|
|
66
65
|
Object.assign(request.internal, value)
|
|
67
66
|
|
|
68
|
-
if (options.setToContext
|
|
67
|
+
if (options.setToContext) {
|
|
69
68
|
const data = await getInternal(Object.keys(options.fetchData), request)
|
|
70
|
-
|
|
71
|
-
if (options.setToContext) Object.assign(request.context, data)
|
|
69
|
+
Object.assign(request.context, data)
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
prefetch = null
|
|
@@ -78,4 +76,4 @@ const secretsManagerMiddleware = (opts = {}) => {
|
|
|
78
76
|
before: secretsManagerMiddlewareBefore
|
|
79
77
|
}
|
|
80
78
|
}
|
|
81
|
-
|
|
79
|
+
export default secretsManagerMiddleware
|
package/package.json
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/secrets-manager",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.3",
|
|
4
4
|
"description": "Secrets Manager middleware for the middy framework",
|
|
5
|
-
"type": "
|
|
5
|
+
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=14"
|
|
8
8
|
},
|
|
9
9
|
"engineStrict": true,
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
13
|
+
"exports": "./index.js",
|
|
14
14
|
"types": "index.d.ts",
|
|
15
15
|
"files": [
|
|
16
|
+
"index.js",
|
|
16
17
|
"index.d.ts"
|
|
17
18
|
],
|
|
18
19
|
"scripts": {
|
|
19
20
|
"test": "npm run test:unit",
|
|
20
|
-
"test:unit": "ava"
|
|
21
|
+
"test:unit": "ava",
|
|
22
|
+
"test:benchmark": "node __benchmarks__/index.js"
|
|
21
23
|
},
|
|
22
24
|
"license": "MIT",
|
|
23
25
|
"keywords": [
|
|
@@ -44,12 +46,12 @@
|
|
|
44
46
|
},
|
|
45
47
|
"homepage": "https://github.com/middyjs/middy#readme",
|
|
46
48
|
"dependencies": {
|
|
47
|
-
"@middy/util": "^
|
|
49
|
+
"@middy/util": "^3.0.0-alpha.3"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
|
-
"@middy/core": "^
|
|
52
|
+
"@middy/core": "^3.0.0-alpha.3",
|
|
51
53
|
"aws-sdk": "^2.939.0",
|
|
52
54
|
"aws-xray-sdk": "^3.3.3"
|
|
53
55
|
},
|
|
54
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "1441158711580313765e6d156046ef0fade0d156"
|
|
55
57
|
}
|