@middy/ssm 2.5.6 → 3.0.0-alpha.3

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 (4) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -6
  3. package/index.js +9 -11
  4. package/package.json +10 -8
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2021 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
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
@@ -29,11 +29,11 @@ This middleware fetches parameters from [AWS Systems Manager Parameter Store](ht
29
29
 
30
30
  Parameters to fetch can be defined by path and by name (not mutually exclusive). See AWS docs [here](https://aws.amazon.com/blogs/mt/organize-parameters-by-hierarchy-tags-or-amazon-cloudwatch-events-with-amazon-ec2-systems-manager-parameter-store/).
31
31
 
32
- Parameters can be assigned to the Node.js `process.env` object by setting the `setToEnv` flag to `true`. They can also be assigned to the function handler's `context` object by setting the `setToContext` flag to `true`. By default all parameters are added with uppercase names.
32
+ Parameters can be assigned to the function handler's `context` object by setting the `setToContext` flag to `true`. By default all parameters are added with uppercase names.
33
33
 
34
34
  The Middleware makes a single API request to fetch all the parameters defined by name, but must make an additional request per specified path. This is because the AWS SDK currently doesn't expose a method to retrieve parameters from multiple paths.
35
35
 
36
- For each parameter defined by name, you also provide the name under which its value should be added to `process.env` or `context`. For each path, you instead provide a prefix, and by default the value import each parameter returned from that path will be added to `process.env` or `context` with a name equal to what's left of the parameter's full name _after_ the defined path, with the prefix prepended. If the prefix is an empty string, nothing is prepended. You can override this behaviour by providing your own mapping function with the `getParamNameFromPath` config option.
36
+ For each parameter defined by name, you also provide the name under which its value should be added to `context`. For each path, you instead provide a prefix, and by default the value import each parameter returned from that path will be added to `context` with a name equal to what's left of the parameter's full name _after_ the defined path, with the prefix prepended. If the prefix is an empty string, nothing is prepended. You can override this behaviour by providing your own mapping function with the `getParamNameFromPath` config option.
37
37
 
38
38
 
39
39
  ## Install
@@ -55,14 +55,11 @@ npm install --save @middy/ssm
55
55
  - `disablePrefetch` (boolean) (default `false`): On cold start requests will trigger early if they can. Setting `awsClientAssumeRole` disables prefetch.
56
56
  - `cacheKey` (string) (default `ssm`): Cache key for the fetched data responses. Must be unique across all middleware.
57
57
  - `cacheExpiry` (number) (default `-1`): How long fetch data responses should be cached for. `-1`: cache forever, `0`: never cache, `n`: cache for n ms.
58
- - `setToEnv` (boolean) (default `false`): Store role tokens to `process.env`. **Storing secrets in `process.env` is considered security bad practice**
59
58
  - `setToContext` (boolean) (default `false`): Store role tokens to `request.context`.
60
59
 
61
60
  NOTES:
62
61
  - Lambda is required to have IAM permission for `ssm:GetParameters` and/or `ssm:GetParametersByPath` depending on what you're requesting.
63
62
  - `SSM` has [throughput limitations](https://docs.aws.amazon.com/general/latest/gr/ssm.html). Switching to Advanced Parameter type or increasing `maxRetries` and `retryDelayOptions.base` in `awsClientOptions` may be required.
64
- - `setToEnv` and `setToContext` are included for legacy support and should be avoided for performance and security reasons. See main documentation for best practices.
65
- - `setToEnv` can only assign secrets of type string
66
63
 
67
64
  ## Sample usage
68
65
 
@@ -134,7 +131,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
134
131
 
135
132
  ## License
136
133
 
137
- Licensed under [MIT License](LICENSE). Copyright (c) 2017-2021 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
134
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
138
135
 
139
136
  <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
140
137
  <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const {
1
+ import {
2
2
  canPrefetch,
3
3
  createPrefetchClient,
4
4
  createClient,
@@ -8,9 +8,9 @@ const {
8
8
  jsonSafeParse,
9
9
  getInternal,
10
10
  sanitizeKey
11
- } = require('@middy/util')
12
- const SSM = require('aws-sdk/clients/ssm') // v2
13
- // const { SSM } = require('@aws-sdk/client-ssm') // v3
11
+ } from '@middy/util'
12
+ import SSM from 'aws-sdk/clients/ssm.js' // v2
13
+ // import { SSM } from '@aws-sdk/client-ssm' // v3
14
14
 
15
15
  const awsRequestLimit = 10
16
16
  const defaults = {
@@ -22,7 +22,6 @@ const defaults = {
22
22
  disablePrefetch: false,
23
23
  cacheKey: 'ssm',
24
24
  cacheExpiry: -1,
25
- setToEnv: false,
26
25
  setToContext: false
27
26
  }
28
27
 
@@ -68,7 +67,7 @@ const ssmMiddleware = (opts = {}) => {
68
67
  return {
69
68
  [fetchKey]: new Promise(() => {
70
69
  const internalKey = internalKeys[fetchKeys.indexOf(fetchKey)]
71
- const value = getCache(options.cacheKey)?.value ?? {}
70
+ const value = getCache(options.cacheKey).value ?? {}
72
71
  value[internalKey] = undefined
73
72
  modifyCache(options.cacheKey, value)
74
73
  throw new Error('ssm.InvalidParameter ' + fetchKey)
@@ -108,7 +107,7 @@ const ssmMiddleware = (opts = {}) => {
108
107
  const fetchKey = options.fetchData[internalKey]
109
108
  if (fetchKey.substr(-1) !== '/') continue // Skip not path passed in
110
109
  values[internalKey] = fetchPath(fetchKey).catch((e) => {
111
- const value = getCache(options.cacheKey)?.value ?? {}
110
+ const value = getCache(options.cacheKey).value ?? {}
112
111
  value[internalKey] = undefined
113
112
  modifyCache(options.cacheKey, value)
114
113
  throw e
@@ -162,10 +161,9 @@ const ssmMiddleware = (opts = {}) => {
162
161
 
163
162
  Object.assign(request.internal, value)
164
163
 
165
- if (options.setToContext || options.setToEnv) {
164
+ if (options.setToContext) {
166
165
  const data = await getInternal(Object.keys(options.fetchData), request)
167
- if (options.setToEnv) Object.assign(process.env, data)
168
- if (options.setToContext) Object.assign(request.context, data)
166
+ Object.assign(request.context, data)
169
167
  }
170
168
 
171
169
  prefetch = null
@@ -175,4 +173,4 @@ const ssmMiddleware = (opts = {}) => {
175
173
  before: ssmMiddlewareBefore
176
174
  }
177
175
  }
178
- module.exports = ssmMiddleware
176
+ export default ssmMiddleware
package/package.json CHANGED
@@ -1,23 +1,25 @@
1
1
  {
2
2
  "name": "@middy/ssm",
3
- "version": "2.5.6",
3
+ "version": "3.0.0-alpha.3",
4
4
  "description": "SSM (EC2 Systems Manager) parameters middleware for the middy framework",
5
- "type": "commonjs",
5
+ "type": "module",
6
6
  "engines": {
7
- "node": ">=12"
7
+ "node": ">=14"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "main": "index.js",
13
+ "exports": "./index.js",
14
14
  "types": "index.d.ts",
15
15
  "files": [
16
+ "index.js",
16
17
  "index.d.ts"
17
18
  ],
18
19
  "scripts": {
19
20
  "test": "npm run test:unit",
20
- "test:unit": "ava"
21
+ "test:unit": "ava",
22
+ "test:benchmark": "node __benchmarks__/index.js"
21
23
  },
22
24
  "license": "MIT",
23
25
  "keywords": [
@@ -46,12 +48,12 @@
46
48
  },
47
49
  "homepage": "https://github.com/middyjs/middy#readme",
48
50
  "dependencies": {
49
- "@middy/util": "^2.5.6"
51
+ "@middy/util": "^3.0.0-alpha.3"
50
52
  },
51
53
  "devDependencies": {
52
- "@middy/core": "^2.5.6",
54
+ "@middy/core": "^3.0.0-alpha.3",
53
55
  "aws-sdk": "^2.939.0",
54
56
  "aws-xray-sdk": "^3.3.3"
55
57
  },
56
- "gitHead": "0c789f55b4adf691f977b0d9904d1a805bb3bb2b"
58
+ "gitHead": "1441158711580313765e6d156046ef0fade0d156"
57
59
  }