3 D\@sHdZddlZddlZddlmZddlmZddlZGdddeZdS)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) RuleMatchcspeZdZdZdZdZdZdZddgZfdd Z d d Z d d Z ddZ ddZ ddZddZddZZS)DynamicReferenceSecureStringzPCheck if Dynamic Reference Secure Strings are only used in the correct locationsZE1027zBCheck dynamic references secure strings are in supported locationsa!Dynamic References Secure Strings are only supported for a small set of resource properties. Validate that they are being used in the correct location when checking values and Fn::Sub in resource properties. Currently doesn't check outputs, maps, conditions, parameters, and descriptions.zVhttps://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.htmlZ functionszdynamic referencec s<tt|jg|_g|_dddddddddddd |_dS)zInit ZPasswordZ AuthTokenZ DbPasswordZMasterUserPassword) z"AWS::DirectoryService::MicrosoftADzAWS::DirectoryService::SimpleADz"AWS::ElastiCache::ReplicationGroupzAWS::IAM::User.LoginProfilezEAWS::KinesisFirehose::DeliveryStream.RedshiftDestinationConfigurationzAWS::OpsWorks::App.SourcezAWS::OpsWorks::Stack.Sourcez"AWS::OpsWorks::Stack.RdsDbInstancezAWS::RDS::DBClusterzAWS::RDS::DBInstancezAWS::Redshift::ClusterN)superr__init__property_specsresource_specs exceptions)self) __class__/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/functions/DynamicReferenceSecureString.pyr#sz%DynamicReferenceSecureString.__init__cCshtjjj|jd}|jd|_|jd|_x|jD]}|jj|q4Wx|jD]}|j j|qPWdS)zInit rZ PropertyTypesZ ResourceTypesN) cfnlinthelpersZRESOURCE_SPECSgetZregionsrrZresource_property_typesappendZresource_sub_property_types)r cfnspecsZ resource_specZ property_specr r r initialize6s    z'DynamicReferenceSecureString.initializecCsXg}t|tjrTtjtjj|rTddjt t |dd}|j t |dd||S)zChec item typezJDynamic Reference secure strings are not supported for this property at %s/N) isinstancesix string_typesrematchrrZREGEX_DYN_REF_SSM_SECUREjoinmapstrrr)r valuepathmatchesmessager r r check_dyn_ref_value@s z0DynamicReferenceSecureString.check_dyn_ref_valuecKsg}|jdi}|dkrdt|tr~xZ|jD]2\}}t|ts,|j|j||dd|gq,Wn|j|j||dd|S)z Check Value item_typeMapN)r$)rrdictitemsextendr")r rrkwargsr r#Zmap_keyZ map_valuer r r check_valueLs   &z(DynamicReferenceSecureString.check_valuecKsbg}t|trDt|dtjr^|j|j|d|dddgn|j|j||dd|S)z%Check Sub Function Dynamic ReferencesrN)rlistrrr'r")r rrr(r r r r check_sub\s  &z&DynamicReferenceSecureString.check_subc Csg}x|D]}||kr ||jkr2||jj|kr2q |j|jd}|sV|j|jd}|j|jddkr||j|jd} nd} |r |j|j|||dd|j|j|| dq W|S) z Check itselfZ PrimitiveTypeZPrimitiveItemTypeTypeListr$N)r)r+primitive_typer#)r-r$)r rr'r)r+) r r propertiesr property_typerr propr.r#r r r checkgs*  z"DynamicReferenceSecureString.checkcCsJg}|jj|ijdrF|jj|ijdi}|j|j||||||S)zMatch for sub properties Properties)rrr'r2)r r/r0rrr rr r r match_resource_sub_propertiess z:DynamicReferenceSecureString.match_resource_sub_propertiescCs6g}|jj|ijdi}|j|j||||||S)zCheck CloudFormation Propertiesr3)rrr'r2)r r/Z resource_typerrr rr r r match_resource_propertiessz6DynamicReferenceSecureString.match_resource_properties)__name__ __module__ __qualname____doc__idZ shortdesc descriptionZ source_urltagsrrr"r)r+r2r4r5 __classcell__r r )r r rs     r)r9rrrrrZcfnlint.helpersrr r r r s