Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

middy

Package Overview
Dependencies
Maintainers
8
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

middy - npm Package Compare versions

Comparing version 0.13.2 to 0.13.3

2

package.json
{
"name": "middy",
"version": "0.13.2",
"version": "0.13.3",
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -18,14 +18,14 @@ jest.mock('aws-sdk')

getParametersByPathMock.mockClear()
delete process.env.MONGO_URL
delete process.env.OTHER_MONGO_URL
delete process.env.SERVICE_NAME_MONGO_URL
delete process.env.KEY_NAME
})
function testScenario ({ssmMockResponse, middlewareOptions, context = {}, cb}) {
getParametersMock.mockReturnValueOnce({
promise: () => Promise.resolve(ssmMockResponse)
})
function testScenario ({ssmMockResponse, ssmMockResponses, middlewareOptions, context = {}, cb}) {
(ssmMockResponses || [ssmMockResponse]).forEach(ssmMockResponse => {
getParametersMock.mockReturnValueOnce({
promise: () => Promise.resolve(ssmMockResponse)
})
getParametersByPathMock.mockReturnValue({
promise: () => Promise.resolve(ssmMockResponse)
getParametersByPathMock.mockReturnValueOnce({
promise: () => Promise.resolve(ssmMockResponse)
})
})

@@ -47,11 +47,11 @@

ssmMockResponse: {
Parameters: [{Name: '/dev/service_name/mongo_url', Value: 'my-mongo-url'}]
Parameters: [{Name: '/dev/service_name/key_name', Value: 'key-value'}]
},
middlewareOptions: {
names: {
MONGO_URL: '/dev/service_name/mongo_url'
KEY_NAME: '/dev/service_name/key_name'
}
},
cb () {
expect(process.env.MONGO_URL).toEqual('my-mongo-url')
expect(process.env.KEY_NAME).toEqual('key-value')
done()

@@ -64,11 +64,11 @@ }

// simulate already cached value
process.env.MONGO_URL = 'some-value'
process.env.KEY_NAME = 'key-value'
testScenario({
ssmMockResponse: {
Parameters: [{Name: '/dev/service_name/mongo_url', Value: 'my-mongo-url'}]
Parameters: [{Name: '/dev/service_name/key_name', Value: 'key-value'}]
},
middlewareOptions: {
names: {
MONGO_URL: '/dev/service_name/mongo_url'
KEY_NAME: '/dev/service_name/key-value'
},

@@ -177,3 +177,3 @@ cache: true

ssmMockResponse: {
Parameters: [{Name: '/dev/service_name/mongo_url', Value: 'my-mongo-url'}]
Parameters: [{Name: '/dev/service_name/key_name', Value: 'key-value'}]
},

@@ -184,3 +184,3 @@ middlewareOptions: {

cb () {
expect(process.env.MONGO_URL).toEqual('my-mongo-url')
expect(process.env.KEY_NAME).toEqual('key-value')
done()

@@ -192,6 +192,7 @@ }

test('It should retrieve params from multiple paths', (done) => {
const ssmMockResponse = {
Parameters: [{Name: '/dev/service_name/key_name', Value: 'key-value'}]
}
testScenario({
ssmMockResponse: {
Parameters: [{Name: '/dev/service_name/mongo_url', Value: 'my-mongo-url'}]
},
ssmMockResponses: [ssmMockResponse, ssmMockResponse],
middlewareOptions: {

@@ -201,4 +202,4 @@ paths: {'': ['/dev/service_name'], 'prefix': '/dev'}

cb () {
expect(process.env.MONGO_URL).toEqual('my-mongo-url')
expect(process.env.PREFIX_SERVICE_NAME_MONGO_URL).toEqual('my-mongo-url')
expect(process.env.KEY_NAME).toEqual('key-value')
expect(process.env.PREFIX_SERVICE_NAME_KEY_NAME).toEqual('key-value')
done()

@@ -208,2 +209,24 @@ }

})
test('It should make multiple API calls for a single path if the response contains a token for additional params', (done) => {
testScenario({
ssmMockResponses: [
{
Parameters: [{Name: '/dev/service_name/key_name1', Value: 'key-value1'}],
NextToken: 'token'
},
{
Parameters: [{Name: '/dev/service_name/key_name2', Value: 'key-value2'}]
}
],
middlewareOptions: {
paths: {'': ['/dev/service_name']}
},
cb () {
expect(process.env.KEY_NAME1).toEqual('key-value1')
expect(process.env.KEY_NAME2).toEqual('key-value2')
done()
}
})
})
})

@@ -31,6 +31,3 @@ let paramsLoaded = false

subAggregator.push(
ssmInstance
.getParametersByPath({ Path: path, Recursive: true, WithDecryption: true })
.promise()
.then(handleInvalidParams)
getParamsByPathRecursively(path)
.then(ssmResponse => getParamsToAssignByPath(path, ssmResponse, prefix, options.getParamNameFromPath))

@@ -65,2 +62,16 @@ )

const getParamsByPathRecursively = (path, nextToken) => {
return ssmInstance
.getParametersByPath({ Path: path, NextToken: nextToken, Recursive: true, WithDecryption: true })
.promise()
.then(paramsResponse => {
const additionalParamsPromise = paramsResponse.NextToken
? getParamsByPathRecursively(path, paramsResponse.NextToken)
: Promise.resolve([])
return additionalParamsPromise
.then(additionalParams => [...paramsResponse.Parameters, ...additionalParams])
})
}
// returns full parameter name sans the path as specified, with slashes replaced with underscores and any prefix applied

@@ -67,0 +78,0 @@ // everything gets upper cased

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc