3 Dã\òã@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@s~eZdZdZdZdZdZdZddgZdd d d d gZ d dgZ ddddddddddddddgZ dd„Z dd „Z d!d"„Zd#d$„Zd%S)&Ú SubNeededzECheck if a substitution string exists without a substitution functionZE1029z1Sub is required if a variable is used in a stringzsIf a substitution variable exists in a string but isn't wrapped with the Fn::Sub function the deployment will fail.zdhttps://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.htmlZ functionsÚsubZUserDataÚZipFileÚ ConditionzAWS::CloudFormation::InitZCloudWatchAlarmDefinitionZUriZBodyz${aws:CurrentTime}z${aws:EpochTime}z${aws:TokenIssueTime}z${aws:principaltype}z${aws:SecureTransport}z${aws:SourceIp}z${aws:UserAgent}z ${aws:userid}z${aws:username}z${ec2:SourceInstanceARN}z!${iot:Connection.Thing.ThingName}z%${iot:Connection.Thing.ThingTypeName}z"${iot:Connection.Thing.IsAttached}z${iot:ClientId}c Csâg}t|tƒrLxÎ|D]2}|dd…}|j|ƒ|j|j||||ƒƒqWn’t|tƒr˜x†t|ƒD]2\}}|dd…}|j|ƒ|j|j|||ƒƒq`WnFt|tƒrÞtj ||ƒrÞtj dƒ} x$tj | |ƒD]} |j|| gƒqÆW|S)z6Recursively search for values matching the searchRegexNz(\$\{.*?\.?.*?})) Ú isinstanceÚdictÚappendÚextendÚ _match_valuesÚlistÚ enumerateÚstrÚreÚmatchÚcompileÚfindall) ÚselfÚ searchRegexZcfnelemÚpathÚvaluesÚkeyZpathpropÚindexÚitemÚregexÚvariable©rú{/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/functions/SubNeeded.pyr ,s         zSubNeeded._match_valuescCs<g}|j|j||jgƒƒ|j|j||jjdiƒgƒƒ|S)z` Search for values in all parts of the templates that match the searchRegex ZGlobals)r r ÚtemplateÚget)rrÚcfnÚresultsrrrÚ match_valuesCszSubNeeded.match_valuescCstjdƒ}tj||ƒS)z Key value exceptions z^\$\{stageVariables\..*\}$)rrr)rÚvalueÚparameter_searchrrrÚ_api_exceptionsMs zSubNeeded._api_exceptionsc CsÐg}tjdƒ}|j||ƒ}x°|D]¨}|d }d|kr@||jkr@q |jdƒrLq d}x@|D]8}||jkrx|j|d ƒrŽd}qV|dksŠ||jkrVd}qVW|s |dd …} d jd j t t | ƒƒƒ} |j t | | ƒƒq W|S)zBasic Rule Matchingz^.*(\$\{.*\}.*(\$\{.*\}.*)*)$éÚResourcez${!FTzFn::SubNz9Found an embedded parameter outside of an "Fn::Sub" at {}ú/éÿÿÿÿr*r*)rrr#Úresource_excludesÚ startswithÚ api_excludesr&ÚexcludesÚformatÚjoinÚmaprr r) rr!Úmatchesr%Zparameter_string_pathsZparameter_string_pathrZ found_subÚsteprÚmessagerrrrRs,        zSubNeeded.matchN)Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚidZ shortdescÚ descriptionZ source_urlÚtagsr.r-r+r r#r&rrrrrrs" r)r8rZcfnlintrrrrrrrÚs