Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter change approval #104

Merged
merged 6 commits into from
Apr 16, 2018
Merged

Parameter change approval #104

merged 6 commits into from
Apr 16, 2018

Conversation

jpb
Copy link
Contributor

@jpb jpb commented Apr 13, 2018

Adds:

  • iidy param set --with-approval
  • iidy param review ...
  • Metadata to iidy get-history

Fixes:

  • bug with iidy get-history which omitted the first previous value

Closes #91

@jpb jpb changed the title [WIP] Parameter change approval Parameter change approval Apr 13, 2018
await setParamTags(ssm, Name, tags);
return 0;
} else {
return 130;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we use a lot of numbers in the repo. Wondering if these numbers should be constants that live somewhere so it can be clearer. Maybe we can also prepend it with SH to signify that it's the shell exit code that it returns?

return SH_SUCCESS // for 0 returns
return SH_FAILURE // for 1 returns
return SH_TERMINATED // I'm assuming 130 happens when we press <Ctrl-c>?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus one for less magic numbers

const Overwrite = true;
const KeyId = Type === 'SecureString' ? await getKMSAliasForParameter(Name) : undefined;

console.log(`Current: ${currentValue}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jpb added 3 commits April 16, 2018 20:04
Fix "previous" list to include correct entries. Add some metadata to 'simple'
format
@jpb jpb force-pushed the param-approval branch from c71e228 to a223dfe Compare April 16, 2018 20:05
@jpb jpb requested a review from tavisrudd April 16, 2018 21:08
@@ -74,8 +75,8 @@ export async function setParam(argv: SetParamArgs): Promise<number> {
const res = await ssm.putParameter({Name, Value, Type, KeyId, Overwrite}).promise();

if(argv.withApproval) {
console.log('Parameter change is pending approval. Review change with:');
console.log(` iidy --region ${argv.region} param review ${argv.path}`);
logger.info('Parameter change is pending approval. Review change with:');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we also using logger.info on the template approval side?

@tavisrudd
Copy link
Collaborator

tavisrudd commented Apr 16, 2018

This looks good, but I think we should remove the use of logger.info and switch back to console.log. That's what we're using elsewhere and the info: prefix adds noise to the output, especially for commands like get and get-history which can be told to output json for parsing / chaining with other tools.

There's also a bug in pagination that I'll look into further:

$ LOG_IIDY_ERROR=1 iidy param --profile sandbox get-by-path --recursive /
error: this.makeRequest is not a function
error:  TypeError: this.makeRequest is not a function
    at svc.(anonymous function) (/Users/tavis/src/ub/cf_templates/node_modules/aws-sdk/lib/service.js:499:23)
    at Object.paginateAwsCall (/Users/tavis/src/ub/cf_templates/lib/paginateAwsCall.js:6:22)
    at Object.getParamsByPath (/Users/tavis/src/ub/cf_templates/lib/params/index.js:175:55)
    at <anonymous>

@jpb jpb force-pushed the param-approval branch from a223dfe to 9206a45 Compare April 16, 2018 21:23
@@ -108,8 +196,7 @@ export async function _getParamsByPath(Path: string): Promise<aws.SSM.ParameterL
Path,
WithDecryption: true
};
const parameters: aws.SSM.ParameterList = await paginateAwsCall(
(args) => ssm.getParametersByPath(args), args, 'Parameters');
const parameters: aws.SSM.ParameterList = await paginateAwsCall(ssm.getParametersByPath, args, 'Parameters');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a bug. We should either revert or bind.

error: this.makeRequest is not a function
error:  TypeError: this.makeRequest is not a function
    at svc.(anonymous function) (/Users/tavis/src/ub/cf_templates/node_modules/aws-sdk/lib/service.js:499:23)
    at Object.paginateAwsCall (/Users/tavis/src/ub/cf_templates/lib/paginateAwsCall.js:6:22)
    at Object.getParamsByPath (/Users/tavis/src/ub/cf_templates/lib/params/index.js:175:55)
    at <anonymous>

@@ -121,43 +208,60 @@ export async function getParamsByPath(argv: GetParamsByPathArgs): Promise<number
Recursive: argv.recursive,
WithDecryption: argv.decrypt
};
const parameters: aws.SSM.ParameterList = await paginateAwsCall((args) => ssm.getParametersByPath(args), args, 'Parameters');
const parameters: aws.SSM.ParameterList = await paginateAwsCall(ssm.getParametersByPath, args, 'Parameters');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above. This is broken.

@@ -0,0 +1,3 @@
export const SUCCESS = 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are backwards in shell terms. 0=SUCCESS

return res && res.Parameter;
} catch(e) {
// Return undefined if parameter does not exist
if(!(e.code && e.code === 'ParameterNotFound')) {
Copy link
Collaborator

@tavisrudd tavisrudd Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would read better if we were to explicitly return undefined in the true case and throw in the else.

return ssm.listTagsForResource({ResourceId: path, ResourceType: 'Parameter'})
.promise()
.then((res) => _.fromPairs(_.map(res.TagList, (tag) => [tag.Key, tag.Value])));
}

async function mergeParamTags(param: aws.SSM.Parameter) {
return _.merge({}, param, {Tags: await getParamTags(param.Name!)});
async function mergeParamTags<T extends aws.SSM.Parameter|aws.SSM.ParameterHistory>(ssm: aws.SSM, param: T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to run tsfmt prior to pushing. It inserts spaces around |.

@jpb jpb force-pushed the param-approval branch from bbad39a to a72ef14 Compare April 16, 2018 22:06
@@ -121,43 +209,60 @@ export async function getParamsByPath(argv: GetParamsByPathArgs): Promise<number
Recursive: argv.recursive,
WithDecryption: argv.decrypt
};
const parameters: aws.SSM.ParameterList = await paginateAwsCall((args) => ssm.getParametersByPath(args), args, 'Parameters');
const parameters: aws.SSM.ParameterList = await paginateAwsCall((p) => ssm.getParametersByPath(p), args, 'Parameters');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p is a bit misleading here as the argument is actually the same args that are passed in later in the call rather than a path.


if (argv.withApproval) {
console.log('Parameter change is pending approval. Review change with:');
console.log(` iidy --region ${argv.region} param review ${argv.path}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argv.region will often be null. Instead, import getCurrentAWSRegion from '../getCurrentAWSRegion';...

Copy link
Collaborator

@tavisrudd tavisrudd Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g.

$ iidy param --profile sandbox set --with-approval /tavis blah2
Parameter change is pending approval. Review change with:
  iidy --region null param review /tavis

@jpb jpb force-pushed the param-approval branch from a72ef14 to fa0061f Compare April 16, 2018 22:52
@tavisrudd
Copy link
Collaborator

Looks good now.

@tavisrudd tavisrudd merged commit ede0293 into master Apr 16, 2018
@tavisrudd tavisrudd deleted the param-approval branch April 16, 2018 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants