3 D\@s0dZddlmZddlmZGdddeZdS)a Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. )CloudFormationLintRule) RuleMatchcsXeZdZdZdZdZdZdZddgZfdd Z d d Z d d Z ddZ ddZ ZS) SecurityGroupz.Check if EC2 Security Group Ingress PropertiesZW2507zISecurity Group Parameters are of correct type AWS::EC2::SecurityGroup::IdzCheck if a parameter is being used in a resource for Security Group. If it is make sure it is of type AWS::EC2::SecurityGroup::Idz\https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html#parmtypes parametersZ securitygroupc sltt|jdddddddddg }dd d d d d g}x|D]}|jj|q:Wx|D]}|jj|qTWdS)ZInitz)AWS::ElasticLoadBalancingV2::LoadBalancerz%AWS::AutoScaling::LaunchConfigurationzAWS::EC2::Instancez"AWS::ElastiCache::ReplicationGroupzAWS::DAX::ClusterzAWS::Glue::DevEndpointzAWS::EC2::SecurityGroupIngressz+AWS::EC2::LaunchTemplate.LaunchTemplateDataz%AWS::Elasticsearch::Domain.VPCOptionszAWS::Lambda::Function.VpcConfigz/AWS::Batch::ComputeEnvironment.ComputeResourcesz!AWS::CodeBuild::Project.VpcConfigzAWS::EC2::SecurityGroup.IngressN)superr__init__Zresource_property_typesappendZresource_sub_property_types)selfZresource_type_specsZproperty_type_specsZresource_type_specZproperty_type_spec) __class__/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/parameters/SecurityGroup.pyrs(  zSecurityGroup.__init__c Csg}d|krddg}n t|d tr.ddg}nddg}||kr|j|}|jd}||krd|dg} d } |jt| | jd jtt|d jtt| |S) zCheck ref for VPCSourceSecurityGroupIdz7AWS::SSM::Parameter::ValuezAWS::EC2::SecurityGroup::Idz=AWS::SSM::Parameter::Value>z!ListTypeZ Parametersz;Security Group Id Parameter should be of type [{0}] for {1}z, /) isinstanceintgetrrformatjoinmapstr) r valuepathr resourcesmatchesZ allowed_typesZparameter_propertiesZparameter_typeZ path_errormessager r r check_sgid_ref<s,   zSecurityGroup.check_sgid_refc Csng}|j|j|d|d|jdddd|j|j|d|d|jdddd|j|j|d|d|jdddd|S)z Check itselfZSecurityGroupIdsN) check_valueZ check_refZcheck_find_in_mapZ check_splitZ check_joinZSecurityGroupsr )extendrr)r properties resource_typercfnrr r r check^s"zSecurityGroup.checkcCsg}|j|j|||||S)zMatch for sub properties)r r$)r r!Z property_typerr#rr r r match_resource_sub_propertieszsz+SecurityGroup.match_resource_sub_propertiescCsg}|j|j|||||S)zCheck CloudFormation Properties)r r$)r r!r"rr#rr r r match_resource_propertiessz'SecurityGroup.match_resource_properties)__name__ __module__ __qualname____doc__idZ shortdesc descriptionZ source_urltagsrrr$r%r& __classcell__r r )r r rs "rN)r*Zcfnlintrrrr r r r s