3 D\@s<dZddlmZddlmZddlmZGdddeZdS)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) RuleMatch) REGEX_CIDRcsXeZdZdZdZdZdZdZddgZfdd Z d d Z d d Z ddZ ddZ ZS)Cidrz)Check Availability Zone parameter checks ZW2509z#CIDR Parameters have allowed valueszhCheck if a parameter is being used as a CIDR. If it is make sure it has allowed values regex comparisonsz`https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html parametersZavailabilityzonecsftt|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__w/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/parameters/Cidr.pyr s"  z Cidr.__init__c Csg}||kr~|j|i}|jd}|jdd}|jdd} |d kr~| r~| r~d|g} dj| } d} |jt| | jtj| |S) zCheck ref for VPCTypeZAllowedPatternNZ AllowedValues"AWS::SSM::Parameter::ValueZ Parameters/zoAllowedPattern and/or AllowedValues for Parameter should be specified at {1}. Example for AllowedPattern: "{0}")r)getjoinr rformatrpattern) r valuepathr resourcesmatchesZ parameterZparameter_typeZallowed_patternZallowed_valuesZ param_pathZfull_param_pathmessager r r check_cidr_ref;s      zCidr.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_joinrZ CidrBlockZCidrIp)extendrr)r properties resource_typercfnrr r r checkNs,z Cidr.checkcCsg}|j|j|||||S)zMatch for sub properties)rr )r rZ property_typerrrr r r match_resource_sub_propertiesqsz"Cidr.match_resource_sub_propertiescCsg}|j|j|||||S)zCheck CloudFormation Properties)rr )r rrrrrr r r match_resource_propertiesyszCidr.match_resource_properties)__name__ __module__ __qualname____doc__idZ shortdesc descriptionZ source_urltagsrrr r!r" __classcell__r r )r r rs #rN)r&ZcfnlintrrZcfnlint.helpersrrr r r r s