@middy/rds-signer 3.0.0-alpha.3 → 3.0.0-alpha.4

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.
Files changed (2) hide show
  1. package/index.js +42 -48
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -1,80 +1,74 @@
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
10
-
1
+ import { canPrefetch, getInternal, processCache, getCache, modifyCache } from '@middy/util';
2
+ import RDS from 'aws-sdk/clients/rds.js';
11
3
  const defaults = {
12
4
  AwsClient: RDS.Signer,
13
5
  awsClientOptions: {},
14
- fetchData: {}, // { contextKey: {region, hostname, username, database, port} }
6
+ fetchData: {},
15
7
  disablePrefetch: false,
16
8
  cacheKey: 'rds-signer',
17
9
  cacheExpiry: -1,
18
10
  setToContext: false
19
- }
11
+ };
20
12
 
21
13
  const rdsSignerMiddleware = (opts = {}) => {
22
- const options = { ...defaults, ...opts }
14
+ const options = { ...defaults,
15
+ ...opts
16
+ };
23
17
 
24
18
  const fetch = (request, cachedValues = {}) => {
25
- const values = {}
26
- for (const internalKey of Object.keys(options.fetchData)) {
27
- if (cachedValues[internalKey]) continue
19
+ const values = {};
28
20
 
29
- const client = new options.AwsClient({
30
- ...options.awsClientOptions,
21
+ for (const internalKey of Object.keys(options.fetchData)) {
22
+ if (cachedValues[internalKey]) continue;
23
+ const client = new options.AwsClient({ ...options.awsClientOptions,
31
24
  ...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
25
+ });
34
26
  values[internalKey] = new Promise((resolve, reject) => {
35
27
  client.getAuthToken({}, (e, token) => {
36
28
  if (e) {
37
- reject(e)
29
+ reject(e);
38
30
  }
39
- // Catch Missing token, this usually means their is something wrong with the credentials
31
+
40
32
  if (!token.includes('X-Amz-Security-Token=')) {
41
- reject(new Error('X-Amz-Security-Token Missing'))
33
+ reject(new Error('X-Amz-Security-Token Missing'));
42
34
  }
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())
35
+
36
+ resolve(token);
37
+ });
38
+ }).catch(e => {
39
+ const value = getCache(options.cacheKey).value ?? {};
40
+ value[internalKey] = undefined;
41
+ modifyCache(options.cacheKey, value);
42
+ throw e;
43
+ });
53
44
  }
54
45
 
55
- return values
56
- }
46
+ return values;
47
+ };
48
+
49
+ let prefetch;
57
50
 
58
- let prefetch
59
51
  if (canPrefetch(options)) {
60
- prefetch = processCache(options, fetch)
52
+ prefetch = processCache(options, fetch);
61
53
  }
62
54
 
63
- const rdsSignerMiddlewareBefore = async (request) => {
64
- const { value } = prefetch ?? processCache(options, fetch, request)
65
-
66
- Object.assign(request.internal, value)
55
+ const rdsSignerMiddlewareBefore = async request => {
56
+ const {
57
+ value
58
+ } = prefetch ?? processCache(options, fetch, request);
59
+ Object.assign(request.internal, value);
67
60
 
68
61
  if (options.setToContext) {
69
- const data = await getInternal(Object.keys(options.fetchData), request)
70
- Object.assign(request.context, data)
62
+ const data = await getInternal(Object.keys(options.fetchData), request);
63
+ Object.assign(request.context, data);
71
64
  }
72
65
 
73
- prefetch = null
74
- }
66
+ prefetch = null;
67
+ };
75
68
 
76
69
  return {
77
70
  before: rdsSignerMiddlewareBefore
78
- }
79
- }
80
- export default rdsSignerMiddleware
71
+ };
72
+ };
73
+
74
+ export default rdsSignerMiddleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/rds-signer",
3
- "version": "3.0.0-alpha.3",
3
+ "version": "3.0.0-alpha.4",
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.3"
51
+ "@middy/util": "^3.0.0-alpha.4"
52
52
  },
53
53
  "devDependencies": {
54
- "@middy/core": "^3.0.0-alpha.3",
54
+ "@middy/core": "^3.0.0-alpha.4",
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": "1441158711580313765e6d156046ef0fade0d156"
59
+ "gitHead": "d4bea7f4e21f6a9bbb1f6f6908361169598b9e53"
60
60
  }