3 Dã\ ã@s0dZddlmZddlmZGdd„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. é)ÚCloudFormationLintRule)Ú RuleMatchc@s@eZdZdZdZdZdZdZddgZdd „Z d d „Z d d „Z dS)ÚDependsOnObsoletez.Check unneeded DepensOn Resource ConfigurationZW3005z4Check obsolete DependsOn configuration for ResourceszgCheck if DependsOn is specified if not needed. A Ref or a Fn::GetAtt already is an implicit dependency.zJhttps://aws.amazon.com/blogs/devops/optimize-aws-cloudformation-templates/Ú resourcesZ dependsoncs.|j|ƒ}tdd„|ƒ}t‡fdd„|ƒ}|S)z1Get tree of all resource references of a resourcecSs |ddkS)NrÚ Resources©)Úxrrúƒ/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/resources/DependsOnObsolete.pyÚ%sz;DependsOnObsolete.get_resource_references..cs |dˆkS)Nér)r)Úresourcerr r )s)Zsearch_deep_keysÚfilter)ÚselfÚcfnZ ref_functionr Útreesr)r r Úget_resource_referencess z)DependsOnObsolete.get_resource_referencesc Cs¬g}|j|d|ƒ}x@|D]8}|d|krd}|jt||j|djtt|ƒƒƒƒƒqW|j|d|ƒ}xD|D]<}|d d|krhd}|jt||j|djtt|ƒƒƒƒƒqhW|S) z+Check if the DependsOn is already specifiedZRefr zSObsolete DependsOn on resource ({0}), dependency already enforced by a "Ref" at {1}ú/z Fn::GetAttrzYObsolete DependsOn on resource ({0}), dependency already enforced by a "Fn:GetAtt" at {1}éÿÿÿÿr)rÚappendrÚformatÚjoinÚmapÚstr) rrr ÚkeyÚpathÚmatchesrÚtreeÚmessagerrr Úcheck_depends_on-s  ( (z"DependsOnObsolete.check_depends_onc Cs¨g}|jƒ}x–|jƒD]Š\}}|jdƒ}|rd|dg}|jjd|ƒt|tƒrŠxPt|ƒD],\}} |j|j ||| |dd…|gƒƒqXWq|j|j ||||ƒƒqW|S)zCheck CloudFormation ResourcesZ DependsOnrz$Validating unneeded DependsOn for %sN) Ú get_resourcesÚitemsÚgetÚloggerÚdebugÚ isinstanceÚlistÚ enumerateÚextendr) rrrrÚ resource_nameZresource_valuesZ depends_onsrÚindexZ depends_onrrr ÚmatchDs   *zDependsOnObsolete.matchN) Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚidZ shortdescÚ descriptionZ source_urlÚtagsrrr*rrrr rsrN)r.Zcfnlintrrrrrrr Ús