@middy/sts 3.0.0-alpha.5 → 3.0.0-alpha.8
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 +25 -15
- package/index.cjs +3 -0
- package/index.js +2 -70
- package/package.json +13 -6
package/README.md
CHANGED
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
# Middy sts 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 sts middleware</h1>
|
|
3
|
+
<img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.svg"/>
|
|
8
4
|
<p><strong>STS 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/sts?activeTab=versions">
|
|
14
7
|
<img src="https://badge.fury.io/js/%40middy%2Fsts.svg" alt="npm version" style="max-width:100%;">
|
|
15
8
|
</a>
|
|
9
|
+
<a href="https://packagephobia.com/result?p=@middy/sts">
|
|
10
|
+
<img src="https://packagephobia.com/badge?p=@middy/sts" 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,8 +49,8 @@ npm install --save @middy/sts
|
|
|
39
49
|
## Options
|
|
40
50
|
|
|
41
51
|
- `AwsClient` (object) (default `AWS.STS`): AWS.STS class constructor (e.g. that has been instrumented with AWS XRay). Must be from `aws-sdk` v2.
|
|
42
|
-
- `awsClientOptions` (object) (
|
|
43
|
-
- `awsClientCapture` (function) (
|
|
52
|
+
- `awsClientOptions` (object) (default `undefined`): Options to pass to AWS.STS class constructor.
|
|
53
|
+
- `awsClientCapture` (function) (default `undefined`): Enable XRay by passing `captureAWSClient` from `aws-xray-sdk` in.
|
|
44
54
|
- `fetchData` (object) (required): Mapping of internal key name to API request parameters.
|
|
45
55
|
- `disablePrefetch` (boolean) (default `false`): On cold start requests will trigger early if they can. Setting `awsClientAssumeRole` disables prefetch.
|
|
46
56
|
- `cacheKey` (string) (default `sts`): Cache key for the fetched data responses. Must be unique across all middleware.
|
package/index.cjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _util=require("@middy/util");var _stsJs=_interopRequireDefault(require("aws-sdk/clients/sts.js"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}var _assumeRoleOptions;const defaults={AwsClient:_stsJs.default,awsClientOptions:{},awsClientCapture:undefined,fetchData:{},disablePrefetch:false,cacheKey:"sts",cacheExpiry:-1,setToContext:false};const stsMiddleware=(opts={})=>{const options={...defaults,...opts};const fetch=(request,cachedValues={})=>{const values={};for(const internalKey of Object.keys(options.fetchData)){if(cachedValues[internalKey])continue;const assumeRoleOptions=options.fetchData[internalKey];(_assumeRoleOptions=assumeRoleOptions).RoleSessionName??(_assumeRoleOptions.RoleSessionName="middy-sts-session-"+Math.ceil(Math.random()*99999));values[internalKey]=client.assumeRole(assumeRoleOptions).promise().then(resp=>({accessKeyId:resp.Credentials.AccessKeyId,secretAccessKey:resp.Credentials.SecretAccessKey,sessionToken:resp.Credentials.SessionToken})).catch(e=>{const value=(0,_util).getCache(options.cacheKey).value??{};value[internalKey]=undefined;(0,_util).modifyCache(options.cacheKey,value);throw e})}return values};let prefetch,client;if((0,_util).canPrefetch(options)){client=(0,_util).createPrefetchClient(options);prefetch=(0,_util).processCache(options,fetch)}const stsMiddlewareBefore=async request=>{if(!client){client=await (0,_util).createClient(options,request)}const{value}=prefetch??(0,_util).processCache(options,fetch,request);Object.assign(request.internal,value);if(options.setToContext){const data=await (0,_util).getInternal(Object.keys(options.fetchData),request);if(options.setToContext)Object.assign(request.context,data)}prefetch=null};return{before:stsMiddlewareBefore}};var _default=stsMiddleware;exports.default=_default
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=index.cjs.map
|
package/index.js
CHANGED
|
@@ -1,71 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import STS from 'aws-sdk/clients/sts.js';
|
|
3
|
-
const defaults = {
|
|
4
|
-
AwsClient: STS,
|
|
5
|
-
awsClientOptions: {},
|
|
6
|
-
awsClientCapture: undefined,
|
|
7
|
-
fetchData: {},
|
|
8
|
-
disablePrefetch: false,
|
|
9
|
-
cacheKey: 'sts',
|
|
10
|
-
cacheExpiry: -1,
|
|
11
|
-
setToContext: false
|
|
12
|
-
};
|
|
1
|
+
var _assumeRoleOptions;import{canPrefetch,createPrefetchClient,createClient,getCache,getInternal,processCache,modifyCache}from"@middy/util";import STS from"aws-sdk/clients/sts.js";const defaults={AwsClient:STS,awsClientOptions:{},awsClientCapture:undefined,fetchData:{},disablePrefetch:false,cacheKey:"sts",cacheExpiry:-1,setToContext:false};const stsMiddleware=(opts={})=>{const options={...defaults,...opts};const fetch=(request,cachedValues={})=>{const values={};for(const internalKey of Object.keys(options.fetchData)){if(cachedValues[internalKey])continue;const assumeRoleOptions=options.fetchData[internalKey];(_assumeRoleOptions=assumeRoleOptions).RoleSessionName??(_assumeRoleOptions.RoleSessionName="middy-sts-session-"+Math.ceil(Math.random()*99999));values[internalKey]=client.assumeRole(assumeRoleOptions).promise().then(resp=>({accessKeyId:resp.Credentials.AccessKeyId,secretAccessKey:resp.Credentials.SecretAccessKey,sessionToken:resp.Credentials.SessionToken})).catch(e=>{const value=getCache(options.cacheKey).value??{};value[internalKey]=undefined;modifyCache(options.cacheKey,value);throw e})}return values};let prefetch,client;if(canPrefetch(options)){client=createPrefetchClient(options);prefetch=processCache(options,fetch)}const stsMiddlewareBefore=async request=>{if(!client){client=await createClient(options,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);if(options.setToContext)Object.assign(request.context,data)}prefetch=null};return{before:stsMiddlewareBefore}};export default stsMiddleware
|
|
13
2
|
|
|
14
|
-
|
|
15
|
-
const options = { ...defaults,
|
|
16
|
-
...opts
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const fetch = (request, cachedValues = {}) => {
|
|
20
|
-
const values = {};
|
|
21
|
-
|
|
22
|
-
for (const internalKey of Object.keys(options.fetchData)) {
|
|
23
|
-
if (cachedValues[internalKey]) continue;
|
|
24
|
-
const assumeRoleOptions = options.fetchData[internalKey];
|
|
25
|
-
assumeRoleOptions.RoleSessionName ?? (assumeRoleOptions.RoleSessionName = 'middy-sts-session-' + Math.ceil(Math.random() * 99999));
|
|
26
|
-
values[internalKey] = client.assumeRole(assumeRoleOptions).promise().then(resp => ({
|
|
27
|
-
accessKeyId: resp.Credentials.AccessKeyId,
|
|
28
|
-
secretAccessKey: resp.Credentials.SecretAccessKey,
|
|
29
|
-
sessionToken: resp.Credentials.SessionToken
|
|
30
|
-
})).catch(e => {
|
|
31
|
-
const value = getCache(options.cacheKey).value ?? {};
|
|
32
|
-
value[internalKey] = undefined;
|
|
33
|
-
modifyCache(options.cacheKey, value);
|
|
34
|
-
throw e;
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return values;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
let prefetch, client;
|
|
42
|
-
|
|
43
|
-
if (canPrefetch(options)) {
|
|
44
|
-
client = createPrefetchClient(options);
|
|
45
|
-
prefetch = processCache(options, fetch);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const stsMiddlewareBefore = async request => {
|
|
49
|
-
if (!client) {
|
|
50
|
-
client = await createClient(options, request);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const {
|
|
54
|
-
value
|
|
55
|
-
} = prefetch ?? processCache(options, fetch, request);
|
|
56
|
-
Object.assign(request.internal, value);
|
|
57
|
-
|
|
58
|
-
if (options.setToContext) {
|
|
59
|
-
const data = await getInternal(Object.keys(options.fetchData), request);
|
|
60
|
-
if (options.setToContext) Object.assign(request.context, data);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
prefetch = null;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
before: stsMiddlewareBefore
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export default stsMiddleware;
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/sts",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.8",
|
|
4
4
|
"description": "STS (Security Token Service) credentials middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -10,10 +10,17 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"exports":
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": "./index.js",
|
|
16
|
+
"require": "./index.cjs",
|
|
17
|
+
"types": "./index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
14
20
|
"types": "index.d.ts",
|
|
15
21
|
"files": [
|
|
16
22
|
"index.js",
|
|
23
|
+
"index.cjs",
|
|
17
24
|
"index.d.ts"
|
|
18
25
|
],
|
|
19
26
|
"scripts": {
|
|
@@ -46,14 +53,14 @@
|
|
|
46
53
|
"bugs": {
|
|
47
54
|
"url": "https://github.com/middyjs/middy/issues"
|
|
48
55
|
},
|
|
49
|
-
"homepage": "https://
|
|
56
|
+
"homepage": "https://middy.js.org",
|
|
50
57
|
"dependencies": {
|
|
51
|
-
"@middy/util": "^3.0.0-alpha.
|
|
58
|
+
"@middy/util": "^3.0.0-alpha.8"
|
|
52
59
|
},
|
|
53
60
|
"devDependencies": {
|
|
54
|
-
"@middy/core": "^3.0.0-alpha.
|
|
61
|
+
"@middy/core": "^3.0.0-alpha.8",
|
|
55
62
|
"aws-sdk": "^2.939.0",
|
|
56
63
|
"aws-xray-sdk": "^3.3.3"
|
|
57
64
|
},
|
|
58
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "c04b3a0c2f326906b34973878d6f823778a5ea99"
|
|
59
66
|
}
|