3 D\ @s0dZddlmZddlmZGdddeZdS)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) RuleMatchcsHeZdZdZdZdZdZdZddgZfdd Z d d Z d d Z Z S) RefWithPathz&Check if IAM Policy Version is correctZE3050z/Check if REFing to a IAM resource with path setzSome resources don't support looking up the IAM resource by name. This check validates when a REF is being used and the Path is not '/'zQhttps://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html propertiesZiamcs8tt|jddi|_x|jD]}|jj|q WdS)ZInitzAWS::CodeBuild::ProjectZ ServiceRoleN)superr__init__resources_and_keysZresource_property_typesappend)selfZ resource_type) __class__/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/resources/iam/RefWithPath.pyrs  zRefWithPath.__init__cCsLg}|j|ijdijd}|s&|S|dkrHd}|jt||j||S)z Check Ref Z PropertiesPath/zdWhen using a Ref to IAM resource the Path must be '/'. Switch to GetAtt if the Path has to be '{}'.)getr rformat)r value parameters resourcespathmatchesZiam_pathmessager r r check_ref(szRefWithPath.check_refcCs<g}d}||jkr|jj|}|j|j||||jd|S)zCheck CloudFormation PropertiesN)r)rrextend check_valuer)r rZ resourcetyperZcfnrkeyr r r match_resource_properties7s   z%RefWithPath.match_resource_properties) __name__ __module__ __qualname____doc__idZ shortdesc descriptionZ source_urltagsrrr __classcell__r r )r r rs rN)r Zcfnlintrrrr r r r s