@middy/rds-signer 3.0.0-alpha.3 → 3.0.0-alpha.7
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 +24 -14
- package/index.js +2 -79
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
# Middy rds-signer middleware
|
|
2
|
-
|
|
3
|
-
<div align="center">
|
|
4
|
-
<img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.png"/>
|
|
5
|
-
</div>
|
|
6
|
-
|
|
7
1
|
<div align="center">
|
|
2
|
+
<h1>Middy rds-signer middleware</h1>
|
|
3
|
+
<img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.svg"/>
|
|
8
4
|
<p><strong>RDS Signer middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda</strong></p>
|
|
9
|
-
</div>
|
|
10
|
-
|
|
11
|
-
<div align="center">
|
|
12
5
|
<p>
|
|
13
|
-
<a href="
|
|
6
|
+
<a href="https://www.npmjs.com/package/@middy/rds-signer?activeTab=versions">
|
|
14
7
|
<img src="https://badge.fury.io/js/%40middy%2Frds-signer.svg" alt="npm version" style="max-width:100%;">
|
|
15
8
|
</a>
|
|
9
|
+
<a href="https://packagephobia.com/result?p=@middy/rds-signer">
|
|
10
|
+
<img src="https://packagephobia.com/badge?p=@middy/rds-signer" alt="npm install size" style="max-width:100%;">
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://github.com/middyjs/middy/actions">
|
|
13
|
+
<img src="https://github.com/middyjs/middy/workflows/Tests/badge.svg" alt="GitHub Actions test status badge" style="max-width:100%;">
|
|
14
|
+
</a>
|
|
15
|
+
<br/>
|
|
16
|
+
<a href="https://standardjs.com/">
|
|
17
|
+
<img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="Standard Code Style" style="max-width:100%;">
|
|
18
|
+
</a>
|
|
16
19
|
<a href="https://snyk.io/test/github/middyjs/middy">
|
|
17
20
|
<img src="https://snyk.io/test/github/middyjs/middy/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/middyjs/middy" style="max-width:100%;">
|
|
18
21
|
</a>
|
|
19
|
-
<a href="https://
|
|
20
|
-
<img src="https://img.shields.io/
|
|
22
|
+
<a href="https://lgtm.com/projects/g/middyjs/middy/context:javascript">
|
|
23
|
+
<img src="https://img.shields.io/lgtm/grade/javascript/g/middyjs/middy.svg?logo=lgtm&logoWidth=18" alt="Language grade: JavaScript" style="max-width:100%;">
|
|
24
|
+
</a>
|
|
25
|
+
<a href="https://bestpractices.coreinfrastructure.org/projects/5280">
|
|
26
|
+
<img src="https://bestpractices.coreinfrastructure.org/projects/5280/badge" alt="Core Infrastructure Initiative (CII) Best Practices" style="max-width:100%;">
|
|
21
27
|
</a>
|
|
28
|
+
<br/>
|
|
22
29
|
<a href="https://gitter.im/middyjs/Lobby">
|
|
23
|
-
<img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter"
|
|
30
|
+
<img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter" style="max-width:100%;">
|
|
31
|
+
</a>
|
|
32
|
+
<a href="https://stackoverflow.com/questions/tagged/middy?sort=Newest&uqlId=35052">
|
|
33
|
+
<img src="https://img.shields.io/badge/StackOverflow-[middy]-yellow" alt="Ask questions on StackOverflow" style="max-width:100%;">
|
|
24
34
|
</a>
|
|
25
35
|
</p>
|
|
26
36
|
</div>
|
|
@@ -39,7 +49,7 @@ npm install --save @middy/rds-signer
|
|
|
39
49
|
## Options
|
|
40
50
|
|
|
41
51
|
- `AwsClient` (object) (default `AWS.RDS.Signer`): AWS.RDS.Signer class constructor (e.g. that has been instrumented with AWS XRay). Must be from `aws-sdk` v2.
|
|
42
|
-
- `awsClientOptions` (object) (
|
|
52
|
+
- `awsClientOptions` (object) (default `undefined`): Options to pass to AWS.RDS.Signer class constructor.
|
|
43
53
|
- `fetchData` (object) (required): Mapping of internal key name to API request parameters.
|
|
44
54
|
- `disablePrefetch` (boolean) (default `false`): On cold start requests will trigger early if they can. Setting `awsClientAssumeRole` disables prefetch.
|
|
45
55
|
- `cacheKey` (string) (default `rds-signer`): Cache key for the fetched data responses. Must be unique across all middleware.
|
package/index.js
CHANGED
|
@@ -1,80 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
canPrefetch,
|
|
3
|
-
getInternal,
|
|
4
|
-
processCache,
|
|
5
|
-
getCache,
|
|
6
|
-
modifyCache
|
|
7
|
-
} from '@middy/util'
|
|
8
|
-
import RDS from 'aws-sdk/clients/rds.js' // v2
|
|
9
|
-
// import { RDS:{Signer} } from '@aws-sdk/client-rds' // v3
|
|
1
|
+
import{canPrefetch,getInternal,processCache,getCache,modifyCache}from'@middy/util';import RDS from'aws-sdk/clients/rds.js';const defaults={AwsClient:RDS.Signer,awsClientOptions:{},fetchData:{},disablePrefetch:false,cacheKey:'rds-signer',cacheExpiry:-1,setToContext:false};const rdsSignerMiddleware=(opts={})=>{const options={...defaults,...opts};const fetch=(request,cachedValues={})=>{const values={};for(const internalKey of Object.keys(options.fetchData)){if(cachedValues[internalKey])continue;const client=new options.AwsClient({...options.awsClientOptions,...options.fetchData[internalKey]});values[internalKey]=new Promise((resolve,reject)=>{client.getAuthToken({},(e,token)=>{if(e){reject(e)}if(!token.includes('X-Amz-Security-Token=')){reject(new Error('[rds-signer] X-Amz-Security-Token Missing'))}resolve(token)})}).catch(e=>{const value=getCache(options.cacheKey).value??{};value[internalKey]=undefined;modifyCache(options.cacheKey,value);throw e})}return values};let prefetch;if(canPrefetch(options)){prefetch=processCache(options,fetch)}const rdsSignerMiddlewareBefore=async request=>{const{value}=prefetch??processCache(options,fetch,request);Object.assign(request.internal,value);if(options.setToContext){const data=await getInternal(Object.keys(options.fetchData),request);Object.assign(request.context,data)}prefetch=null};return{before:rdsSignerMiddlewareBefore}};export default rdsSignerMiddleware
|
|
10
2
|
|
|
11
|
-
|
|
12
|
-
AwsClient: RDS.Signer,
|
|
13
|
-
awsClientOptions: {},
|
|
14
|
-
fetchData: {}, // { contextKey: {region, hostname, username, database, port} }
|
|
15
|
-
disablePrefetch: false,
|
|
16
|
-
cacheKey: 'rds-signer',
|
|
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
|
-
// AWS doesn't support getAuthToken.promise() in aws-sdk v2 :( See https://github.com/aws/aws-sdk-js/issues/3595
|
|
34
|
-
values[internalKey] = new Promise((resolve, reject) => {
|
|
35
|
-
client.getAuthToken({}, (e, token) => {
|
|
36
|
-
if (e) {
|
|
37
|
-
reject(e)
|
|
38
|
-
}
|
|
39
|
-
// Catch Missing token, this usually means their is something wrong with the credentials
|
|
40
|
-
if (!token.includes('X-Amz-Security-Token=')) {
|
|
41
|
-
reject(new Error('X-Amz-Security-Token Missing'))
|
|
42
|
-
}
|
|
43
|
-
resolve(token)
|
|
44
|
-
})
|
|
45
|
-
}).catch((e) => {
|
|
46
|
-
const value = getCache(options.cacheKey).value ?? {}
|
|
47
|
-
value[internalKey] = undefined
|
|
48
|
-
modifyCache(options.cacheKey, value)
|
|
49
|
-
throw e
|
|
50
|
-
})
|
|
51
|
-
// aws-sdk v3
|
|
52
|
-
// values[internalKey] = createClient(awsClientOptions, request).then(client => client.getAuthToken())
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return values
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
let prefetch
|
|
59
|
-
if (canPrefetch(options)) {
|
|
60
|
-
prefetch = processCache(options, fetch)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const rdsSignerMiddlewareBefore = async (request) => {
|
|
64
|
-
const { value } = prefetch ?? processCache(options, fetch, request)
|
|
65
|
-
|
|
66
|
-
Object.assign(request.internal, value)
|
|
67
|
-
|
|
68
|
-
if (options.setToContext) {
|
|
69
|
-
const data = await getInternal(Object.keys(options.fetchData), request)
|
|
70
|
-
Object.assign(request.context, data)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
prefetch = null
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
before: rdsSignerMiddlewareBefore
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
export default rdsSignerMiddleware
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/rds-signer",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.7",
|
|
4
4
|
"description": "RDS (Relational Database Service) credentials middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -48,13 +48,13 @@
|
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://github.com/middyjs/middy#readme",
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@middy/util": "^3.0.0-alpha.
|
|
51
|
+
"@middy/util": "^3.0.0-alpha.7"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@middy/core": "^3.0.0-alpha.
|
|
54
|
+
"@middy/core": "^3.0.0-alpha.7",
|
|
55
55
|
"@types/node": "^17.0.0",
|
|
56
56
|
"aws-sdk": "^2.939.0",
|
|
57
57
|
"aws-xray-sdk": "^3.3.3"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "5cef39ebe49c201f97d71bb0680004de4b82cb91"
|
|
60
60
|
}
|