3 D\)@sLdZddlZddlmZddlmZddlmZddlZGdddeZdS)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@sZeZdZdZdZdZdZdgZddZdd Z d d Z d d Z ddZ ddZ ddZdS)ValueRefGetAttz(Check if Resource Properties are correctZE3008z5Check values of properties for valid Refs and GetAttsz4Checks resource properties for Ref and GetAtt values resourcescCs\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/ValueRefGetAtt.py initializeszValueRefGetAtt.initializecCsB|d|kr>t|dtr:|d dkr:|j|dd |SdSdS) aQ Determines if the value checked is a list or a value in a list We need to handle conditions in the path that could be nested, etc. ['Resources', 'LoadBalancer', 'Properties', 'Subnets', 'Fn::If', 2, 'Fn::If', 2] Numbers preceeded by a Fn::If should be removed and check repeated. zFn::IfNFTrr) isinstanceintis_value_a_list)r path property_namerrrr&s  zValueRefGetAtt.is_value_a_listc Ks*t}|jd}|jdijd}|jdijd}|jd}|jd} |ddkrv|dkrv|j|d d| rv|} n|} | s|S||jjd ikrr|jjd j|i} | jd } g} xB| jd D]4}x.tj|jd jd j|D]}| j|qWqW| jd s2d}|jt||j| dj t t |n@| | krrd}|jt||j| dj t t | dj t t |||jjdikr&|jjdj|i}|jd }| jdsd}|jt||j| dj t t |nL|| jdkr&d}|jt||j| dj t t | jddj t t ||S)z Check Refr value_specsZReflist_value_specs property_typerrListNZ ParametersTyperZParameterTypesz5Property "{0}" has no valid Refs to Parameters at {1}/z9Property "{0}" can Ref to parameter of types [{1}] at {2}z, Resourcesz4Property "{0}" has no valid Refs to Resources at {1}z9Property "{0}" can Ref to resources of types [{1}] at {2}rr) listr rtemplaterr r rformatjoinmapstr)r valuerkwargsmatchesr rrrrspecsparamZparameter_typeZvalid_parameter_typesZ parameterZ param_typemessageresource resource_typerrrcheck_value_ref7s\   ( " &   &zValueRefGetAtt.check_value_refc Ks:g}|jd}|jdijd}|jdijd}|jd}|jd} t|tr|d} t|dd dkr||djd } q|dd } n,t|tjr|jd d} |jd dd } |j|d d| } |dd kr|d kr| r|} n|} |jjd ij| ijd}t j j |r|S|dkrl| ddkrl| rh|d krhd}|j t ||jdjtt||S| d krz|S| sd}|j t ||j| djtt||S|| krd}|j t ||j| djtt| djtt|nHd jtt| | |kr6d}|j t ||j| | |djtt||S)z Check GetAttr rZGetAttrrrrrN.z Fn::GetAttrr rzAWS::CloudFormation::StackZOutputsz@CloudFormation stack outputs need to be strings not lists at {0}rz5Property "{0}" has no valid Fn::GetAtt options at {1}zAProperty "{0}" can Fn::GetAtt to a resource of types [{1}] at {2}z, zBProperty "{0}" can Fn::GetAtt to a resource attribute "{1}" at {2}rr)r rr!lensplitsix string_typesrr"cfnlintZhelpersZis_custom_resourcer rr#r$r%r&)r r'rr(r)r rrrr resource_nameZresource_attributerr*r.r,rrrcheck_value_getattpsf     " $ z!ValueRefGetAtt.check_value_getattcCst}x|j|ddD]\}}x|D]} | |kr(|j| jdi} | r(| jdd} | jdd} |jdj| jd} |j|j|| ||j|jtj|jdjd j| itj|jdjd j| i|| | d q(WqW|S) z Check itselfNValueZ ValueTypeZ ListValueType PropertiesrrZ ValueTypes)Z check_refZ check_get_attrrr rr) r!Z items_safer extend check_valuer/r7rr )r r propertiesrproperty_specsrr)Zp_valuep_pathpropr'Z value_typeZlist_value_typerrrrchecks$   zValueRefGetAtt.checkcCsdt}tj|jdjdj|ijdi}tj|jdjdj|}|j|j||||||S)zMatch for sub propertiesrrr:)r!rr r r;rA)r r=rrr r)r*r>rrrmatch_resource_sub_propertiess &z,ValueRefGetAtt.match_resource_sub_propertiescCsdt}tj|jdjdj|ijdi}tj|jdjdj|}|j|j||||||S)zCheck CloudFormation Propertiesrrr:)r!rr r r;rA)r r=r.rr r)r*Zresource_specsrrrmatch_resource_propertiess &z(ValueRefGetAtt.match_resource_propertiesN)__name__ __module__ __qualname____doc__idZ shortdesc descriptiontagsrrr/r7rArBrCrrrrrs9F r)rGr3r5rrZcfnlint.helpersrrrrrrs