From a975aba2506c0b4846ebe2b030f2459173c850ac Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 8 Nov 2023 12:51:20 -0500 Subject: [PATCH] Check if a workflow payload is valid during sync When syncing a repository and creating workflows check if the payload is valid and if it isn't set a (hopefully) helpful error message. --- .../configuration_script_source.rb | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/models/manageiq/providers/workflows/automation_manager/configuration_script_source.rb b/app/models/manageiq/providers/workflows/automation_manager/configuration_script_source.rb index 590d23e..3341bb1 100644 --- a/app/models/manageiq/providers/workflows/automation_manager/configuration_script_source.rb +++ b/app/models/manageiq/providers/workflows/automation_manager/configuration_script_source.rb @@ -18,9 +18,24 @@ def sync next if filename.start_with?(".") || !filename.end_with?(".asl") payload = worktree.read_file(filename) - found = current.delete(filename) || self.class.module_parent::Workflow.new(:configuration_script_source_id => id) - - found.update!(:name => filename, :manager_id => manager_id, :payload => payload, :payload_type => "json") + payload_valid, payload_error = + begin + Floe::Workflow.new(payload) + true + rescue Floe::InvalidWorkflowError => err + [false, err.message] + end + + found = current.delete(filename) || self.class.module_parent::Workflow.new(:configuration_script_source_id => id) + + found.update!( + :name => filename, + :manager_id => manager_id, + :payload => payload, + :payload_type => "json", + :payload_valid => payload_valid, + :payload_error => payload_error + ) end end