3 D\@sDdZddlZddlmZddlmZddlmZGdddeZdS)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. N)CloudFormationLintRule) RuleMatch) REGEX_CIDRcsXeZdZdZdZdZdZdZddgZfdd Z d d Z d d Z ddZ ddZ ZS)CidrAllowedValuesz)Check Availability Zone parameter checks ZE2004z*CIDR Allowed Values should be a Cidr Rangez`Check if a parameter is being used as a CIDR. If it is make sure allowed values are proper CIDRsz`https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html parameterscidrcsftt|jddddddddg}d d d d g}x|D]}|jj|q4Wx|D]}|jj|qNWd S)ZInitzAWS::EC2::Subnetz AWS::EC2::VPCz AWS::RDS::DBSecurityGroupIngresszAWS::EC2::NetworkAclEntryzAWS::EC2::SecurityGroupIngresszAWS::EC2::SecurityGroupEgressz*AWS::Redshift::ClusterSecurityGroupIngresszAWS::EC2::VPCCidrBlockz!AWS::RDS::DBSecurityGroup.IngresszAWS::EC2::SecurityGroup.Egressz AWS::SES::ReceiptFilter.IpFilterzAWS::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/CidrAllowedValues.pyr !s"  zCidrAllowedValues.__init__c Cshg}||krd|j|i}|jdd}|rdx:|D]2}tjt|s.d|g} d} |jt| | j|q.W|S)zCheck ref for VPCZ AllowedValuesNZ Parametersz0Cidr should be a Cidr Range based string for {0})getrematchrr rformat) r valuepathr resourcesmatchesZ parameterZallowed_valuesrZ cidr_pathmessager r rcheck_cidr_ref<s    z CidrAllowedValues.check_cidr_refc Csg}|j|j|d|d|jdddd|j|j|d|d|jdddd|j|j|d|d|jdddd|j|j|d|d|jdddd|S)z Check itselfZCIDRIPN) check_valueZ check_refZcheck_find_in_mapZ check_splitZ check_joinZCidrZ CidrBlockZCidrIp)extendrr)r properties resource_typercfnrr r rcheckLs,zCidrAllowedValues.checkcCsg}|j|j|||||S)zMatch for sub properties)rr)r rZ property_typerrrr r rmatch_resource_sub_propertiesosz/CidrAllowedValues.match_resource_sub_propertiescCsg}|j|j|||||S)zCheck CloudFormation Properties)rr)r rrrrrr r rmatch_resource_propertieswsz+CidrAllowedValues.match_resource_properties)__name__ __module__ __qualname____doc__idZ shortdesc descriptionZ source_urltagsr rrrr __classcell__r r )r rrs #r)r$rZcfnlintrrZcfnlint.helpersrrr r r rs