@middy/rds-signer 5.0.0-alpha.0 → 5.0.0-alpha.2
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 +3 -2
- package/index.d.ts +27 -3
- package/index.js +9 -5
- package/package.json +6 -11
- package/index.cjs +0 -65
package/README.md
CHANGED
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
<a href="https://snyk.io/test/github/middyjs/middy">
|
|
20
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%;">
|
|
21
21
|
</a>
|
|
22
|
-
<a href="https://
|
|
23
|
-
<img src="https://
|
|
22
|
+
<a href="https://github.com/middyjs/middy/actions/workflows/sast.yml">
|
|
23
|
+
<img src="https://github.com/middyjs/middy/actions/workflows/sast.yml/badge.svg
|
|
24
|
+
?branch=main&event=push" alt="CodeQL" style="max-width:100%;">
|
|
24
25
|
</a>
|
|
25
26
|
<a href="https://bestpractices.coreinfrastructure.org/projects/5280">
|
|
26
27
|
<img src="https://bestpractices.coreinfrastructure.org/projects/5280/badge" alt="Core Infrastructure Initiative (CII) Best Practices" style="max-width:100%;">
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
import middy from '@middy/core'
|
|
2
2
|
import { Options as MiddyOptions } from '@middy/util'
|
|
3
|
+
import { Context as LambdaContext } from 'aws-lambda'
|
|
3
4
|
import { SignerConfig, Signer } from '@aws-sdk/rds-signer'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
export type RdsSignerOptions<AwsSigner = Signer> = Omit<MiddyOptions<AwsSigner, SignerConfig>, 'fetchData'> & {
|
|
7
|
+
fetchData?: {
|
|
8
|
+
[key: string]: SignerConfig
|
|
9
|
+
}
|
|
10
|
+
}
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
export type Context<TOptions extends RdsSignerOptions | undefined> =
|
|
13
|
+
TOptions extends { setToContext: true }
|
|
14
|
+
? TOptions extends { fetchData: infer TFetchData }
|
|
15
|
+
? LambdaContext & {
|
|
16
|
+
[Key in keyof TFetchData]: string
|
|
17
|
+
}
|
|
18
|
+
: LambdaContext
|
|
19
|
+
: LambdaContext
|
|
20
|
+
|
|
21
|
+
export type Internal<TOptions extends RdsSignerOptions | undefined> =
|
|
22
|
+
TOptions extends RdsSignerOptions
|
|
23
|
+
? TOptions extends { fetchData: infer TFetchData }
|
|
24
|
+
? {
|
|
25
|
+
[Key in keyof TFetchData]: string
|
|
26
|
+
}
|
|
27
|
+
: {}
|
|
28
|
+
: {}
|
|
29
|
+
|
|
30
|
+
declare function rdsSigner<TOptions extends RdsSignerOptions | undefined> (
|
|
31
|
+
options?: TOptions
|
|
32
|
+
): middy.MiddlewareObj<unknown, any, Error, Context<TOptions>, Internal<TOptions>>
|
|
9
33
|
|
|
10
34
|
export default rdsSigner
|
package/index.js
CHANGED
|
@@ -6,6 +6,7 @@ const defaults = {
|
|
|
6
6
|
fetchData: {},
|
|
7
7
|
disablePrefetch: false,
|
|
8
8
|
cacheKey: 'rds-signer',
|
|
9
|
+
cacheKeyExpiry: {},
|
|
9
10
|
cacheExpiry: -1,
|
|
10
11
|
setToContext: false
|
|
11
12
|
};
|
|
@@ -23,8 +24,13 @@ const rdsSignerMiddleware = (opts = {})=>{
|
|
|
23
24
|
...options.fetchData[internalKey]
|
|
24
25
|
});
|
|
25
26
|
values[internalKey] = client.getAuthToken().then((token)=>{
|
|
27
|
+
// Catch Missing token, this usually means their is something wrong with the credentials
|
|
26
28
|
if (!token.includes('X-Amz-Security-Token=')) {
|
|
27
|
-
throw new Error('
|
|
29
|
+
throw new Error('X-Amz-Security-Token Missing', {
|
|
30
|
+
cause: {
|
|
31
|
+
package: '@middy/rds-signer'
|
|
32
|
+
}
|
|
33
|
+
});
|
|
28
34
|
}
|
|
29
35
|
return token;
|
|
30
36
|
}).catch((e)=>{
|
|
@@ -36,18 +42,16 @@ const rdsSignerMiddleware = (opts = {})=>{
|
|
|
36
42
|
}
|
|
37
43
|
return values;
|
|
38
44
|
};
|
|
39
|
-
let prefetch;
|
|
40
45
|
if (canPrefetch(options)) {
|
|
41
|
-
|
|
46
|
+
processCache(options, fetch);
|
|
42
47
|
}
|
|
43
48
|
const rdsSignerMiddlewareBefore = async (request)=>{
|
|
44
|
-
const { value
|
|
49
|
+
const { value } = processCache(options, fetch, request);
|
|
45
50
|
Object.assign(request.internal, value);
|
|
46
51
|
if (options.setToContext) {
|
|
47
52
|
const data = await getInternal(Object.keys(options.fetchData), request);
|
|
48
53
|
Object.assign(request.context, data);
|
|
49
54
|
}
|
|
50
|
-
prefetch = null;
|
|
51
55
|
};
|
|
52
56
|
return {
|
|
53
57
|
before: rdsSignerMiddlewareBefore
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/rds-signer",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.2",
|
|
4
4
|
"description": "RDS (Relational Database Service) credentials middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -10,24 +10,18 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"main": "./index.cjs",
|
|
14
13
|
"module": "./index.js",
|
|
15
14
|
"exports": {
|
|
16
15
|
".": {
|
|
17
16
|
"import": {
|
|
18
17
|
"types": "./index.d.ts",
|
|
19
18
|
"default": "./index.js"
|
|
20
|
-
},
|
|
21
|
-
"require": {
|
|
22
|
-
"types": "./index.d.ts",
|
|
23
|
-
"default": "./index.cjs"
|
|
24
19
|
}
|
|
25
20
|
}
|
|
26
21
|
},
|
|
27
22
|
"types": "index.d.ts",
|
|
28
23
|
"files": [
|
|
29
24
|
"index.js",
|
|
30
|
-
"index.cjs",
|
|
31
25
|
"index.d.ts"
|
|
32
26
|
],
|
|
33
27
|
"scripts": {
|
|
@@ -66,13 +60,14 @@
|
|
|
66
60
|
"url": "https://github.com/sponsors/willfarrell"
|
|
67
61
|
},
|
|
68
62
|
"dependencies": {
|
|
69
|
-
"@middy/util": "5.0.0-alpha.
|
|
63
|
+
"@middy/util": "5.0.0-alpha.2"
|
|
70
64
|
},
|
|
71
65
|
"devDependencies": {
|
|
72
66
|
"@aws-sdk/rds-signer": "^3.0.0",
|
|
73
|
-
"@middy/core": "5.0.0-alpha.
|
|
74
|
-
"@types/
|
|
67
|
+
"@middy/core": "5.0.0-alpha.2",
|
|
68
|
+
"@types/aws-lambda": "^8.10.101",
|
|
69
|
+
"@types/node": "^20.0.0",
|
|
75
70
|
"aws-xray-sdk": "^3.3.3"
|
|
76
71
|
},
|
|
77
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "ebce8d5df8783077fa49ba62ee9be20e8486a7f1"
|
|
78
73
|
}
|
package/index.cjs
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(module, "exports", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>_default
|
|
8
|
-
});
|
|
9
|
-
const _util = require("@middy/util");
|
|
10
|
-
const _rdsSigner = require("@aws-sdk/rds-signer");
|
|
11
|
-
const defaults = {
|
|
12
|
-
AwsClient: _rdsSigner.Signer,
|
|
13
|
-
awsClientOptions: {},
|
|
14
|
-
fetchData: {},
|
|
15
|
-
disablePrefetch: false,
|
|
16
|
-
cacheKey: 'rds-signer',
|
|
17
|
-
cacheExpiry: -1,
|
|
18
|
-
setToContext: false
|
|
19
|
-
};
|
|
20
|
-
const rdsSignerMiddleware = (opts = {})=>{
|
|
21
|
-
const options = {
|
|
22
|
-
...defaults,
|
|
23
|
-
...opts
|
|
24
|
-
};
|
|
25
|
-
const fetch = (request, cachedValues = {})=>{
|
|
26
|
-
const values = {};
|
|
27
|
-
for (const internalKey of Object.keys(options.fetchData)){
|
|
28
|
-
if (cachedValues[internalKey]) continue;
|
|
29
|
-
const client = new options.AwsClient({
|
|
30
|
-
...options.awsClientOptions,
|
|
31
|
-
...options.fetchData[internalKey]
|
|
32
|
-
});
|
|
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;
|
|
38
|
-
}).catch((e)=>{
|
|
39
|
-
const value = (0, _util.getCache)(options.cacheKey).value ?? {};
|
|
40
|
-
value[internalKey] = undefined;
|
|
41
|
-
(0, _util.modifyCache)(options.cacheKey, value);
|
|
42
|
-
throw e;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return values;
|
|
46
|
-
};
|
|
47
|
-
let prefetch;
|
|
48
|
-
if ((0, _util.canPrefetch)(options)) {
|
|
49
|
-
prefetch = (0, _util.processCache)(options, fetch);
|
|
50
|
-
}
|
|
51
|
-
const rdsSignerMiddlewareBefore = async (request)=>{
|
|
52
|
-
const { value } = prefetch ?? (0, _util.processCache)(options, fetch, request);
|
|
53
|
-
Object.assign(request.internal, value);
|
|
54
|
-
if (options.setToContext) {
|
|
55
|
-
const data = await (0, _util.getInternal)(Object.keys(options.fetchData), request);
|
|
56
|
-
Object.assign(request.context, data);
|
|
57
|
-
}
|
|
58
|
-
prefetch = null;
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
before: rdsSignerMiddlewareBefore
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
const _default = rdsSignerMiddleware;
|
|
65
|
-
|