@middy/rds-signer 3.6.1 → 4.0.0-alpha.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/README.md +8 -10
- package/index.cjs +7 -17
- package/index.d.ts +3 -2
- package/index.js +7 -12
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -46,11 +46,10 @@ To install this middleware you can use NPM:
|
|
|
46
46
|
npm install --save @middy/rds-signer
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
|
|
50
49
|
## Options
|
|
51
50
|
|
|
52
|
-
- `AwsClient` (object) (default `
|
|
53
|
-
- `awsClientOptions` (object) (default `undefined`): Options to pass to
|
|
51
|
+
- `AwsClient` (object) (default `Signer`): Signer class constructor (e.g. that has been instrumented with AWS XRay). Must be from `@aws-sdk/rds-signer`.
|
|
52
|
+
- `awsClientOptions` (object) (default `undefined`): Options to pass to Signer class constructor.
|
|
54
53
|
- `fetchData` (object `{ contextKey: {region, hostname, username, database, port} }`) (required): Mapping of internal key name to API request parameters.
|
|
55
54
|
- `disablePrefetch` (boolean) (default `false`): On cold start requests will trigger early if they can. Setting `awsClientAssumeRole` disables prefetch.
|
|
56
55
|
- `cacheKey` (string) (default `rds-signer`): Cache key for the fetched data responses. Must be unique across all middleware.
|
|
@@ -58,6 +57,7 @@ npm install --save @middy/rds-signer
|
|
|
58
57
|
- `setToContext` (boolean) (default `false`): Store role tokens to `request.context`.
|
|
59
58
|
|
|
60
59
|
NOTES:
|
|
60
|
+
|
|
61
61
|
- 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}`
|
|
62
62
|
|
|
63
63
|
## Sample usage
|
|
@@ -71,13 +71,13 @@ const handler = middy((event, context) => {
|
|
|
71
71
|
statusCode: 200,
|
|
72
72
|
headers: {},
|
|
73
73
|
body: JSON.stringify({ message: 'hello world' })
|
|
74
|
-
}
|
|
74
|
+
}
|
|
75
75
|
|
|
76
76
|
return response
|
|
77
77
|
})
|
|
78
78
|
|
|
79
|
-
handler
|
|
80
|
-
|
|
79
|
+
handler.use(
|
|
80
|
+
rdsSigner({
|
|
81
81
|
fetchData: {
|
|
82
82
|
rdsToken: {
|
|
83
83
|
region: 'ca-central-1',
|
|
@@ -87,20 +87,18 @@ handler
|
|
|
87
87
|
port: 5432
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
})
|
|
90
|
+
})
|
|
91
|
+
)
|
|
91
92
|
```
|
|
92
93
|
|
|
93
|
-
|
|
94
94
|
## Middy documentation and examples
|
|
95
95
|
|
|
96
96
|
For more documentation and examples, refers to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org).
|
|
97
97
|
|
|
98
|
-
|
|
99
98
|
## Contributing
|
|
100
99
|
|
|
101
100
|
Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
|
|
102
101
|
|
|
103
|
-
|
|
104
102
|
## License
|
|
105
103
|
|
|
106
104
|
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
package/index.cjs
CHANGED
|
@@ -7,14 +7,9 @@ Object.defineProperty(module, "exports", {
|
|
|
7
7
|
get: ()=>_default
|
|
8
8
|
});
|
|
9
9
|
const _util = require("@middy/util");
|
|
10
|
-
const
|
|
11
|
-
function _interopRequireDefault(obj) {
|
|
12
|
-
return obj && obj.__esModule ? obj : {
|
|
13
|
-
default: obj
|
|
14
|
-
};
|
|
15
|
-
}
|
|
10
|
+
const _rdsSigner = require("@aws-sdk/rds-signer");
|
|
16
11
|
const defaults = {
|
|
17
|
-
AwsClient:
|
|
12
|
+
AwsClient: _rdsSigner.Signer,
|
|
18
13
|
awsClientOptions: {},
|
|
19
14
|
fetchData: {},
|
|
20
15
|
disablePrefetch: false,
|
|
@@ -35,16 +30,11 @@ const rdsSignerMiddleware = (opts = {})=>{
|
|
|
35
30
|
...options.awsClientOptions,
|
|
36
31
|
...options.fetchData[internalKey]
|
|
37
32
|
});
|
|
38
|
-
values[internalKey] =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!token.includes('X-Amz-Security-Token=')) {
|
|
44
|
-
reject(new Error('[rds-signer] X-Amz-Security-Token Missing'));
|
|
45
|
-
}
|
|
46
|
-
resolve(token);
|
|
47
|
-
});
|
|
33
|
+
values[internalKey] = client.getAuthToken().then((token)=>{
|
|
34
|
+
if (!token.includes('X-Amz-Security-Token=')) {
|
|
35
|
+
throw new Error('[rds-signer] X-Amz-Security-Token Missing');
|
|
36
|
+
}
|
|
37
|
+
return token;
|
|
48
38
|
}).catch((e)=>{
|
|
49
39
|
const value = (0, _util.getCache)(options.cacheKey).value ?? {};
|
|
50
40
|
value[internalKey] = undefined;
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import RDS from 'aws-sdk/clients/rds'
|
|
2
1
|
import middy from '@middy/core'
|
|
3
2
|
import { Options as MiddyOptions } from '@middy/util'
|
|
3
|
+
import { SignerConfig, Signer } from '@aws-sdk/rds-signer'
|
|
4
4
|
|
|
5
|
-
interface Options<
|
|
5
|
+
interface Options<AwsSigner = Signer>
|
|
6
|
+
extends MiddyOptions<AwsSigner, SignerConfig> {}
|
|
6
7
|
|
|
7
8
|
declare function rdsSigner (options?: Options): middy.MiddlewareObj
|
|
8
9
|
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { canPrefetch, getInternal, processCache, getCache, modifyCache } from '@middy/util';
|
|
2
|
-
import
|
|
2
|
+
import { Signer } from '@aws-sdk/rds-signer';
|
|
3
3
|
const defaults = {
|
|
4
|
-
AwsClient:
|
|
4
|
+
AwsClient: Signer,
|
|
5
5
|
awsClientOptions: {},
|
|
6
6
|
fetchData: {},
|
|
7
7
|
disablePrefetch: false,
|
|
@@ -22,16 +22,11 @@ const rdsSignerMiddleware = (opts = {})=>{
|
|
|
22
22
|
...options.awsClientOptions,
|
|
23
23
|
...options.fetchData[internalKey]
|
|
24
24
|
});
|
|
25
|
-
values[internalKey] =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!token.includes('X-Amz-Security-Token=')) {
|
|
31
|
-
reject(new Error('[rds-signer] X-Amz-Security-Token Missing'));
|
|
32
|
-
}
|
|
33
|
-
resolve(token);
|
|
34
|
-
});
|
|
25
|
+
values[internalKey] = client.getAuthToken().then((token)=>{
|
|
26
|
+
if (!token.includes('X-Amz-Security-Token=')) {
|
|
27
|
+
throw new Error('[rds-signer] X-Amz-Security-Token Missing');
|
|
28
|
+
}
|
|
29
|
+
return token;
|
|
35
30
|
}).catch((e)=>{
|
|
36
31
|
const value = getCache(options.cacheKey).value ?? {};
|
|
37
32
|
value[internalKey] = undefined;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/rds-signer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.0",
|
|
4
4
|
"description": "RDS (Relational Database Service) credentials middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=16"
|
|
8
8
|
},
|
|
9
9
|
"engineStrict": true,
|
|
10
10
|
"publishConfig": {
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
},
|
|
63
63
|
"homepage": "https://middy.js.org",
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@middy/util": "
|
|
65
|
+
"@middy/util": "4.0.0-alpha.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@
|
|
68
|
+
"@aws-sdk/rds-signer": "^3.186.0",
|
|
69
|
+
"@middy/core": "4.0.0-alpha.0",
|
|
69
70
|
"@types/node": "^18.0.0",
|
|
70
|
-
"aws-sdk": "^2.939.0",
|
|
71
71
|
"aws-xray-sdk": "^3.3.3"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "306fb9aa633d5757d11ced3dc192f046ef3c2685"
|
|
74
74
|
}
|