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

feat(cloudformation): SAM Globals support with CloudFormation #6657

Merged
merged 24 commits into from
Aug 21, 2024

Conversation

omriyoffe-panw
Copy link
Contributor

@omriyoffe-panw omriyoffe-panw commented Aug 15, 2024

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Added partial support for configuring Globals section according to SAM syntax

Fixes #2758

Fix

SAM properties that are represented in the same data structure as in CloudFormation syntax are merged. Other properties (such as Tags) are not merged as part of this feature.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes

@omriyoffe-panw omriyoffe-panw changed the title feat: SAM Globals support with CloudFormation feat(cloudformation): SAM Globals support with CloudFormation Aug 15, 2024
@@ -1,5 +1,6 @@
from __future__ import annotations

from copy import deepcopy
Copy link
Contributor

Choose a reason for hiding this comment

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

we have the pickle_deepcopy func for performance wise :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great I'll use it, Thanks!

Copy link
Contributor

@SteveVaknin SteveVaknin 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 and well tested 💯

return new_template # Return the new template even if there were no globals to apply


def deep_merge(dict1: DictNode, dict2: DictNode) -> DictNode:
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this function can be moved under DictNode class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

@@ -154,10 +154,16 @@ def _add_sam_globals(self) -> None:
transform_step=True,
)
elif isinstance(value, list):
# Remove duplicates
new_value = [*vertex.attributes[property], *value]
new_value_unique = []
Copy link
Contributor

Choose a reason for hiding this comment

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

why not use list(set(new_value)).
also new_value is a bad name, I would call it list_updated_value or something like that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of the lists there have multiple types in them so list(set(new_value)) didn't work. And I'll change the name

enriched_template = enrich_resources_with_globals(original_template)
self.assertEqual(enriched_template, expected_template)

def test_deep_merge_non_conflicting(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

nice tests!

@omriyoffe-panw omriyoffe-panw merged commit f064a6b into main Aug 21, 2024
41 checks passed
@omriyoffe-panw omriyoffe-panw deleted the cf-global-support branch August 21, 2024 06:38
boring-repos bot pushed a commit to harryzcy/checkov that referenced this pull request Aug 22, 2024
epartington pushed a commit to epartington/checkov that referenced this pull request Aug 26, 2024
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.

Properties in AWS SAM Globals section not merged with associated resources
5 participants