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@sReZdZdZdZdZdZdZdddgZdd Z d d Z d d Z ddZ ddZ dS) AllowedValuez&Check if parameters have a valid valueZW2030zCheck if parameters have a valid value in case of an enumator. The Parameters allowed values is based on the usages in property (Ref)zqhttps://github.com/aws-cloudformation/cfn-python-lint/blob/master/docs/cfn-resource-specification.md#allowedvalue resourcespropertyz allowed valuecCs\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/parameters/AllowedValue.py initialize szAllowedValue.initializecKs.g}|jdijdi}|jd}|r*||jjdikr*|jjdj|i}|jd}|jd}|jd} t| tjr*| jd o| jd o| d kr*|rxJt|D]>\} } t| |krd|d| g} d } |jt | | j || |qW|r*t||kr*d|dg} d } |jt | | j ||||S)z Check Ref value_specsZ AllowedValuesrZ ParametersZDefaultTypezListzJYou must specify a valid allowed value for {0} ({1}). Valid values are {2}zJYou must specify a valid Default value for {0} ({1}). Valid values are {2})rr) r template isinstancesix string_types startswith enumeratestrr rformat)r valuekwargsmatchesZallowed_value_specsrparamZparameter_values default_valueZparameter_typeindexZ allowed_valueZ param_pathmessagerrrcheck_value_ref's2          zAllowedValue.check_value_refc 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 PropertiesrrZ ValueTypes)Z check_refrr property_typeZ property_name)listZ items_safer extend check_valuer%rr ) r r propertiesrproperty_specspathr Zp_valuep_pathproprZ value_typer)rrrcheckHs  zAllowedValue.checkcCsdt}tj|jdjdj|ijdi}tj|jdjdj|}|j|j||||||S)zMatch for sub propertiesrr r()r*rr r r+r2)r r-r)r/rr specsr.rrrmatch_resource_sub_properties]s &z*AllowedValue.match_resource_sub_propertiescCsdt}tj|jdjdj|ijdi}tj|jdjdj|}|j|j||||||S)zCheck CloudFormation Propertiesrrr()r*rr r r+r2)r r-Z resource_typer/rr r3Zresource_specsrrrmatch_resource_propertiesgs &z&AllowedValue.match_resource_propertiesN)__name__ __module__ __qualname____doc__idZ shortdesc descriptionZ source_urltagsrr%r2r4r5rrrrrs ! r)r9rZcfnlintrrZcfnlint.helpersrrrrrrs