Cfn-python-lint: Need to validate that resource type is a string

Created on 9 May 2020  路  3Comments  路  Source: aws-cloudformation/cfn-python-lint

cfn-lint version: (cfn-lint --version) 0.30.1

Description of issue.

image

image

bug good first issue

All 3 comments

The code lines you pointed out are all using either cfn.template.get('Resources', {}).items() or cfn.get_resources().items(). If we can change all instances of the former to the latter, maybe we can make a change within cfn.get_resources():

results = {}
for k, v in resources.items():
    if isinstance(v, dict):
        existing_resource_type = v.get('Type', None)
        if not isinstance(existing_resource_type, six.string_types):
            raise ValueError("A resource type has to be a string")
        if (existing_resource_type in resource_type) or (not resource_type and existing_resource_type is not None):
            results[k] = v

return results

@miparnisari I completely agree catching it in get_resources(). I tried to make the functions like cfn.get_resources() return resources only if they are valid. No value in returning something if the Type is a number or not even specified. It should be a safe way to get back "valid" resources that any rule or even other core functionality can use.

Was this page helpful?
0 / 5 - 0 ratings