@middy/secrets-manager 3.0.3 → 3.1.0-rc.1
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 +67 -1
- package/index.js +56 -1
- package/package.json +13 -7
package/index.cjs
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
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 _secretsmanagerJs = _interopRequireDefault(require("aws-sdk/clients/secretsmanager.js"));
|
|
8
|
+
function _interopRequireDefault(obj) {
|
|
9
|
+
return obj && obj.__esModule ? obj : {
|
|
10
|
+
default: obj
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const defaults = {
|
|
14
|
+
AwsClient: _secretsmanagerJs.default,
|
|
15
|
+
awsClientOptions: {},
|
|
16
|
+
awsClientAssumeRole: undefined,
|
|
17
|
+
awsClientCapture: undefined,
|
|
18
|
+
fetchData: {},
|
|
19
|
+
disablePrefetch: false,
|
|
20
|
+
cacheKey: 'secrets-manager',
|
|
21
|
+
cacheExpiry: -1,
|
|
22
|
+
setToContext: false
|
|
23
|
+
};
|
|
24
|
+
const secretsManagerMiddleware = (opts = {})=>{
|
|
25
|
+
const options = {
|
|
26
|
+
...defaults,
|
|
27
|
+
...opts
|
|
28
|
+
};
|
|
29
|
+
const fetch = (request, cachedValues = {})=>{
|
|
30
|
+
const values = {};
|
|
31
|
+
for (const internalKey of Object.keys(options.fetchData)){
|
|
32
|
+
if (cachedValues[internalKey]) continue;
|
|
33
|
+
values[internalKey] = client.getSecretValue({
|
|
34
|
+
SecretId: options.fetchData[internalKey]
|
|
35
|
+
}).promise().then((resp)=>(0, _util).jsonSafeParse(resp.SecretString)).catch((e)=>{
|
|
36
|
+
const value = (0, _util).getCache(options.cacheKey).value ?? {};
|
|
37
|
+
value[internalKey] = undefined;
|
|
38
|
+
(0, _util).modifyCache(options.cacheKey, value);
|
|
39
|
+
throw e;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return values;
|
|
43
|
+
};
|
|
44
|
+
let prefetch, client;
|
|
45
|
+
if ((0, _util).canPrefetch(options)) {
|
|
46
|
+
client = (0, _util).createPrefetchClient(options);
|
|
47
|
+
prefetch = (0, _util).processCache(options, fetch);
|
|
48
|
+
}
|
|
49
|
+
const secretsManagerMiddlewareBefore = async (request)=>{
|
|
50
|
+
if (!client) {
|
|
51
|
+
client = await (0, _util).createClient(options, request);
|
|
52
|
+
}
|
|
53
|
+
const { value } = prefetch ?? (0, _util).processCache(options, fetch, request);
|
|
54
|
+
Object.assign(request.internal, value);
|
|
55
|
+
if (options.setToContext) {
|
|
56
|
+
const data = await (0, _util).getInternal(Object.keys(options.fetchData), request);
|
|
57
|
+
Object.assign(request.context, data);
|
|
58
|
+
}
|
|
59
|
+
prefetch = null;
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
before: secretsManagerMiddlewareBefore
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
var _default = secretsManagerMiddleware;
|
|
66
|
+
module.exports = _default;
|
|
67
|
+
|
|
2
68
|
|
|
3
69
|
//# sourceMappingURL=index.cjs.map
|
package/index.js
CHANGED
|
@@ -1,3 +1,58 @@
|
|
|
1
|
-
import{canPrefetch,createPrefetchClient,createClient,getCache,getInternal,processCache,modifyCache,jsonSafeParse}from
|
|
1
|
+
import { canPrefetch, createPrefetchClient, createClient, getCache, getInternal, processCache, modifyCache, jsonSafeParse } from '@middy/util';
|
|
2
|
+
import SecretsManager from 'aws-sdk/clients/secretsmanager.js';
|
|
3
|
+
const defaults = {
|
|
4
|
+
AwsClient: SecretsManager,
|
|
5
|
+
awsClientOptions: {},
|
|
6
|
+
awsClientAssumeRole: undefined,
|
|
7
|
+
awsClientCapture: undefined,
|
|
8
|
+
fetchData: {},
|
|
9
|
+
disablePrefetch: false,
|
|
10
|
+
cacheKey: 'secrets-manager',
|
|
11
|
+
cacheExpiry: -1,
|
|
12
|
+
setToContext: false
|
|
13
|
+
};
|
|
14
|
+
const secretsManagerMiddleware = (opts = {})=>{
|
|
15
|
+
const options = {
|
|
16
|
+
...defaults,
|
|
17
|
+
...opts
|
|
18
|
+
};
|
|
19
|
+
const fetch = (request, cachedValues = {})=>{
|
|
20
|
+
const values = {};
|
|
21
|
+
for (const internalKey of Object.keys(options.fetchData)){
|
|
22
|
+
if (cachedValues[internalKey]) continue;
|
|
23
|
+
values[internalKey] = client.getSecretValue({
|
|
24
|
+
SecretId: options.fetchData[internalKey]
|
|
25
|
+
}).promise().then((resp)=>jsonSafeParse(resp.SecretString)).catch((e)=>{
|
|
26
|
+
const value = getCache(options.cacheKey).value ?? {};
|
|
27
|
+
value[internalKey] = undefined;
|
|
28
|
+
modifyCache(options.cacheKey, value);
|
|
29
|
+
throw e;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return values;
|
|
33
|
+
};
|
|
34
|
+
let prefetch, client;
|
|
35
|
+
if (canPrefetch(options)) {
|
|
36
|
+
client = createPrefetchClient(options);
|
|
37
|
+
prefetch = processCache(options, fetch);
|
|
38
|
+
}
|
|
39
|
+
const secretsManagerMiddlewareBefore = async (request)=>{
|
|
40
|
+
if (!client) {
|
|
41
|
+
client = await createClient(options, request);
|
|
42
|
+
}
|
|
43
|
+
const { value } = prefetch ?? processCache(options, fetch, request);
|
|
44
|
+
Object.assign(request.internal, value);
|
|
45
|
+
if (options.setToContext) {
|
|
46
|
+
const data = await getInternal(Object.keys(options.fetchData), request);
|
|
47
|
+
Object.assign(request.context, data);
|
|
48
|
+
}
|
|
49
|
+
prefetch = null;
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
before: secretsManagerMiddlewareBefore
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export default secretsManagerMiddleware;
|
|
56
|
+
|
|
2
57
|
|
|
3
58
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/secrets-manager",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.1.0-rc.1",
|
|
4
4
|
"description": "Secrets Manager middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -10,11 +10,17 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
+
"main": "./index.cjs",
|
|
13
14
|
"exports": {
|
|
14
15
|
".": {
|
|
15
|
-
"import":
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"default": "./index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"types": "./index.d.ts",
|
|
22
|
+
"default": "./index.cjs"
|
|
23
|
+
}
|
|
18
24
|
}
|
|
19
25
|
},
|
|
20
26
|
"types": "index.d.ts",
|
|
@@ -53,12 +59,12 @@
|
|
|
53
59
|
},
|
|
54
60
|
"homepage": "https://middy.js.org",
|
|
55
61
|
"dependencies": {
|
|
56
|
-
"@middy/util": "3.0.
|
|
62
|
+
"@middy/util": "3.1.0-rc.1"
|
|
57
63
|
},
|
|
58
64
|
"devDependencies": {
|
|
59
|
-
"@middy/core": "3.0.
|
|
65
|
+
"@middy/core": "3.1.0-rc.1",
|
|
60
66
|
"aws-sdk": "^2.939.0",
|
|
61
67
|
"aws-xray-sdk": "^3.3.3"
|
|
62
68
|
},
|
|
63
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "044c397e7a2b1de516b4b5c21ece2baffdbfa771"
|
|
64
70
|
}
|