3 D\[%@s8dZddlZddlmZddlmZGdddeZdS)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@seZdZdZdZdZdZdZddgZdd d iid d id d id d id d id ddddddddgdd d iddd d iid d id d id d id d iddddgdddgdddgdd d!gdd d"gd#d$e j e e e d%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/S)0 Configurationz!Check Update Policy ConfigurationZE3016z3Check the configuration of a resources UpdatePolicyz9Make sure a resources UpdatePolicy is properly configuredz^https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html resourcesZ updatepolicyZ WillReplace PrimitiveTypeBooleanIntegerStringListZLaunchZ TerminateZ HealthCheckZReplaceUnhealthyZ AZRebalanceZAlarmNotificationZScheduledActionsZAddToLoadBalancer)r ValidValues)Z MaxBatchSizeZMinInstancesInServiceZMinSuccessfulInstancesPercentZ PauseTimeZSuspendProcessesZWaitOnResourceSignalsZ#IgnoreUnmodifiedGroupSizeProperties)ZAfterAllowTrafficHookZApplicationNameZBeforeAllowTrafficHookZDeploymentGroupName)AutoScalingReplacingUpdateAutoScalingRollingUpdateAutoScalingScheduledActionCodeDeployLambdaAliasUpdater z"AWS::AutoScaling::AutoScalingGroup)Type ResourceTypesr rrzAWS::Lambda::Aliasz"AWS::ElastiCache::ReplicationGroup)rr)r r rrZUseOnlineResharding)r rrr )submainprimitive_typesc Ksg}|jd}|dkr\|jd}|r||krd}|jt||j|jddjtt|n:d}t||jjdj|s|jt||j|jd||S) z Check a primitive value primitive_typer valid_valuesz Allowed values for {0} are ({1})key_namez, z!Value for {0} must be of type {1}r) getappendrformatjoinmapstr isinstancevalid_attributes) selfvaluepathkwargsmatchesZ prim_typermessageZdefault_messager&/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/resources/updatepolicy/Configuration.py check_valueys  (zConfiguration.check_valuec Csg}|jjdj|}t|trx|j|D]\}}x|jD]\} } | |kr|j| } d| kr|j|j|| | jd|dd| gq|j|j| | i| |dd|j| jdg| jd| dq>d} |j t |dd| g| j | q>Wq,Wnd} |j t || j |d |S) z; Check the properties against the spec rrNr r)objkeyr"r(rrrz%UpdatePolicy doesn't support type {0}z{0} should be an object) rrrdict items_safeitemsextendcheck_attributesr(rrr) r cfnZ propertiesZ spec_typer"r$specZ p_value_safeZ p_path_safeZp_nameZp_value up_type_specr%r&r&r'r1s2  $  *zConfiguration.check_attributesc Csg}x|jD]\}}|dd|g}|jjdj|} | r|| jdkrxd} |jt|| jdjtt| jdd| kr|j |j ||| jd|ddq|j |j ||i||dd|j | jdg| jd|d qd } |jt|| j|qW|S) zCheck an update policyNrrz@UpdatePolicy only supports this type for resources of type ({0})z, rr r)r)r*r"r(rrrz%UpdatePolicy doesn't support type {0}) r/rrrrrrrrr0r1r() r r2 update_policyr" resource_typer$Zup_typeZup_valueZup_pathr4r%r&r&r'check_update_policys0$  z!Configuration.check_update_policyc Csg}x|jjD]\}}|jd}|dkr.q|jd}t|tr|d|dg}xL|j|D]\}} |j|j||| |qXWqd} |jt d|dg| j qW|S)zCheck CloudFormation ResourcesZ UpdatePolicyNrZ Resourcesz UpdatePolicy should be an object) get_resourcesr/rrr-r.r0r7rrr) r r2r$Zr_nameZr_valuesr5r6r"Z up_value_safeZ up_path_safer%r&r&r'matchs    zConfiguration.matchN)__name__ __module__ __qualname____doc__idZ shortdesc descriptionZ source_urltagssix string_typesintboollistrr(r1r7r9r&r&r&r'rsR    $!r)r=rAZcfnlintrrrr&r&r&r's