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

Ignore Mapping key issues when using Fn::Transform #2017

Merged
merged 1 commit into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/cfnlint/rules/mappings/KeyName.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def check_key(self, key, path):
if not isinstance(key, six.string_types):
message = 'Mapping key ({0}) has to be a string.'
matches.append(RuleMatch(path[:], message.format(key)))
elif not re.match('^[a-zA-Z0-9.-]{1,255}$', key):
elif not re.match('^[a-zA-Z0-9.-]{1,255}$', key) and key != 'Fn::Transform':
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool with this, but had a wilder general thought on #476

What if every violation on Transform lines were ignored, regardless of individual rule logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was more filtering this out because we didn't flag this as a failure, then we started flagging it as a failure so wanted to bring it back to where it was.

Interesting. It could be possible. We would want to evaluate the start and end mark of the finding is within the transform so if someone is doing a one line json document we don't filter out everything.

As we continue to evaluate the need of credentials we may be able to test resolving the Transform as well. Your option would be a great way to not have an issue if we can't resolve credentials. We may be able to implement your idea fairly easily. I may test it out today actually :)

message = 'Mapping key ({0}) has invalid name. Name has to be alphanumeric, \'-\' or \'.\''
matches.append(RuleMatch(path[:], message.format(key)))

Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/templates/good/mappings/key_name.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
AWSTemplateFormatVersion: "2010-09-09"
Mappings:
AwsAgentPlatformMap:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: s3://my-bucket-name/version/3.0.1/amazonlinux2/a-json-file.json
myMap:
'123456789012':
AMI: "ami-7f418316"
Expand Down