Skip to content

Commit

Permalink
Move the resource types into the init function to prevent rule and se…
Browse files Browse the repository at this point in the history
…tting sharing between rules (aws-cloudformation#424)
  • Loading branch information
kddejong authored and Chuck Meyer committed Oct 29, 2018
1 parent 70737f4 commit 4765ff5
Show file tree
Hide file tree
Showing 23 changed files with 37 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/cfnlint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class CloudFormationLintRule(object):
tags = []

logger = logging.getLogger(__name__)
resource_property_types = []
resource_sub_property_types = []

def __init__(self):
self.resource_property_types = []
self.resource_sub_property_types = []

def __repr__(self):
return '%s: %s' % (self.id, self.shortdesc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DynamicReferenceSecureString(CloudFormationLintRule):

def __init__(self, ):
"""Init """
super(DynamicReferenceSecureString, self).__init__()
specs = cfnlint.helpers.RESOURCE_SPECS.get('us-east-1')
self.property_specs = specs.get('PropertyTypes')
self.resource_specs = specs.get('ResourceTypes')
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/functions/GetAtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class GetAtt(CloudFormationLintRule):
tags = ['functions', 'getatt']

def __init__(self):
super(GetAtt, self).__init__()
resourcespecs = cfnlint.helpers.RESOURCE_SPECS['us-east-1']
self.resourcetypes = resourcespecs['ResourceTypes']
self.propertytypes = resourcespecs['PropertyTypes']
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/outputs/Value.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Value(CloudFormationLintRule):
tags = ['outputs']

def __init__(self):
super(Value, self).__init__()
resourcespecs = RESOURCE_SPECS['us-east-1']
self.resourcetypes = resourcespecs['ResourceTypes']

Expand Down
2 changes: 2 additions & 0 deletions src/cfnlint/rules/parameters/AvailabilityZone.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class AvailabilityZone(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(AvailabilityZone, self).__init__()
self.multiple_resource_type_specs = [
'AWS::DAX::Cluster',
'AWS::AutoScaling::AutoScalingGroup',
Expand All @@ -40,6 +41,7 @@ def __init__(self):
'AWS::OpsWorks::Instance',
'AWS::RDS::DBInstance',
'AWS::EC2::Host',
'AWS::EC2::Subnet',
'AWS::DMS::ReplicationInstance',
'AWS::EC2::Instance'
]
Expand Down
3 changes: 2 additions & 1 deletion src/cfnlint/rules/parameters/Cidr.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ class Cidr(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(Cidr, self).__init__()
resource_type_specs = [
'AWS::EC2::Subnet',
'AWS::EC2::Vpc',
'AWS::EC2::VPC',
'AWS::RDS::DBSecurityGroupIngress',
'AWS::EC2::NetworkAclEntry',
'AWS::EC2::SecurityGroupIngress',
Expand Down
3 changes: 2 additions & 1 deletion src/cfnlint/rules/parameters/CidrAllowedValues.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class CidrAllowedValues(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(CidrAllowedValues, self).__init__()
resource_type_specs = [
'AWS::EC2::Subnet',
'AWS::EC2::Vpc',
'AWS::EC2::VPC',
'AWS::RDS::DBSecurityGroupIngress',
'AWS::EC2::NetworkAclEntry',
'AWS::EC2::SecurityGroupIngress',
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/parameters/LambdaMemorySize.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class LambdaMemorySize(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(LambdaMemorySize, self).__init__()
resource_type_specs = [
'AWS::Lambda::Function',
]
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/parameters/LambdaRuntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class LambdaRuntime(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(LambdaRuntime, self).__init__()
resource_type_specs = [
'AWS::Lambda::Function',
]
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/parameters/SecurityGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SecurityGroup(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(SecurityGroup, self).__init__()
resource_type_specs = [
'AWS::ElasticLoadBalancingV2::LoadBalancer',
'AWS::AutoScaling::LaunchConfiguration',
Expand Down
14 changes: 8 additions & 6 deletions src/cfnlint/rules/resources/events/RuleTargetsLimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ class RuleTargetsLimit(CloudFormationLintRule):

def __init__(self):
"""Init"""
self.resource_property_types.append('AWS::Events::Rule')
super(RuleTargetsLimit, self).__init__()
self.resource_property_types = ['AWS::Events::Rule']
self.limits = {}

# pylint: disable=W0613
def check_value(self, value, path):
"""Count them up """
if path[4] == 'Fn::If':
resource_name = '%s.%s' % (path[1], path[5])
else:
resource_name = path[1]

resource_name = path[1]
if len(path) > 4:
if path[4] == 'Fn::If':
resource_name = '%s.%s' % (path[1], path[5])

if resource_name not in self.limits:
self.limits[resource_name] = {
'count': 0,
Expand All @@ -51,7 +54,6 @@ def check_value(self, value, path):
def match_resource_properties(self, properties, _, path, cfn):
"""Check CloudFormation Properties"""
matches = []

matches.extend(
cfn.check_value(
obj=properties, key='Targets',
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/resources/iam/Policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Policy(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(Policy, self).__init__()
self.resource_exceptions = {
'AWS::ECR::Repository': 'RepositoryPolicyText',
}
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/resources/iam/PolicyVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PolicyVersion(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(PolicyVersion, self).__init__()
self.resources_and_keys = {
'AWS::SNS::TopicPolicy': 'PolicyDocument',
'AWS::S3::BucketPolicy': 'PolicyDocument',
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/resources/properties/AtLeastOne.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AtLeastOne(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(AtLeastOne, self).__init__()
atleastonespec = cfnlint.helpers.load_resources('data/AdditionalSpecs/AtLeastOne.json')
self.resource_types_specs = atleastonespec['ResourceTypes']
self.property_types_specs = atleastonespec['PropertyTypes']
Expand Down
2 changes: 2 additions & 0 deletions src/cfnlint/rules/resources/properties/AvailabilityZone.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AvailabilityZone(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(AvailabilityZone, self).__init__()
resource_type_specs = [
'AWS::DAX::Cluster',
'AWS::AutoScaling::AutoScalingGroup',
Expand All @@ -36,6 +37,7 @@ def __init__(self):
'AWS::OpsWorks::Instance',
'AWS::RDS::DBInstance',
'AWS::EC2::Host',
'AWS::EC2::Subnet',
'AWS::DMS::ReplicationInstance',
'AWS::EC2::Instance'
]
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/resources/properties/Exclusive.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Exclusive(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(Exclusive, self).__init__()
exclusivespec = cfnlint.helpers.load_resources('data/AdditionalSpecs/Exclusive.json')
self.resource_types_specs = exclusivespec['ResourceTypes']
self.property_types_specs = exclusivespec['PropertyTypes']
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/resources/properties/Inclusive.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Inclusive(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(Inclusive, self).__init__()
inclusivespec = cfnlint.helpers.load_resources('data/AdditionalSpecs/Inclusive.json')
self.resource_types_specs = inclusivespec['ResourceTypes']
self.property_types_specs = inclusivespec['PropertyTypes']
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/resources/properties/OnlyOne.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class OnlyOne(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(OnlyOne, self).__init__()
onlyonespec = cfnlint.helpers.load_resources('data/AdditionalSpecs/OnlyOne.json')
self.resource_types_specs = onlyonespec['ResourceTypes']
self.property_types_specs = onlyonespec['PropertyTypes']
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/resources/properties/Properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Properties(CloudFormationLintRule):
tags = ['resources']

def __init__(self):
super(Properties, self).__init__()
self.cfn = {}
self.resourcetypes = {}
self.propertytypes = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class PropertiesTemplated(CloudFormationLintRule):
tags = ['resources']

def __init__(self):
super(PropertiesTemplated, self).__init__()
self.resource_property_types.extend([
'AWS::ApiGateway::RestApi',
'AWS::Lambda::Function',
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/resources/properties/Required.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Required(CloudFormationLintRule):
cfn = {}

def __init__(self):
super(Required, self).__init__()
resourcespecs = cfnlint.helpers.RESOURCE_SPECS['us-east-1']
self.resourcetypes = resourcespecs['ResourceTypes']
self.propertytypes = resourcespecs['PropertyTypes']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ValuePrimitiveType(CloudFormationLintRule):

def __init__(self, ):
"""Init """
super(ValuePrimitiveType, self).__init__()
specs = cfnlint.helpers.RESOURCE_SPECS.get('us-east-1')
self.property_specs = specs.get('PropertyTypes')
self.resource_specs = specs.get('ResourceTypes')
Expand Down
1 change: 1 addition & 0 deletions src/cfnlint/rules/resources/stepfunctions/StateMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class StateMachine(CloudFormationLintRule):

def __init__(self):
"""Init"""
super(StateMachine, self).__init__()
self.resource_property_types.append('AWS::StepFunctions::StateMachine')

def _check_state_json(self, def_json, state_name, path):
Expand Down

0 comments on commit 4765ff5

Please sign in to comment.