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

Don't check for required attributes when spec doesn't have properties #1096

Merged
merged 1 commit into from
Aug 13, 2019
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
7 changes: 6 additions & 1 deletion src/cfnlint/rules/resources/properties/Required.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def propertycheck(self, text, proptype, parenttype, resourcename, tree, root):
self.propertycheck(
item, property_type, parenttype, resourcename,
tree[:] + [index], root))
else:
# this isn't a standard type in the CloudFormation spec so we
# can't check required so skip
return matches

if not isinstance(text, dict):
# Covered with Properties not with Required
Expand Down Expand Up @@ -116,7 +120,8 @@ def propertycheck(self, text, proptype, parenttype, resourcename, tree, root):
if resourcespec[prop]['Required']:
if prop not in value:
message = 'Property {0} missing at {1}'
matches.append(RuleMatch(path, message.format(prop, '/'.join(map(str, path)))))
matches.append(RuleMatch(path, message.format(
prop, '/'.join(map(str, path)))))

# For all specified properties, check all nested properties
for prop in value:
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/templates/good/resources/properties/required.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Deploy resources for the SFTP managed service'

Parameters:
SSHPublicKey:
Type: String
Description: 'SSH public key of the SFTP transfer user'

Resources:
SFTPDTRFUser:
Type: AWS::Transfer::User
Properties:
UserName: test
ServerId: s-123456
Role: arn:aws:iam:etc
SshPublicKeys:
- !Ref SSHPublicKey # Don't fail when using a dict on a non standard spec resource
Tags:
- Key: Issue
Value: https://github.com/aws-cloudformation/cfn-python-lint/issues/1088
5 changes: 5 additions & 0 deletions test/rules/resources/properties/test_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@

class TestResourceConfiguration(BaseRuleTestCase):
"""Test Resource Properties"""

def setUp(self):
"""Setup"""
super(TestResourceConfiguration, self).setUp()
self.collection.register(Required())
self.success_templates = [
'test/fixtures/templates/good/resources/properties/required.yaml',
]

def test_file_positive(self):
"""Test Positive"""
Expand All @@ -42,6 +46,7 @@ def test_file_negative_generic(self):

class TestSpecifiedCustomResourceRequiredProperties(TestResourceConfiguration):
"""Test Custom Resource Required Properties when override spec is provided"""

def setUp(self):
"""Setup"""
super(TestSpecifiedCustomResourceRequiredProperties, self).setUp()
Expand Down