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

Feature/use s3 uploader for cf package with include transforms #3454

Conversation

ekcrisp
Copy link

@ekcrisp ekcrisp commented Jul 16, 2018

I recently opened a PR which added exports for include transform of inline swagger AWS::Serverless::Api resource. I've reconsidered and decided to add an implementation that will upload AWS::Include from anywhere in a cloud formation template for cloudformation package command. I have seen several discussions where users have asked for this feature, we would like to manage templates for various resources in isolation and also potentially reuse them in different stacks, this feature will help a lot towards this end.

A few notes, I originally considered doing this on yaml parse or dump to avoid a pass through the entire template dictionary, however since JSON is also supported this would have been clunky, since it would be difficult to reuse parse hooks across pyyaml and json. It was impossible to add this without bypassing the existing "resource" export pattern since these can appear anywhere in the document, adding a handler that matched some key seemed reasonable to me, and I don't think we have to worry about cyclic references for yaml_parse return val. Lastly my python is not very strong and I've never used this unit testing framework, open to any suggestions you have

If this PR is approved I will reject and close the other one

Elliot Korte added 2 commits July 16, 2018 12:28
…age template by adding a global export function for artifacts that are not specific to a resource type
@ekcrisp
Copy link
Author

ekcrisp commented Jul 16, 2018

#3440 will be closed without merging if this is approved

@codecov-io
Copy link

codecov-io commented Jul 17, 2018

Codecov Report

Merging #3454 into develop will increase coverage by 0.45%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3454      +/-   ##
===========================================
+ Coverage    94.43%   94.88%   +0.45%     
===========================================
  Files          173      180       +7     
  Lines        13346    13716     +370     
===========================================
+ Hits         12603    13015     +412     
+ Misses         743      701      -42
Impacted Files Coverage Δ
...customizations/cloudformation/artifact_exporter.py 97.82% <100%> (+0.39%) ⬆️
awscli/compat.py 87.3% <0%> (-4.19%) ⬇️
awscli/clidriver.py 96.06% <0%> (-0.02%) ⬇️
awscli/customizations/commands.py 99.54% <0%> (-0.01%) ⬇️
awscli/customizations/s3/subcommands.py 97.21% <0%> (ø) ⬆️
awscli/handlers.py 100% <0%> (ø) ⬆️
awscli/paramfile.py 100% <0%> (ø) ⬆️
awscli/customizations/putmetricdata.py 100% <0%> (ø) ⬆️
awscli/customizations/cliinputjson.py 100% <0%> (ø) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b31a418...1eaa24f. Read the comment docs.

@ekcrisp
Copy link
Author

ekcrisp commented Jul 17, 2018

@stealthycoin @sanathkr @jamesls @joguSD would appreciate a review from someone on your end when you get a chance, I'm going on vacation soon and would like to make any updates before then :)

this implements the feature requested here
#2513

@davidkelley
Copy link

Any update on this work? It would be fantastic to have this working 👍

Copy link
Contributor

@sanathkr sanathkr left a comment

Choose a reason for hiding this comment

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

Code looks good! Thanks for doing this. Very useful indeed.

Can you also update the aws cloudformation package help text specifying this usage mode?

@ekcrisp
Copy link
Author

ekcrisp commented Oct 16, 2018

@sanathkr Just updated, thank you for reviewing!

Copy link
Contributor

@sanathkr sanathkr left a comment

Choose a reason for hiding this comment

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

Thanks for the quick revision!

Copy link
Contributor

@kyleknap kyleknap left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for putting this together! Looks like it will be really helpful. My main comments were related to Python styling. One suggestion I have in general is to run the code that you added (I would not worry about the preexisting code) under flake8 it will help catch issues with Python styling.

here we iterate through the template dict and export params with a
handler defined in GLOBAL_EXPORT_DICT
"""
for key, val in iter(template_dict.items()):
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a python thing. We can simplify this to:

Suggested change
for key, val in iter(template_dict.items()):
for key, val in template_dict.items():

template_dict[key] = GLOBAL_EXPORT_DICT[key](val, self.uploader)
elif type(val) is dict:
self.export_global_artifacts(val)
return self.template_dict
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it intentional that we are returning self.template_dict? I would assume it would instead be return template_dict. We probably we do not even need to return anything here because Python dictionaries are mutable so any updates made to the dictionary will reflect in the original dictionary passed in.

Copy link
Author

Choose a reason for hiding this comment

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

I meant to return just template_dict good catch. I'm aware it's not necessary to return and reassign in export but I decided to since I generally dislike mutating values passed into a method so I added an assignment for a brighter future where this is refactored :)

for key, val in iter(template_dict.items()):
if key in GLOBAL_EXPORT_DICT:
template_dict[key] = GLOBAL_EXPORT_DICT[key](val, self.uploader)
elif type(val) is dict:
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to simplify this to:

Suggested change
elif type(val) is dict:
elif isinstance(val, dict):

if key in GLOBAL_EXPORT_DICT:
template_dict[key] = GLOBAL_EXPORT_DICT[key](val, self.uploader)
elif type(val) is dict:
self.export_global_artifacts(val)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to have Fn::Transforms in lists as well? We may want to traverse through lists as well if that is the case.

Copy link
Author

Choose a reason for hiding this comment

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

great catch, updated

@ekcrisp
Copy link
Author

ekcrisp commented Oct 17, 2018

@kyleknap thank you for the review! I just updated take a look when you get a chance

Copy link
Contributor

@kyleknap kyleknap left a comment

Choose a reason for hiding this comment

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

Thanks for the update! Looks good to me. 🚢 Merging.

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.

5 participants