3 D\@sDdZddlZddlmZddlmZddlmZGdddeZdS)a Copyright 2018 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) PSEUDOPARAMS)CloudFormationLintRule) RuleMatchc@s0eZdZdZdZdZdZdZddgZdd Z d S) RelationshipConditionsz7Check if Ref/GetAtt values are available via conditionsZW1001zDRef/GetAtt to resource that is available when conditions are appliedzCheck the Conditions that affect a Ref/GetAtt to make sure the resource being related to is available when there is a resource condition.zdhttps://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html resourcesZ relationshipsc Cshg}|jd}x|D]}|d}|tkr|j||}x^|D]V}djdd|jD}d} |jt|dd| j||djtt |ddq:WqW|jd } x| D]} | d} d}t | t r| d }nt | t j r| jd d }|r|tkr|j| |}x`|D]X}djd d|jD}d } |jt| dd| j||djtt | ddqWqW|S)z.Check CloudFormation Ref/GetAtt for ConditionsZRefz and cSsg|]\}}d||fqS)zwhen condition "%s" is %s).0kvrr/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/functions/RelationshipConditions.py .sz0RelationshipConditions.match..z:Ref to resource "{0}" that may not be available {1} at {2}N/z Fn::GetAttr.cSsg|]\}}d||fqS)zwhen condition "%s" is %sr)r r r rrr r Fsz=GetAtt to resource "{0}" that may not be available {1} at {2}rrrrr)Zsearch_deep_keysrZis_resource_availablejoinitemsappendrformatmapstr isinstancelistsix string_typessplit) selfZcfnmatchesZref_objsZref_objvalueZ scenariosZscenarioZ scenario_textmessageZ getatt_objsZ getatt_objZ value_objrrr match!sP     &        (zRelationshipConditions.matchN) __name__ __module__ __qualname____doc__idZ shortdesc descriptionZ source_urltagsr rrrr rsr)r$rZcfnlint.helpersrZcfnlintrrrrrrr s