@middy/rds-signer 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 -3
- package/index.js +12 -14
- package/package.json +11 -9
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
|
@@ -44,12 +44,10 @@ npm install --save @middy/rds-signer
|
|
|
44
44
|
- `disablePrefetch` (boolean) (default `false`): On cold start requests will trigger early if they can. Setting `awsClientAssumeRole` disables prefetch.
|
|
45
45
|
- `cacheKey` (string) (default `rds-signer`): Cache key for the fetched data responses. Must be unique across all middleware.
|
|
46
46
|
- `cacheExpiry` (number) (default `-1`): How long fetch data responses should be cached for. `-1`: cache forever, `0`: never cache, `n`: cache for n ms.
|
|
47
|
-
- `setToEnv` (boolean) (default `false`): Store role tokens to `process.env`. **Storing secrets in `process.env` is considered security bad practice**
|
|
48
47
|
- `setToContext` (boolean) (default `false`): Store role tokens to `request.context`.
|
|
49
48
|
|
|
50
49
|
NOTES:
|
|
51
50
|
- Lambda is required to have IAM permission for `rds-db:connect` with a resource like `arn:aws:rds-db:#{AWS::Region}:#{AWS::AccountId}:dbuser:${database_resource}/${iam_role}`
|
|
52
|
-
- `setToEnv` and `setToContext` are included for legacy support and should be avoided for performance and security reasons. See main documentation for best practices.
|
|
53
51
|
|
|
54
52
|
## Sample usage
|
|
55
53
|
|
|
@@ -94,7 +92,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
|
|
|
94
92
|
|
|
95
93
|
## License
|
|
96
94
|
|
|
97
|
-
Licensed under [MIT License](LICENSE). Copyright (c) 2017-
|
|
95
|
+
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
|
98
96
|
|
|
99
97
|
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
|
|
100
98
|
<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,21 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
2
|
canPrefetch,
|
|
3
3
|
getInternal,
|
|
4
4
|
processCache,
|
|
5
5
|
getCache,
|
|
6
6
|
modifyCache
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
//
|
|
7
|
+
} from '@middy/util'
|
|
8
|
+
import RDS from 'aws-sdk/clients/rds.js' // v2
|
|
9
|
+
// import { RDS:{Signer} } from '@aws-sdk/client-rds' // v3
|
|
10
10
|
|
|
11
11
|
const defaults = {
|
|
12
|
-
AwsClient: Signer,
|
|
12
|
+
AwsClient: RDS.Signer,
|
|
13
13
|
awsClientOptions: {},
|
|
14
14
|
fetchData: {}, // { contextKey: {region, hostname, username, database, port} }
|
|
15
15
|
disablePrefetch: false,
|
|
16
16
|
cacheKey: 'rds-signer',
|
|
17
17
|
cacheExpiry: -1,
|
|
18
|
-
setToEnv: false,
|
|
19
18
|
setToContext: false
|
|
20
19
|
}
|
|
21
20
|
|
|
@@ -33,9 +32,9 @@ const rdsSignerMiddleware = (opts = {}) => {
|
|
|
33
32
|
})
|
|
34
33
|
// AWS doesn't support getAuthToken.promise() in aws-sdk v2 :( See https://github.com/aws/aws-sdk-js/issues/3595
|
|
35
34
|
values[internalKey] = new Promise((resolve, reject) => {
|
|
36
|
-
client.getAuthToken({}, (
|
|
37
|
-
if (
|
|
38
|
-
reject(
|
|
35
|
+
client.getAuthToken({}, (e, token) => {
|
|
36
|
+
if (e) {
|
|
37
|
+
reject(e)
|
|
39
38
|
}
|
|
40
39
|
// Catch Missing token, this usually means their is something wrong with the credentials
|
|
41
40
|
if (!token.includes('X-Amz-Security-Token=')) {
|
|
@@ -44,7 +43,7 @@ const rdsSignerMiddleware = (opts = {}) => {
|
|
|
44
43
|
resolve(token)
|
|
45
44
|
})
|
|
46
45
|
}).catch((e) => {
|
|
47
|
-
const value = getCache(options.cacheKey)
|
|
46
|
+
const value = getCache(options.cacheKey).value ?? {}
|
|
48
47
|
value[internalKey] = undefined
|
|
49
48
|
modifyCache(options.cacheKey, value)
|
|
50
49
|
throw e
|
|
@@ -66,10 +65,9 @@ const rdsSignerMiddleware = (opts = {}) => {
|
|
|
66
65
|
|
|
67
66
|
Object.assign(request.internal, value)
|
|
68
67
|
|
|
69
|
-
if (options.setToContext
|
|
68
|
+
if (options.setToContext) {
|
|
70
69
|
const data = await getInternal(Object.keys(options.fetchData), request)
|
|
71
|
-
|
|
72
|
-
if (options.setToContext) Object.assign(request.context, data)
|
|
70
|
+
Object.assign(request.context, data)
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
prefetch = null
|
|
@@ -79,4 +77,4 @@ const rdsSignerMiddleware = (opts = {}) => {
|
|
|
79
77
|
before: rdsSignerMiddlewareBefore
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
|
-
|
|
80
|
+
export default rdsSignerMiddleware
|
package/package.json
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/rds-signer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.3",
|
|
4
4
|
"description": "RDS (Relational Database Service) credentials 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": [
|
|
@@ -46,13 +48,13 @@
|
|
|
46
48
|
},
|
|
47
49
|
"homepage": "https://github.com/middyjs/middy#readme",
|
|
48
50
|
"dependencies": {
|
|
49
|
-
"@middy/util": "^
|
|
51
|
+
"@middy/util": "^3.0.0-alpha.3"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
|
-
"@middy/core": "^
|
|
53
|
-
"@types/node": "^
|
|
54
|
+
"@middy/core": "^3.0.0-alpha.3",
|
|
55
|
+
"@types/node": "^17.0.0",
|
|
54
56
|
"aws-sdk": "^2.939.0",
|
|
55
57
|
"aws-xray-sdk": "^3.3.3"
|
|
56
58
|
},
|
|
57
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "1441158711580313765e6d156046ef0fade0d156"
|
|
58
60
|
}
|