@middy/rds-signer 7.3.3 → 7.4.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 +23 -6
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -10,12 +10,15 @@ import {
|
|
|
10
10
|
validateOptions,
|
|
11
11
|
} from "@middy/util";
|
|
12
12
|
|
|
13
|
+
const name = "rds-signer";
|
|
14
|
+
const pkg = `@middy/${name}`;
|
|
15
|
+
|
|
13
16
|
const defaults = {
|
|
14
17
|
AwsClient: Signer,
|
|
15
18
|
awsClientOptions: {},
|
|
16
19
|
fetchData: {},
|
|
17
20
|
disablePrefetch: false,
|
|
18
|
-
cacheKey:
|
|
21
|
+
cacheKey: pkg,
|
|
19
22
|
cacheKeyExpiry: {},
|
|
20
23
|
cacheExpiry: -1,
|
|
21
24
|
setToContext: false,
|
|
@@ -35,7 +38,7 @@ const optionSchema = {
|
|
|
35
38
|
port: { type: "integer", minimum: 1, maximum: 65535 },
|
|
36
39
|
username: { type: "string" },
|
|
37
40
|
},
|
|
38
|
-
required: [
|
|
41
|
+
required: [],
|
|
39
42
|
additionalProperties: true,
|
|
40
43
|
},
|
|
41
44
|
},
|
|
@@ -52,11 +55,23 @@ const optionSchema = {
|
|
|
52
55
|
};
|
|
53
56
|
|
|
54
57
|
export const rdsSignerValidateOptions = (options) =>
|
|
55
|
-
validateOptions(
|
|
58
|
+
validateOptions(pkg, optionSchema, options);
|
|
56
59
|
|
|
57
60
|
const rdsSignerMiddleware = (opts = {}) => {
|
|
58
61
|
const options = { ...defaults, ...opts };
|
|
59
62
|
|
|
63
|
+
const defaultFetchData = {
|
|
64
|
+
hostname: process.env.PGHOST ?? process.env.DBHOST,
|
|
65
|
+
port: Number.parseInt(
|
|
66
|
+
process.env.PGPORT ?? process.env.DBPORT ?? "5432",
|
|
67
|
+
10,
|
|
68
|
+
),
|
|
69
|
+
username: process.env.PGUSER ?? process.env.DBUSER,
|
|
70
|
+
};
|
|
71
|
+
for (const key of Object.keys(options.fetchData)) {
|
|
72
|
+
options.fetchData[key] = { ...defaultFetchData, ...options.fetchData[key] };
|
|
73
|
+
}
|
|
74
|
+
|
|
60
75
|
const fetchDataKeys = Object.keys(options.fetchData);
|
|
61
76
|
const clients = {};
|
|
62
77
|
const fetchRequest = (request, cachedValues = {}) => {
|
|
@@ -64,17 +79,19 @@ const rdsSignerMiddleware = (opts = {}) => {
|
|
|
64
79
|
for (const internalKey of fetchDataKeys) {
|
|
65
80
|
if (cachedValues[internalKey]) continue;
|
|
66
81
|
|
|
82
|
+
const signerConfig = options.fetchData[internalKey];
|
|
67
83
|
clients[internalKey] ??= new options.AwsClient({
|
|
68
84
|
...options.awsClientOptions,
|
|
69
|
-
...
|
|
85
|
+
...signerConfig,
|
|
70
86
|
});
|
|
87
|
+
const method = "getAuthToken";
|
|
71
88
|
values[internalKey] = clients[internalKey]
|
|
72
|
-
|
|
89
|
+
[method]()
|
|
73
90
|
.then((token) => {
|
|
74
91
|
// Catch Missing token, this usually means there is something wrong with the credentials
|
|
75
92
|
if (!token.includes("X-Amz-Security-Token=")) {
|
|
76
93
|
throw new Error("X-Amz-Security-Token Missing", {
|
|
77
|
-
cause: { package:
|
|
94
|
+
cause: { package: pkg, method },
|
|
78
95
|
});
|
|
79
96
|
}
|
|
80
97
|
return token;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/rds-signer",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.0",
|
|
4
4
|
"description": "RDS (Relational Database Service) credentials middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@middy/util": "7.
|
|
73
|
+
"@middy/util": "7.4.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@aws-sdk/rds-signer": "^3.0.0",
|
|
77
|
-
"@middy/core": "7.
|
|
77
|
+
"@middy/core": "7.4.0",
|
|
78
78
|
"@types/aws-lambda": "^8.0.0",
|
|
79
79
|
"@types/node": "^22.0.0",
|
|
80
80
|
"aws-xray-sdk": "^3.3.3"
|