Skip to content

Commit

Permalink
Extract resolve/update credentials into methods
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Jan 2, 2024
1 parent b9c76da commit 40eb537
Showing 1 changed file with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,34 @@ 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&.to_h do |key, val|
creds = resolved_credentials
wf = Floe::Workflow.new(payload, context, creds)
wf.run_nonblock
update_credentials!(wf.credentials)

update!(:context => wf.context.to_h, :status => wf.status, :output => wf.output, :credentials => credentials)

if object.present? && object.respond_to?(:after_ae_delivery)
ae_result =
case status
when "running"
"retry"
when "success"
"ok"
else
status
end

object.after_ae_delivery(ae_result)
end

run_queue(:zone => zone, :role => role, :object => object, :deliver_on => 10.seconds.from_now.utc, :server_guid => MiqServer.my_server.guid) unless wf.end?
end

private

def resolved_credentials
credentials&.to_h do |key, val|
if key.end_with?(".$")
credential_ref, credential_field = val.values_at("credential_ref", "credential_field")

Expand All @@ -70,11 +97,12 @@ def run(args = {})
[key, ManageIQ::Password.try_decrypt(val)]
end
end
end

wf = Floe::Workflow.new(payload, context, creds)
wf.run_nonblock

wf.credentials.each do |key, val|
def update_credentials!(workflow_credentials)
workflow_credentials.each do |key, val|
# If the workflow has changed a credential that is mapped to an Authentication record
# drop the mapping and replace it with an in-line encrypted value
if credentials.key?("#{key}.$")
credential_ref, credential_field = credentials["#{key}.$"].values_at("credential_ref", "credential_field")
authentication = parent.authentications.find_by(:ems_ref => credential_ref)
Expand All @@ -86,23 +114,5 @@ def run(args = {})

credentials[key] = ManageIQ::Password.encrypt(val)
end

update!(:context => wf.context.to_h, :status => wf.status, :output => wf.output, :credentials => credentials)

if object.present? && object.respond_to?(:after_ae_delivery)
ae_result =
case status
when "running"
"retry"
when "success"
"ok"
else
status
end

object.after_ae_delivery(ae_result)
end

run_queue(:zone => zone, :role => role, :object => object, :deliver_on => 10.seconds.from_now.utc, :server_guid => MiqServer.my_server.guid) unless wf.end?
end
end

0 comments on commit 40eb537

Please sign in to comment.