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

Create approve templates #43

Merged
merged 5 commits into from
Jan 17, 2018
Merged

Create approve templates #43

merged 5 commits into from
Jan 17, 2018

Conversation

pauloancheta
Copy link
Contributor

@pauloancheta pauloancheta commented Jan 4, 2018

depends on #41

Usage

  • Change ApprovedTemplateLocation to the full s3 url with key of the template to be approved
  • Run command: iidy approve-template stack-args.yaml

Notes:

I could also change it to iidy approve-template https://s3.amazon.com...yaml.pending but to add --profile functionality is more tedious.
Ideally, it would be using iidy approve-template hash.yaml.pending but the command would not know which profile to use and which bucket to look at.

Added a flag --approve to approve the template. Running the iidy approve-template ... command should diff the changes first. I have opted not to use a readline to precent fat fingering answers.

TODO:

@pauloancheta pauloancheta force-pushed the create-approve-templates branch 5 times, most recently from 5d47767 to 7a8cc8a Compare January 7, 2018 22:04
@pauloancheta pauloancheta changed the base branch from master to create-request-approval January 8, 2018 20:31
@pauloancheta pauloancheta force-pushed the create-request-approval branch from dbc018d to 02d8bde Compare January 8, 2018 20:33
Copy link
Contributor

@jpb jpb left a comment

Choose a reason for hiding this comment

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

Simliar to #41, I don't think you should assume the extension is or should be .yaml. Either use path.extname to discover the extension or do not append an extension to the path (I think its unlikely these paths will be used in a context where the extension is meaningful anyway).

}
});
console.log(colorizedString);
console.log("Do these changes look good for you? Add a flag `--approve true` to approve");
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be interactive? Prompt for y/n similar to this.

return 0
}

// create a new pending file
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be in the else branch of the conditional above (even though there is a return).

Bucket: s3Url.bucket,
Key: s3Url.key.replace(/\.pending$/, "")
}).promise();
logSuccess("Created a new cfn-template.yaml.");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should log this and "Updated latest" at debug level.

export async function approveTemplate(argv: Arguments): Promise<number> {
await configureAWS(argv.profile, "us-east-1");
const s3 = new S3();
const s3Url = parseS3HttpUrl(argv.filename);
Copy link
Contributor

Choose a reason for hiding this comment

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

The same as #41 (comment), this is a misuse of parseS3HttpUrl

.then((template) => template.Body)
.catch((e) => {
if (e.code !== "NoSuchKey") {
return Promise.reject(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

👌

@pauloancheta pauloancheta force-pushed the create-approve-templates branch from 7a8cc8a to 3732c0c Compare January 9, 2018 22:58
@jpb jpb changed the base branch from create-request-approval to master January 11, 2018 22:47
@jpb jpb mentioned this pull request Jan 11, 2018
1 task
src/cfn/index.ts Outdated
@@ -1515,6 +1516,7 @@ export async function convertStackToIIDY(argv: Arguments): Promise<number> {
const stackArgs: StackArgs = {
Template: './cfn-template.yaml',
StackName: StackNameArg,
ApprovedTemplateLocation: '',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't the default here be undefined?

const s3Bucket = s3Url.hostname ? s3Url.hostname : "";

const fileName = new Md5().appendStr(cfnTemplate.toString()).end().toString()
const fullFileName = `${fileName}${path.extname(stackArgs.Template)}.pending`
Copy link
Collaborator

Choose a reason for hiding this comment

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

semicolons on this and line 30.

previouslyApprovedTemplate!.toString(),
pendingTemplate!.toString(),
);
let colorizedString = ""
Copy link
Collaborator

Choose a reason for hiding this comment

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

semicolon

Copy link
Collaborator

Choose a reason for hiding this comment

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

same in other spots in this file

@tavisrudd
Copy link
Collaborator

Let's squash the commits prior to merge and then rebase #45.

@jpb jpb force-pushed the create-approve-templates branch from 5a85793 to 420abd5 Compare January 16, 2018 23:52
the command is used as an approval process for the cfn-template.yaml.
When a template is uploaded to an s3 bucket through the cmd, it appends
the suffix `.pending` to the filename. This then enables the
maintainers/admins to review the changes in the cfn-template.yaml before
using it for the stack.

When a template has already been approved (the filename is not appended
with `.pending`) it results to a noop.

When a template is changed, the filename is changed because of the md5
hashing.
@jpb jpb force-pushed the create-approve-templates branch from 420abd5 to 16bf034 Compare January 17, 2018 18:46
@jpb jpb merged commit 69a54e2 into master Jan 17, 2018
@jpb jpb deleted the create-approve-templates branch January 17, 2018 18:51
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.

3 participants