@middy/rds-signer 5.0.3 → 5.2.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/index.js +71 -57
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -1,60 +1,74 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
canPrefetch,
|
|
3
|
+
getInternal,
|
|
4
|
+
processCache,
|
|
5
|
+
getCache,
|
|
6
|
+
modifyCache
|
|
7
|
+
} from '@middy/util'
|
|
8
|
+
import { Signer } from '@aws-sdk/rds-signer'
|
|
9
|
+
|
|
3
10
|
const defaults = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
11
|
+
AwsClient: Signer,
|
|
12
|
+
awsClientOptions: {},
|
|
13
|
+
fetchData: {},
|
|
14
|
+
disablePrefetch: false,
|
|
15
|
+
cacheKey: 'rds-signer',
|
|
16
|
+
cacheKeyExpiry: {},
|
|
17
|
+
cacheExpiry: -1,
|
|
18
|
+
setToContext: false
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const rdsSignerMiddleware = (opts = {}) => {
|
|
22
|
+
const options = { ...defaults, ...opts }
|
|
23
|
+
|
|
24
|
+
const fetch = (request, cachedValues = {}) => {
|
|
25
|
+
const values = {}
|
|
26
|
+
for (const internalKey of Object.keys(options.fetchData)) {
|
|
27
|
+
if (cachedValues[internalKey]) continue
|
|
28
|
+
|
|
29
|
+
const client = new options.AwsClient({
|
|
30
|
+
...options.awsClientOptions,
|
|
31
|
+
...options.fetchData[internalKey]
|
|
32
|
+
})
|
|
33
|
+
values[internalKey] = client
|
|
34
|
+
.getAuthToken()
|
|
35
|
+
.then((token) => {
|
|
36
|
+
// Catch Missing token, this usually means their is something wrong with the credentials
|
|
37
|
+
if (!token.includes('X-Amz-Security-Token=')) {
|
|
38
|
+
throw new Error('X-Amz-Security-Token Missing', {
|
|
39
|
+
cause: { package: '@middy/rds-signer' }
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
return token
|
|
43
|
+
})
|
|
44
|
+
.catch((e) => {
|
|
45
|
+
const value = getCache(options.cacheKey).value ?? {}
|
|
46
|
+
value[internalKey] = undefined
|
|
47
|
+
modifyCache(options.cacheKey, value)
|
|
48
|
+
throw e
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return values
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (canPrefetch(options)) {
|
|
56
|
+
processCache(options, fetch)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const rdsSignerMiddlewareBefore = async (request) => {
|
|
60
|
+
const { value } = processCache(options, fetch, request)
|
|
61
|
+
|
|
62
|
+
Object.assign(request.internal, value)
|
|
63
|
+
|
|
64
|
+
if (options.setToContext) {
|
|
65
|
+
const data = await getInternal(Object.keys(options.fetchData), request)
|
|
66
|
+
Object.assign(request.context, data)
|
|
46
67
|
}
|
|
47
|
-
|
|
48
|
-
const { value } = processCache(options, fetch, request);
|
|
49
|
-
Object.assign(request.internal, value);
|
|
50
|
-
if (options.setToContext) {
|
|
51
|
-
const data = await getInternal(Object.keys(options.fetchData), request);
|
|
52
|
-
Object.assign(request.context, data);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
return {
|
|
56
|
-
before: rdsSignerMiddlewareBefore
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
export default rdsSignerMiddleware;
|
|
68
|
+
}
|
|
60
69
|
|
|
70
|
+
return {
|
|
71
|
+
before: rdsSignerMiddlewareBefore
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export default rdsSignerMiddleware
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/rds-signer",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "RDS (Relational Database Service) credentials middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -60,14 +60,14 @@
|
|
|
60
60
|
"url": "https://github.com/sponsors/willfarrell"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@middy/util": "5.0
|
|
63
|
+
"@middy/util": "5.2.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@aws-sdk/rds-signer": "^3.0.0",
|
|
67
|
-
"@middy/core": "5.0
|
|
67
|
+
"@middy/core": "5.2.0",
|
|
68
68
|
"@types/aws-lambda": "^8.10.101",
|
|
69
69
|
"@types/node": "^20.0.0",
|
|
70
70
|
"aws-xray-sdk": "^3.3.3"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "2d9096a49cd8fb62359517be96d6c93609df41f0"
|
|
73
73
|
}
|