Skip to content

Commit

Permalink
Merge pull request #25 from mysense-ai/bugfix/max-params-for-get-para…
Browse files Browse the repository at this point in the history
…meters

fix: account for SSM.GetParameters only taking max 10 names as input
  • Loading branch information
monsagri committed Apr 1, 2020
2 parents 37b69de + 0fceda2 commit 5b76c62
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@types/jest": "^25.1.4",
"@types/node": "^13.9.8",
"@types/serverless": "^1.18.6",
"aws-sdk": "^2.649.0",
"aws-sdk": "^2.650.0",
"aws-sdk-mock": "^5.1.0",
"codecov": "^3.6.5",
"commitizen": "^4.0.3",
Expand All @@ -76,7 +76,7 @@
"husky": "^4.2.3",
"jest": "^25.2.4",
"jest-environment-node": "^25.2.4",
"lint-staged": "^10.1.0",
"lint-staged": "^10.1.1",
"semantic-release": "^17.0.4",
"ts-jest": "^25.3.0",
"ts-node": "^8.8.1",
Expand Down
24 changes: 21 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,31 @@ class ServerlessSSMPublish {
/**
* Checks whether parameters exist in SSM and if they've been changed
* Stores arrays of changed/unchanged/new Parameters on class
* We need to account for SSM.GetParameters taking a max of 10 names
*/
private async getAndCheckParams() {
if (!this.params) return;
const retrievedParameters = await this.ssm.getParameters({ Names: this.params.map((param) => param.path), WithDecryption: true}).promise();

if (retrievedParameters.InvalidParameters?.length) this.log(chalk.yellow(`New or invalid parameters present:\n\t${retrievedParameters.InvalidParameters.join('\n\t')}`));
const chunkArray = ((array: SSMParam[], arraySize: number): SSMParam[][] => {
const arrayChunks: SSMParam[][] = [];
for (let i = 0; i < array.length; i += arraySize) {
arrayChunks.push(array.slice(i, arraySize + i));
}
return arrayChunks;
});

const getParameters = async (params: SSMParam[]) => this.ssm.getParameters({ Names: params.map((param) => param.path), WithDecryption: true}).promise();

const paramsToCheck = chunkArray(this.params, 10); // tslint:disable-line:no-magic-numbers

const retrievedParameterArray = await Promise.all(paramsToCheck.map(async (paramGroup: SSMParam[]) => getParameters(paramGroup)));

const { nonExistingParams, existingChangedParams, existingUnchangedParams } = compareParams(this.params, retrievedParameters.Parameters);
const foundParams = retrievedParameterArray.map((result) => result.Parameters).reduce((acc, curr) => [...acc ? acc : [], ...curr ? curr : []], []);
const invalidOrNewParams = retrievedParameterArray.map((result) => result.InvalidParameters).reduce((acc, curr) => [...acc ? acc : [], ...curr ? curr : []], []);

if (invalidOrNewParams?.length) this.log(chalk.yellow(`New or invalid parameters present:\n\t${invalidOrNewParams.join('\n\t')}`));

const { nonExistingParams, existingChangedParams, existingUnchangedParams } = compareParams(this.params, foundParams);

this.logIfDebug(`New param paths:\n\t${nonExistingParams.map((param) => param.path).join('\n\t')}`);
this.logIfDebug(`Changed param paths:\n\t${existingChangedParams.map((param) => param.path).join('\n\t')}`);
Expand All @@ -171,6 +188,7 @@ class ServerlessSSMPublish {
this.nonExistingParams = nonExistingParams;
this.existingChangedParams = existingChangedParams;
this.existingUnchangedParams = existingUnchangedParams;

}

/**
Expand Down
51 changes: 33 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,9 @@
semver "^6.1.1"

"@serverless/enterprise-plugin@^3.5.0":
version "3.6.1"
resolved "https://registry.yarnpkg.com/@serverless/enterprise-plugin/-/enterprise-plugin-3.6.1.tgz#66f3352545d8ca483c16694551f6df1920992d21"
integrity sha512-n0skyN6CSprI4djHUU69XDCb06W5DU/ogHmbTKrwrNhvsLg6Hhd99sRKHjKM5wCSbsILKR79/rkozah+mw6e2w==
version "3.6.2"
resolved "https://registry.yarnpkg.com/@serverless/enterprise-plugin/-/enterprise-plugin-3.6.2.tgz#2f9b9f046efbfbc2d1c4bda9f067e3ab0ce9f7f3"
integrity sha512-B1W2m8+oS5qG2vgYgwQzrib3OUzSzOLqVD6P7AY6moVAFiGNYqoc7XzdkSO4O9ds4B6MJXbwUjeE8at+Fsgyrg==
dependencies:
"@serverless/event-mocks" "^1.1.1"
"@serverless/platform-client" "^0.24.0"
Expand Down Expand Up @@ -871,7 +871,7 @@
"@types/lodash" "^4.14.123"
lodash "^4.17.11"

"@serverless/platform-client@^0.24.0", "@serverless/platform-client@latest":
"@serverless/platform-client@^0.24.0":
version "0.24.0"
resolved "https://registry.yarnpkg.com/@serverless/platform-client/-/platform-client-0.24.0.tgz#1e0366e9bf22831d0f62f351280cdccffe0acc43"
integrity sha512-ppxR5wONzzxNSmt/9agfSzC0F4yrkHZWAR5IPLm4yj+dMxb+768XrbqBU6vnOfCcmjb89OX5Bk0GvyQh+T5gLw==
Expand All @@ -886,6 +886,21 @@
traverse "^0.6.6"
ws "^7.2.1"

"@serverless/platform-client@latest":
version "0.25.1"
resolved "https://registry.yarnpkg.com/@serverless/platform-client/-/platform-client-0.25.1.tgz#e01d3bc7e10efb5b1f1399c607ae3833a0edc316"
integrity sha512-hqHIqHOGxrqXxoI2Se4ezXwtVhKNJhQDv/njN4obfquv7QBVfXSfe7pBed98ld3jA9exOqqTT+xtHpsLKT6ujg==
dependencies:
adm-zip "^0.4.13"
axios "^0.19.2"
https-proxy-agent "^5.0.0"
isomorphic-ws "^4.0.1"
js-yaml "^3.13.1"
jwt-decode "^2.2.0"
querystring "^0.2.0"
traverse "^0.6.6"
ws "^7.2.1"

"@serverless/platform-sdk@^2.3.0":
version "2.3.0"
resolved "https://registry.yarnpkg.com/@serverless/platform-sdk/-/platform-sdk-2.3.0.tgz#a8a7345e1b37f3204fdaf525e9d1935ef024ed67"
Expand Down Expand Up @@ -980,9 +995,9 @@
integrity sha512-88E4Hlypo3AE40wslm7N4n09lCIJwgYJm5wsaA3/Vib1xqjC/ANePTaPRpPdj9NzBSpw7Tgon58qGMYEArx4oA==

"@types/babel__core@^7.1.0":
version "7.1.6"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.6.tgz#16ff42a5ae203c9af1c6e190ed1f30f83207b610"
integrity sha512-tTnhWszAqvXnhW7m5jQU9PomXSiKXk2sFxpahXvI20SZKu9ylPi8WtIxueZ6ehDWikPT0jeFujMj3X4ZHuf3Tg==
version "7.1.7"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.7.tgz#1dacad8840364a57c98d0dd4855c6dd3752c6b89"
integrity sha512-RL62NqSFPCDK2FM1pSDH0scHpJvsXtZNiYlMB73DgPBaG1E38ZYVL+ei5EkWRbr+KC4YNiAUNBnRj+bgwpgjMw==
dependencies:
"@babel/parser" "^7.1.0"
"@babel/types" "^7.0.0"
Expand Down Expand Up @@ -1547,10 +1562,10 @@ aws-sdk-mock@^5.1.0:
sinon "^9.0.1"
traverse "^0.6.6"

aws-sdk@^2.637.0, aws-sdk@^2.642.0, aws-sdk@^2.649.0:
version "2.649.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.649.0.tgz#a600584171a53a4dcf09d768e514b7bdc408abab"
integrity sha512-0o3l+bfz++KOYHG0gdWofSX/1EdyaD1ixEvWXt71mBbDM1vWc71xfXGzPRtt8Cu8/Id47v7DE3ayELZytzLCXQ==
aws-sdk@^2.637.0, aws-sdk@^2.642.0, aws-sdk@^2.650.0:
version "2.650.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.650.0.tgz#edf995cf2805c918d7470a652f1316ae902c5aa4"
integrity sha512-MlTKXeRSe4IXXqnulAiXZccpTgDafs3ofYIQv/7ApR+oQUFsq96RHwe8MdW9N1cXn7fz302jLXUAykj4boR3DA==
dependencies:
buffer "4.9.1"
events "1.1.1"
Expand Down Expand Up @@ -5992,10 +6007,10 @@ lines-and-columns@^1.1.6:
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00"
integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=

lint-staged@^10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-10.1.0.tgz#18785bb005d5ed404f1c1db6563e082f7a7baac2"
integrity sha512-WzZ/T+O/aEaaT679sMgI4JqK5mnG69V5KQSouzVsShzZ8wGWte39HT3z61LsxjVNeCf8m/ChhvWJa2wTiQLy5A==
lint-staged@^10.1.1:
version "10.1.1"
resolved "https://registry.yarnpkg.com/lint-staged/-/lint-staged-10.1.1.tgz#1c8569b66d684e6e3553cd760c03053f41fca152"
integrity sha512-wAeu/ePaBAOfwM2+cVbgPWDtn17B0Sxiv0NvNEqDAIvB8Yhvl60vafKFiK4grcYn87K1iK+a0zVoETvKbdT9/Q==
dependencies:
chalk "^3.0.0"
commander "^4.0.1"
Expand Down Expand Up @@ -9879,9 +9894,9 @@ umask@^1.1.0, umask@~1.1.0:
integrity sha1-8pzr8B31F5ErtY/5xOUP3o4zMg0=

unbzip2-stream@^1.0.9:
version "1.3.3"
resolved "https://registry.yarnpkg.com/unbzip2-stream/-/unbzip2-stream-1.3.3.tgz#d156d205e670d8d8c393e1c02ebd506422873f6a"
integrity sha512-fUlAF7U9Ah1Q6EieQ4x4zLNejrRvDWUYmxXUpN3uziFYCHapjWFaCAnreY9bGgxzaMCFAPPpYNng57CypwJVhg==
version "1.4.0"
resolved "https://registry.yarnpkg.com/unbzip2-stream/-/unbzip2-stream-1.4.0.tgz#097ca7b18b5b71e6c8bc8e514a0f1884a12d6eb1"
integrity sha512-kVx7CDAsdBSWVf404Mw7oI9i09w5/mTT/Ruk+RWa64PLYKvsAucLLFHvQtnvjeADM4ZizxrvG5SHnF4Te4T2Cg==
dependencies:
buffer "^5.2.1"
through "^2.3.8"
Expand Down

0 comments on commit 5b76c62

Please sign in to comment.