@middy/sts 2.5.4 → 3.0.0-alpha.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/LICENSE +1 -1
- package/README.md +1 -1
- package/package.json +7 -7
- package/index.js +0 -96
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2017-
|
|
3
|
+
Copyright (c) 2017-2022 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
|
|
|
91
91
|
|
|
92
92
|
## License
|
|
93
93
|
|
|
94
|
-
Licensed under [MIT License](LICENSE). Copyright (c) 2017-
|
|
94
|
+
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
|
|
95
95
|
|
|
96
96
|
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
|
|
97
97
|
<img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/sts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
4
|
"description": "STS (Security Token Service) credentials middleware for the middy framework",
|
|
5
|
-
"type": "
|
|
5
|
+
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=14"
|
|
8
8
|
},
|
|
9
9
|
"engineStrict": true,
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
13
|
+
"exports": "./index.js",
|
|
14
14
|
"types": "index.d.ts",
|
|
15
15
|
"files": [
|
|
16
16
|
"index.d.ts"
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://github.com/middyjs/middy#readme",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@middy/util": "^
|
|
49
|
+
"@middy/util": "^3.0.0-alpha.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@middy/core": "^
|
|
52
|
+
"@middy/core": "^3.0.0-alpha.0",
|
|
53
53
|
"aws-sdk": "^2.939.0",
|
|
54
54
|
"aws-xray-sdk": "^3.3.3"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "c533f62841c8a39d061d7b94f30ba178f002c8db"
|
|
57
57
|
}
|
package/index.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
canPrefetch,
|
|
5
|
-
createPrefetchClient,
|
|
6
|
-
createClient,
|
|
7
|
-
getInternal,
|
|
8
|
-
processCache,
|
|
9
|
-
getCache,
|
|
10
|
-
modifyCache
|
|
11
|
-
} = require('@middy/util');
|
|
12
|
-
|
|
13
|
-
const STS = require('aws-sdk/clients/sts'); // v2
|
|
14
|
-
// const { STS } = require('@aws-sdk/client-sts') // v3
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const defaults = {
|
|
18
|
-
AwsClient: STS,
|
|
19
|
-
awsClientOptions: {},
|
|
20
|
-
// awsClientAssumeRole: undefined, // Not Applicable, as this is the middleware that defines the roles
|
|
21
|
-
awsClientCapture: undefined,
|
|
22
|
-
fetchData: {},
|
|
23
|
-
// { contextKey: {RoleArn, RoleSessionName} }
|
|
24
|
-
disablePrefetch: false,
|
|
25
|
-
cacheKey: 'sts',
|
|
26
|
-
cacheExpiry: -1,
|
|
27
|
-
// setToEnv: false, // returns object, cannot set to process.env
|
|
28
|
-
setToContext: false
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const stsMiddleware = (opts = {}) => {
|
|
32
|
-
const options = { ...defaults,
|
|
33
|
-
...opts
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const fetch = (request, cachedValues = {}) => {
|
|
37
|
-
const values = {};
|
|
38
|
-
|
|
39
|
-
for (const internalKey of Object.keys(options.fetchData)) {
|
|
40
|
-
var _assumeRoleOptions$Ro;
|
|
41
|
-
|
|
42
|
-
if (cachedValues[internalKey]) continue;
|
|
43
|
-
const assumeRoleOptions = options.fetchData[internalKey]; // Date cannot be used here to assign default session name, possibility of collision when > 1 role defined
|
|
44
|
-
|
|
45
|
-
assumeRoleOptions.RoleSessionName = (_assumeRoleOptions$Ro = assumeRoleOptions === null || assumeRoleOptions === void 0 ? void 0 : assumeRoleOptions.RoleSessionName) !== null && _assumeRoleOptions$Ro !== void 0 ? _assumeRoleOptions$Ro : 'middy-sts-session-' + Math.ceil(Math.random() * 99999);
|
|
46
|
-
values[internalKey] = client.assumeRole(assumeRoleOptions).promise() // Required for aws-sdk v2
|
|
47
|
-
.then(resp => ({
|
|
48
|
-
accessKeyId: resp.Credentials.AccessKeyId,
|
|
49
|
-
secretAccessKey: resp.Credentials.SecretAccessKey,
|
|
50
|
-
sessionToken: resp.Credentials.SessionToken
|
|
51
|
-
})).catch(e => {
|
|
52
|
-
var _getCache$value, _getCache;
|
|
53
|
-
|
|
54
|
-
const value = (_getCache$value = (_getCache = getCache(options.cacheKey)) === null || _getCache === void 0 ? void 0 : _getCache.value) !== null && _getCache$value !== void 0 ? _getCache$value : {};
|
|
55
|
-
value[internalKey] = undefined;
|
|
56
|
-
modifyCache(options.cacheKey, value);
|
|
57
|
-
throw e;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return values;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
let prefetch, client;
|
|
65
|
-
|
|
66
|
-
if (canPrefetch(options)) {
|
|
67
|
-
client = createPrefetchClient(options);
|
|
68
|
-
prefetch = processCache(options, fetch);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const stsMiddlewareBefore = async request => {
|
|
72
|
-
var _prefetch;
|
|
73
|
-
|
|
74
|
-
if (!client) {
|
|
75
|
-
client = await createClient(options, request);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const {
|
|
79
|
-
value
|
|
80
|
-
} = (_prefetch = prefetch) !== null && _prefetch !== void 0 ? _prefetch : processCache(options, fetch, request);
|
|
81
|
-
Object.assign(request.internal, value);
|
|
82
|
-
|
|
83
|
-
if (options.setToContext) {
|
|
84
|
-
const data = await getInternal(Object.keys(options.fetchData), request);
|
|
85
|
-
if (options.setToContext) Object.assign(request.context, data);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
prefetch = null;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
before: stsMiddlewareBefore
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
module.exports = stsMiddleware;
|