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@s8eZdZdZdZdZdZdZddgZdd „Z d d „Z d S) ÚDeletionPolicyz!Check Base Resource ConfigurationZE3035z)Check DeletionPolicy values for Resourcesz.Check that the DeletionPolicy values are validz`https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.htmlÚ resourcesZdeletionpolicyc CsÔg}dddg}dddddd d g}t|tjtjfƒs\d }|jt||jd jtt |ƒƒƒƒƒ|S||kr˜d }|jt||jdjtt |ƒƒd jtt |ƒƒƒƒƒ|dkrÐ||krÐd}|jt||j|d jtt |ƒƒƒƒƒ|S)z'Check resource names for DeletionPolicyÚDeleteZRetainZSnapshotzAWS::EC2::VolumezAWS::ElastiCache::CacheClusterz"AWS::ElastiCache::ReplicationGroupzAWS::Neptune::DBClusterzAWS::RDS::DBClusterzAWS::RDS::DBInstancezAWS::Redshift::Clusterz0DeletionPolicy values should be of string at {0}ú/z/DeletionPolicy should be only one of {0} at {1}z, zBDeletionPolicy cannot be Snapshot for resources of type {0} at {1}) Ú isinstanceÚsixÚ text_typeÚ string_typesÚappendrÚformatÚjoinÚmapÚstr)ÚselfÚkeyÚpathÚres_typeÚmatchesZ valid_valuesZvalid_snapshot_typesÚmessage©rú€/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/resources/DeletionPolicy.pyÚ check_values8"zDeletionPolicy.check_valuec Csœg}|jƒ}xŠ|jƒD]~\}}|jdƒ}|rd|dg}|jdƒ}|jjd|ƒt|tƒr€d} |jt|| j dj t t |ƒƒƒƒƒq|j |j|||ƒƒqW|S)zCheck CloudFormation ResourcesrZ ResourcesÚTypez3Validating DeletionPolicy for %s base configurationz3Only one DeletionPolicy allowed per resource at {0}r)Ú get_resourcesÚitemsÚgetÚloggerÚdebugrÚlistr rr rrrÚextendr) rZcfnrrÚ resource_nameZresource_valuesZdeletion_policiesrrrrrrÚmatchDs    $zDeletionPolicy.matchN) Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚidZ shortdescÚ descriptionZ source_urlÚtagsrr#rrrrrs&r)r'r ZcfnlintrrrrrrrÚs