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)RESOURCE_SPECSc@sTeZdZdZdZdZdZdZdddd gZd d Z d d Z ddZ ddZ ddZ dS)AllowedPatternz&Check if properties have a valid valueZE3031z5Check if property values adhere to a specific patternzPCheck if properties have a valid value in case of a pattern (Regular Expression)zhhttps://github.com/awslabs/cfn-python-lint/blob/master/docs/cfn-resource-specification.md#allowedpattern resourcespropertyzallowed patternregexcCs\x*tj|jdjdD]}|jj|qWx*tj|jdjdD]}|jj|qDWdS)zInitialize the ruler ResourceTypes PropertyTypesN)rgetregionsZresource_property_typesappendZresource_sub_property_types)selfcfnZresource_type_specZproperty_type_specr/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/resources/properties/AllowedPattern.py initialize szAllowedPattern.initializec Ksg}|jdijdi}|jdijd|}|r~tj|}d|kr~|j|s~djdd|D} d} |jt|| j||| |S) z Check Value value_specsZAllowedPatternRegexrz {{resolve:/css|]}t|VqdS)N)str).0xrrr 8sz-AllowedPattern.check_value..z2{} contains invalid characters (Pattern: {}) at {})r recompilematchjoinr rformat) rvaluepath property_namekwargsmatchesZvalue_pattern_regexZ value_patternr full_pathmessagerrr check_value's  zAllowedPattern.check_valuec Cst}x|j|ddD]\}}x|D]} | |kr(|j| jdi} | r(| jdd} |jdj| jd} |j|j|| ||jtj|jdjdj| i|| | d q(WqW|S) z Check itselfNValueZ ValueType PropertiesTyperZ ValueTypes)r%rr property_typer )listZ items_safer extendr%rr ) rr propertiesrproperty_specsrr"Zp_valuep_pathproprZ value_typer*rrrcheck?s  zAllowedPattern.checkcCsdt}tj|jdjdj|ijdi}tj|jdjdj|}|j|j||||||S)zMatch for sub propertiesrr r()r+rr r r,r1)rr-r*rrr"specsr.rrrmatch_resource_sub_propertiesSs &z,AllowedPattern.match_resource_sub_propertiescCsdt}tj|jdjdj|ijdi}tj|jdjdj|}|j|j||||||S)zCheck CloudFormation Propertiesrr r()r+rr r r,r1)rr-Z resource_typerrr"r2Zresource_specsrrrmatch_resource_properties]s &z(AllowedPattern.match_resource_propertiesN)__name__ __module__ __qualname____doc__idZ shortdesc descriptionZ source_urltagsrr%r1r3r4rrrrrs  r)r8rZcfnlintrrZcfnlint.helpersrrrrrrs