3 Dã\2ã@s8dZddlZddlmZddlmZGdd„deƒZdS)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)Ú RuleMatchc@sXeZdZdZdZdZdZdZddgZdd gZ d d „Z d d „Z dd„Z dd„Z dd„ZdS)Ú FindInMapz%Check if FindInMap values are correctZE1011z%FindInMap validation of configurationz8Making sure the function is a list of appropriate configzjhttps://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.htmlZ functionsÚ findinmapz Fn::FindInMapZRefc CsÂg}t|tƒr¾t|ƒdkr€x¢|jƒD]V\}}||jkr$d}|jt|dd…|g|jdjt t |jƒƒdjt t |ƒƒƒƒƒq$Wn>d}|jt|dd…|jdjt t |jƒƒdjt t |ƒƒƒƒƒ|S)zy Check that obj is a dict with Ref as the only key Mappings only support Ref inside them éz.FindInMap only supports [{0}] functions at {1}Nz, ú/z@FindInMap only supports an object of 1 of [{0}] functions at {1}) Ú isinstanceÚdictÚlenÚitemsÚsupported_functionsÚappendrÚformatÚjoinÚmapÚstr)ÚselfÚobjÚtreeÚmatchesZkey_nameÚ_Úmessage©rú{/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/functions/FindInMap.pyÚ check_dict#s$    zFindInMap.check_dictc CsÈg}t|tjtfƒr€t|tƒr@|j|j||dd…dgƒƒqÄ||krÄd}|jt|dd…dg|j|dj t t |ƒƒƒƒƒnDd}|jt|dd…dg|jdj t t |j ƒƒdj t t |ƒƒƒƒƒ|S)z Check the map name Nrz!Map Name {0} doesnt exist for {0}rz*Map Name should be a {0}, or string at {1}z, ) rÚsixÚ string_typesr Úextendrr rrrrrr )rÚmap_nameÚmappingsrrrrrrr>s ".zFindInMap.map_namec CsŒg}t|tjtfƒr|St|tƒrD|j|j||dd…dgƒƒnDd}|jt|dd…dg|j dj t t |j ƒƒdj t t |ƒƒƒƒƒ|S)z% Check the validity of the first key Nrz:FindInMap first key should be a {0}, string, or int at {1}z, r)rrrÚintr rrr rrrrrr )rÚ first_keyrrrrrrr!Ss "zFindInMap.first_keyc CsŒg}t|tjtfƒr|St|tƒrD|j|j||dd…dgƒƒnDd}|jt|dd…dg|j dj t t |j ƒƒdj t t |ƒƒƒƒƒ|S)z& Check the validity of the second key Néz;FindInMap second key should be a {0}, string, or int at {1}z, r)rrrr r rrr rrrrrr )rÚ second_keyrrrrrrr#ds "zFindInMap.second_keyc Csg}|jdƒ}|jƒ}xæ|D]Þ}|dd …}|d }t|tƒshd}|jt|dd…|jdj|ƒƒƒƒqt|ƒdkrÆ|d} |d} |d} |j |j | ||ƒƒ|j |j | |ƒƒ|j |j | |ƒƒqd}|jt|dd…dg|jdjt t|ƒƒƒƒƒqW|S) zCheck CloudFormation GetAttz Fn::FindInMapNrz)FindInMap is a list with 3 values for {0}rérr"éÿÿÿÿr%)Zsearch_deep_keysZ get_mappingsrÚlistr rrrr rrr!r#rr) rZcfnrZ findinmapsrrrZmap_objrrr!r#rrrÚmatchvs,     .zFindInMap.matchN)Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚidZ shortdescÚ descriptionZ source_urlÚtagsr rrr!r#r'rrrrrsr)r+rZcfnlintrrrrrrrÚs