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(invoke): reading Metadata adding to Resources in a template #907

Merged
merged 5 commits into from
Jan 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add warning message when only one of aws:asset:* is provided
  • Loading branch information
jfuss committed Jan 7, 2019
commit 933ee7cd10abdc494f02919aabd705839317e436
17 changes: 13 additions & 4 deletions samcli/lib/samlib/resource_metadata_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
Class that Normalizes a Template based on Resource Metadata
"""

import logging

RESOURCES_KEY = "Resources"
PROPERTIES_KEY = "Properties"
METADATA_KEY = "Metadata"
ASSET_PATH_METADATA_KEY = "aws:asset:path"
ASSET_PROPERTY_METADATA_KEY = "aws:asset:property"

LOG = logging.getLogger(__name__)


class ResourceMetadataNormalizer(object):

Expand All @@ -26,15 +30,15 @@ def normalize(template_dict):
"""
resources = template_dict.get(RESOURCES_KEY, {})

for _, resource in resources.items():
for logical_id, resource in resources.items():
resource_metadata = resource.get(METADATA_KEY, {})
asset_path = resource_metadata.get(ASSET_PATH_METADATA_KEY)
asset_property = resource_metadata.get(ASSET_PROPERTY_METADATA_KEY)

ResourceMetadataNormalizer._replace_property(asset_property, asset_path, resource)
ResourceMetadataNormalizer._replace_property(asset_property, asset_path, resource, logical_id)

@staticmethod
def _replace_property(property_key, property_value, resource):
def _replace_property(property_key, property_value, resource, logical_id):
"""
Replace a property with an asset on a given resource

Expand All @@ -48,7 +52,12 @@ def _replace_property(property_key, property_value, resource):
The new value of the property
resource dict
Dictionary representing the Resource to change
logical_id str
LogicalId of the Resource

"""
if property_value and property_key:
if property_key and property_value:
resource.get(PROPERTIES_KEY, {})[property_key] = property_value
elif property_key or property_value:
LOG.info("WARNING: Ignoring Metadata for Resource %s. Metadata contains only aws:asset:path or "
Copy link

Choose a reason for hiding this comment

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

LOG.warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That will not get logged to console by default (due to how we currently have logging setup) and the pattern we have followed thus far is using LOG.info instead. There is a bigger story here on our logging (including adding colors to make reading easier) but that is for another day.

Copy link

Choose a reason for hiding this comment

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

Sure no prob

"aws:assert:property but not both", logical_id)