3 D\@s@dZddlZddlZddlmZddlmZGdddeZdS)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) RuleMatchcsbeZdZdZdZdZdZdZddgZfdd Z d d Z d d Z dddZ ddZ ddZZS) StateMachinezCheck State Machine DefinitionZE2532z0Check State Machine Definition for proper syntaxzyCheck the State Machine String Definition to make sure its JSON. Validate basic syntax of the file to determine validity.zkhttps://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html resourcesZ stepfunctionscstt|j|jjddS)ZInitz AWS::StepFunctions::StateMachineN)superr__init__Zresource_property_typesappend)self) __class__/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/resources/stepfunctions/StateMachine.pyr szStateMachine.__init__c Cslg}ddddddg}dg}ddd gd dd d d d dgddgddddggddgddd d gd}gd gdggggdgd}x4|D],} | |krzd| |f} |jt|| |SqzW|jd} | |krPxF|jD]:\} } | ||j| gkrd| || f} |jt|| qWx`||j| gD]2} | |krd| || f} |jt|| |SqWnd| } |jt|| |S)zCheck State JSON DefinitionZNextZEndTypeCommentZ InputPathZ OutputPathZResultZ ResultPathZ ParametersResourceRetryZCatchTimeoutSecondsZHeartbeatSecondsZChoicesZDefaultZSecondsZ TimestampZ SecondsPathZ TimestampPathZCauseErrorZBranches)PassZTaskZChoiceZWaitZSucceedZFailZParallelzDState Machine Definition required key (%s) for State (%s) is missingzJState Machine Definition key (%s) for State (%s) of Type (%s) is not validzQState Machine Definition required key (%s) for State (%s) of Type (%s) is missingz/State Machine Definition Type (%s) is not valid)rrgetitems)r def_json state_namepathmatchesZcommon_state_keysZcommon_state_required_keysZstate_key_typesZstate_required_typesreq_keymessageZ state_typeZ state_key_r r r _check_state_json%sR        zStateMachine._check_state_jsonc Csg}dddddg}ddg}x4|jD](\}}||kr$d|}|jt||q$Wx,|D]$} | |krVd| }|jt||qVWx0|jdijD]\} } |j|j| | |qW|S)zCheck JSON DefinitionrZStartAtrVersionZStatesz.State Machine Definition key (%s) is not validz5State Machine Definition required key (%s) is missing)rrrrextendr) r rrrZtop_level_keysZtop_level_required_keysZtop_keyrrrrZ state_valuer r r _check_definition_json`s& z#StateMachine._check_definition_jsonTcCsvg}ytj|}WnLtk r^}z0|rDd|}|jt|||S|jjd|Sd}~XnX|j|j|||S)zCheck Definition Valuez@State Machine Definition needs to be formatted as JSON. Error %sz6State Machine definition could not be parsed. SkippingN) jsonloads Exceptionrrloggerdebugrr )r valuerZ fail_on_loadsrrerrrr r r check_value}s zStateMachine.check_valuecCsLg}t|tr(|j|j|d|dn t|tjrH|j|j||d|S)zCheck Sub ObjectrF) isinstancelistrr(six string_types)r r&rrr r r check_subs   zStateMachine.check_subcCs.g}|j|j|d|dd|j|jd|S)zCheck CloudFormation PropertiesZDefinitionStringN)objkeyrr(r-)rr(r-)r Z propertiesrrZcfnrr r r match_resource_propertiess  z&StateMachine.match_resource_properties)T)__name__ __module__ __qualname____doc__idZ shortdesc descriptionZ source_urltagsrrr r(r-r0 __classcell__r r )r r rs ;  r)r4r!r+Zcfnlintrrrr r r r s