@middy/rds-signer 3.0.3 → 3.0.4
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/index.cjs +73 -1
- package/index.js +62 -1
- package/package.json +4 -4
package/index.cjs
CHANGED
|
@@ -1,3 +1,75 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
module.exports = void 0;
|
|
6
|
+
var _util = require("@middy/util");
|
|
7
|
+
var _rdsJs = _interopRequireDefault(require("aws-sdk/clients/rds.js"));
|
|
8
|
+
function _interopRequireDefault(obj) {
|
|
9
|
+
return obj && obj.__esModule ? obj : {
|
|
10
|
+
default: obj
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const defaults = {
|
|
14
|
+
AwsClient: _rdsJs.default.Signer,
|
|
15
|
+
awsClientOptions: {},
|
|
16
|
+
fetchData: {},
|
|
17
|
+
disablePrefetch: false,
|
|
18
|
+
cacheKey: 'rds-signer',
|
|
19
|
+
cacheExpiry: -1,
|
|
20
|
+
setToContext: false
|
|
21
|
+
};
|
|
22
|
+
const rdsSignerMiddleware = (opts = {})=>{
|
|
23
|
+
const options = {
|
|
24
|
+
...defaults,
|
|
25
|
+
...opts
|
|
26
|
+
};
|
|
27
|
+
const fetch = (request, cachedValues = {})=>{
|
|
28
|
+
const values = {};
|
|
29
|
+
for (const internalKey of Object.keys(options.fetchData)){
|
|
30
|
+
if (cachedValues[internalKey]) continue;
|
|
31
|
+
const client = new options.AwsClient({
|
|
32
|
+
...options.awsClientOptions,
|
|
33
|
+
...options.fetchData[internalKey]
|
|
34
|
+
});
|
|
35
|
+
values[internalKey] = new Promise((resolve, reject)=>{
|
|
36
|
+
client.getAuthToken({}, (e, token)=>{
|
|
37
|
+
if (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
if (!token.includes('X-Amz-Security-Token=')) {
|
|
41
|
+
reject(new Error('[rds-signer] X-Amz-Security-Token Missing'));
|
|
42
|
+
}
|
|
43
|
+
resolve(token);
|
|
44
|
+
});
|
|
45
|
+
}).catch((e)=>{
|
|
46
|
+
const value = (0, _util).getCache(options.cacheKey).value ?? {};
|
|
47
|
+
value[internalKey] = undefined;
|
|
48
|
+
(0, _util).modifyCache(options.cacheKey, value);
|
|
49
|
+
throw e;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return values;
|
|
53
|
+
};
|
|
54
|
+
let prefetch;
|
|
55
|
+
if ((0, _util).canPrefetch(options)) {
|
|
56
|
+
prefetch = (0, _util).processCache(options, fetch);
|
|
57
|
+
}
|
|
58
|
+
const rdsSignerMiddlewareBefore = async (request)=>{
|
|
59
|
+
const { value } = prefetch ?? (0, _util).processCache(options, fetch, request);
|
|
60
|
+
Object.assign(request.internal, value);
|
|
61
|
+
if (options.setToContext) {
|
|
62
|
+
const data = await (0, _util).getInternal(Object.keys(options.fetchData), request);
|
|
63
|
+
Object.assign(request.context, data);
|
|
64
|
+
}
|
|
65
|
+
prefetch = null;
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
before: rdsSignerMiddlewareBefore
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
var _default = rdsSignerMiddleware;
|
|
72
|
+
module.exports = _default;
|
|
73
|
+
|
|
2
74
|
|
|
3
75
|
//# sourceMappingURL=index.cjs.map
|
package/index.js
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
-
import{canPrefetch,getInternal,processCache,getCache,modifyCache}from
|
|
1
|
+
import { canPrefetch, getInternal, processCache, getCache, modifyCache } from '@middy/util';
|
|
2
|
+
import RDS from 'aws-sdk/clients/rds.js';
|
|
3
|
+
const defaults = {
|
|
4
|
+
AwsClient: RDS.Signer,
|
|
5
|
+
awsClientOptions: {},
|
|
6
|
+
fetchData: {},
|
|
7
|
+
disablePrefetch: false,
|
|
8
|
+
cacheKey: 'rds-signer',
|
|
9
|
+
cacheExpiry: -1,
|
|
10
|
+
setToContext: false
|
|
11
|
+
};
|
|
12
|
+
const rdsSignerMiddleware = (opts = {})=>{
|
|
13
|
+
const options = {
|
|
14
|
+
...defaults,
|
|
15
|
+
...opts
|
|
16
|
+
};
|
|
17
|
+
const fetch = (request, cachedValues = {})=>{
|
|
18
|
+
const values = {};
|
|
19
|
+
for (const internalKey of Object.keys(options.fetchData)){
|
|
20
|
+
if (cachedValues[internalKey]) continue;
|
|
21
|
+
const client = new options.AwsClient({
|
|
22
|
+
...options.awsClientOptions,
|
|
23
|
+
...options.fetchData[internalKey]
|
|
24
|
+
});
|
|
25
|
+
values[internalKey] = new Promise((resolve, reject)=>{
|
|
26
|
+
client.getAuthToken({}, (e, token)=>{
|
|
27
|
+
if (e) {
|
|
28
|
+
reject(e);
|
|
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
|
+
});
|
|
35
|
+
}).catch((e)=>{
|
|
36
|
+
const value = getCache(options.cacheKey).value ?? {};
|
|
37
|
+
value[internalKey] = undefined;
|
|
38
|
+
modifyCache(options.cacheKey, value);
|
|
39
|
+
throw e;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return values;
|
|
43
|
+
};
|
|
44
|
+
let prefetch;
|
|
45
|
+
if (canPrefetch(options)) {
|
|
46
|
+
prefetch = processCache(options, fetch);
|
|
47
|
+
}
|
|
48
|
+
const rdsSignerMiddlewareBefore = async (request)=>{
|
|
49
|
+
const { value } = prefetch ?? processCache(options, fetch, request);
|
|
50
|
+
Object.assign(request.internal, value);
|
|
51
|
+
if (options.setToContext) {
|
|
52
|
+
const data = await getInternal(Object.keys(options.fetchData), request);
|
|
53
|
+
Object.assign(request.context, data);
|
|
54
|
+
}
|
|
55
|
+
prefetch = null;
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
before: rdsSignerMiddlewareBefore
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export default rdsSignerMiddleware;
|
|
62
|
+
|
|
2
63
|
|
|
3
64
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/rds-signer",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "RDS (Relational Database Service) credentials middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -55,13 +55,13 @@
|
|
|
55
55
|
},
|
|
56
56
|
"homepage": "https://middy.js.org",
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@middy/util": "3.0.
|
|
58
|
+
"@middy/util": "3.0.4"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@middy/core": "3.0.
|
|
61
|
+
"@middy/core": "3.0.4",
|
|
62
62
|
"@types/node": "^17.0.0",
|
|
63
63
|
"aws-sdk": "^2.939.0",
|
|
64
64
|
"aws-xray-sdk": "^3.3.3"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "3e9bc83e791f943c71cd7003fc27f0a3692d83a1"
|
|
67
67
|
}
|