-
Notifications
You must be signed in to change notification settings - Fork 313
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
[Resolve #1318] Implement dump template and write output files #1325
[Resolve #1318] Implement dump template and write output files #1325
Conversation
In the event that the reader class is unable to parse the rendered config, this adds logic to write the rendered config to a file to assist the caller in understand what went wrong.
This adds a sceptre dump template command and deprecates sceptre generate.
This reverts commit 3005b14.
This reverts commit acb399b.
This reverts commit 4d1e5cc.
This reverts commit c1ca8ed.
I feel like there must be a better way. Is there a way we can fix the |
Maybe a flag like |
@jfalkenstein Well if we fixed the generate command (we could copy this functionality there instead), we are then left with:
I think this is actually quite clean and a big improvement myself. (Not that I really care either way.) |
Yes, I assume we will probably make this behaviour optional via some sort of flag in the final version. |
sceptre/cli/dump.py
Outdated
if template is None: | ||
logger.warning(f"{stack.external_name} does not exist") | ||
else: | ||
output.append({stack.external_name: template}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a list of dicts and not just one big dict?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, for consistency with dump config
. I can't remember to be honest why we did it this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That feels a bit odd to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it may be to work around or hack the limitations of the write
helper. If we need to change dump config
, perhaps this should be looked at in a separate issue/PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only concern is this: Let's say I need to pipe a template over to a linter or awscli for some reason because it has jinja and other stuff in it. I want to do something like: sceptre dump template my/sceptre/config.yaml | cfn-lint -
. When you're outputting the templates inside a larger data structure like this, that's not a valid template.
I understand your concern of wanting to be able to associate the template with a stack, so there are a few options I can think of:
Option 1: Rather than this, you could output the stack name via a logger rather than echoing it. That will result it going to stderr rather than stdout. That way, if you pipe output to another command or use >
, it won't actually get included. So you could alternate by logging the stack name and then writing the output.
Option 2: Have a --stack-names
flag that optionally makes it output this way but by default it does not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jfalkenstein you are misunderstanding the implementation and behaviour. Here's a demo, showing a yaml stream that can be parsed by external tools is always emitted, even in the case of multiple stacks:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm just very concerned about adding a completely new command that is ALMOST identical to the old command except it outputs in a slightly different format. I really don't think this is the right way to proceed.
I've refactored the |
@jfalkenstein have a look now. Here's what I changed:
|
changes done
@@ -18,9 +22,12 @@ def dump_group(): | |||
|
|||
@dump_group.command(name="config") | |||
@click.argument("path") | |||
@click.option( | |||
"--to-file", is_flag=True, help="If True, also dump the template to a local file." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor thing, but this says "also", but it appears as if dumping is now either to file or to console, but not both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind. I see what we're doing now.
sceptre/cli/helpers.py
Outdated
@@ -93,6 +102,13 @@ def write(var, output_format="json", no_colour=True): | |||
|
|||
click.echo(output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it odd that we still echo if a file_path is specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok how about now? (I'm not sure whether people want the text to go to both the screen and file if file_path is specified).
Running integration tests now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generate
is found in a few locations in the docs. if we are deprecating that command in this same PR then could we also update to dump in the docs as well?
I think it might be cleaner to deprecate the generate command in a follow on PR.
|
||
@dump_group.command(name="all") | ||
@click.argument("path") | ||
@click.option( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing the --to-file
option. is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not intentional, fixed.
A few hits on the word when I |
This is what i see
I think those references should be changed to the Also didn't we decide to alias the generate to the dump command? if so, it looks like it wasn't done in template.py
|
@zaro0508 I didn't actually know about the |
Yes but it was aliased not in the CLI but in the API which is I think the way it should be. |
What is your reasoning for not aliasing it in the CLI as well? |
Well, aliasing in both places will just result in unused code paths. If I point the generate CLI command at the dump_template API, why not just remove the generate API since it is no longer used? In the end I don't really mind how it is done or necessarily see the point in aliasing in the first place. The implementation above does have the advantage that it seems to be the one that @jfalkenstein agreed to and not to mention that it's the one that I already implemented! |
Description
Proposed implementation of #1318
This introduces a
dump template
command that behaves similarly togenerate
but also writes output docs to files.The behaviour of
dump config
is changed here not to print multi-doc output to screen similar todump config
.The
write
helper function is modified to optionally write to afile_path
.Writes files in a naming convention for
dump config
anddump template
respectively:Usage example
Dump config
Dump template
File structure created
File content
PR Checklist
[Resolve #issue-number]
.make test
) are passing.pre-commit run --all-files
).and description in grammatically correct, complete sentences.
Approver/Reviewer Checklist
Other Information
Guide to writing a good commit