From 2ffd0f36d4936ad261f4fcc7dd8118787759b59b Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 21 Sep 2023 12:27:01 -0400 Subject: [PATCH] Strip trailing .$ from Credentials When transforming a payload_template style hash we have to strip off the trailing .$ after interpolating the value. --- .../workflows/automation_manager/workflow_instance.rb | 8 ++++---- .../automation_manager/workflow_instance_spec.rb | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/manageiq/providers/workflows/automation_manager/workflow_instance.rb b/app/models/manageiq/providers/workflows/automation_manager/workflow_instance.rb index 9ba59c7..bc3b47d 100644 --- a/app/models/manageiq/providers/workflows/automation_manager/workflow_instance.rb +++ b/app/models/manageiq/providers/workflows/automation_manager/workflow_instance.rb @@ -55,16 +55,16 @@ def run(args = {}) object = object_type.constantize.find_by(:id => object_id) if object_type && object_id object.before_ae_starts({}) if object.present? && object.respond_to?(:before_ae_starts) - creds = credentials&.transform_values do |val| - if val.kind_of?(Hash) + creds = credentials&.to_h do |key, val| + if key.end_with?(".$") credential_ref, credential_field = val.values_at("credential_ref", "credential_field") authentication = parent.authentications.find_by(:ems_ref => credential_ref) raise ActiveRecord::RecordNotFound, "Couldn't find Authentication" if authentication.nil? - authentication.send(credential_field) + [key.chomp(".$"), authentication.send(credential_field)] else - val + [key, val] end end diff --git a/spec/models/manageiq/providers/workflows/automation_manager/workflow_instance_spec.rb b/spec/models/manageiq/providers/workflows/automation_manager/workflow_instance_spec.rb index a0ad2af..72d271b 100644 --- a/spec/models/manageiq/providers/workflows/automation_manager/workflow_instance_spec.rb +++ b/spec/models/manageiq/providers/workflows/automation_manager/workflow_instance_spec.rb @@ -125,7 +125,7 @@ end context "with a Credentials property in the workflow_content" do - let(:credentials) { {"username" => {"credential_ref" => "my-credential", "credential_field" => "userid"}, "password" => {"credential_ref" => "my-credential", "credential_field" => "password"}} } + let(:credentials) { {"username.$" => {"credential_ref" => "my-credential", "credential_field" => "userid"}, "password.$" => {"credential_ref" => "my-credential", "credential_field" => "password"}} } let(:payload) do { "Comment" => "Example Workflow", @@ -134,8 +134,8 @@ "FirstState" => { "Type" => "Succeed", "Credentials" => { - "username" => "$.username", - "password" => "$.password" + "username.$" => "$.username", + "password.$" => "$.password" } } }