class Eso::Workflow

The following classes have mixed casing (snake and camel) to accommodate for the API. I guess a TODO would be to write a helper to automatically convert them.

Constants

StateHistory

Attributes

id[RW]

The id of the workflow. This will be created upon saving to the server upon creation.

name[RW]

The name of the workflow. This is required.

steps[RW]

An array of the steps this workflow takes action on.

timeCreated[RW]

The time the workflow was created in milliseconds since epoch

Public Class Methods

load(conductor, id) click to toggle source

Load an existing workflow from the API.

@param [Conductor] conductor The Conductor object governing the workflows @param [String] id ID of the workflow to load @return [Workflow] Workflow object that was loaded.

# File lib/eso/workflow.rb, line 38
def self.load(conductor, id)
  uri = "#{conductor.url}workflows/#{id}"
  resp = conductor.get(url: uri)
  workflow = self.new(id: resp[:id], name: resp[:name])
  steps = resp[:steps]
  steps.each do |step|
    workflow_step = Step.new(uuid: step[:uuid],
                             service_name: step[:serviceName],
                             workflow: workflow,
                             type_name: step[:stepConfiguration][:typeName],
                             previous_type_name: step[:stepConfiguration][:previousTypeName],
                             configuration_params: step[:stepConfiguration][:configurationParams])
    workflow.steps << workflow_step
  end
  workflow
end
new(id: nil, name:, steps: [], time_created: (Time.now.strftime('%s').to_i * 1000)) click to toggle source

Constructor for the workflow

@param [String] id ID of the workflow. @param [String] name Name of the workflow. @param [Array] steps Array of the steps that this workflow takes. @param [Fixnum] time_created The time the workflow was created in millis since epoch

# File lib/eso/workflow.rb, line 25
def initialize(id: nil, name:, steps: [], time_created: (Time.now.strftime('%s').to_i * 1000))
  @id = id
  @name = name
  @steps = steps
  @timeCreated = time_created
end

Public Instance Methods

get_step(type_name) click to toggle source

Return the relevant step based on the given service name. For example, if you want the step related to the scan service you would pass 'nexpose-scan-service'.

@param [String] service_name Service name to be returned. @return [Step] Step object corresponding to the given service.

# File lib/eso/workflow.rb, line 61
def get_step(type_name)
  @steps.find do |step|
    step.type_name == type_name
  end
end
to_hash() click to toggle source

Return this object as a hash. The corresponding steps will still be objects.

@return [Hash{}] Hash interpretation of this workflow.

# File lib/eso/workflow.rb, line 97
def to_hash
  hash = {}
  instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
  hash
end
to_json() click to toggle source

Return this object and the associated steps in a digestible JSON format.

@return [String] JSON interpretation of this workflow.

# File lib/eso/workflow.rb, line 84
def to_json
  hash = self.to_hash
  steps = hash['steps']
  hashified_steps = []
  steps.each { |step| hashified_steps << step.to_hash }
  hash['steps'] = hashified_steps
  hash.to_json
end
trigger() click to toggle source

Return the trigger step of a workflow. The trigger step is defined as a step that monitors for events that will cause the action to fire.

Currently triggers do not have a previous-action so that is what this is returning. This behavior could change in ESO's future.

@return [Step] Step object representation of the trigger step.

# File lib/eso/workflow.rb, line 74
def trigger
  @steps.find do |step|
    step.stepConfiguration.previousTypeName.nil?
  end
end