Class: Eso::Workflow
- Inherits:
-
Object
- Object
- Eso::Workflow
- Defined in:
- lib/eso/workflow.rb
Overview
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.
Direct Known Subclasses
Defined Under Namespace
Modules: State Classes: History, StateHistory
Instance Attribute Summary collapse
-
#id ⇒ Object
The id of the workflow.
-
#name ⇒ Object
The name of the workflow.
-
#steps ⇒ Object
An array of the steps this workflow takes action on.
-
#timeCreated ⇒ Object
The time the workflow was created in milliseconds since epoch.
Class Method Summary collapse
-
.load(conductor, id) ⇒ Workflow
Load an existing workflow from the API.
Instance Method Summary collapse
-
#get_step(type_name) ⇒ Step
Return the relevant step based on the given service name.
-
#initialize(id: nil, name:, steps: [], time_created: (Time.now.strftime('%s').to_i * 1000)) ⇒ Workflow
constructor
Constructor for the workflow.
-
#to_hash ⇒ Hash{}
Return this object as a hash.
-
#to_json ⇒ String
Return this object and the associated steps in a digestible JSON format.
-
#trigger ⇒ Step
Return the trigger step of a workflow.
Constructor Details
#initialize(id: nil, name:, steps: [], time_created: (Time.now.strftime('%s').to_i * 1000)) ⇒ Workflow
Constructor for the workflow
25 26 27 28 29 30 |
# 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 |
Instance Attribute Details
#id ⇒ Object
The id of the workflow. This will be created upon saving to the server upon creation.
7 8 9 |
# File 'lib/eso/workflow.rb', line 7 def id @id end |
#name ⇒ Object
The name of the workflow. This is required.
10 11 12 |
# File 'lib/eso/workflow.rb', line 10 def name @name end |
#steps ⇒ Object
An array of the steps this workflow takes action on.
13 14 15 |
# File 'lib/eso/workflow.rb', line 13 def steps @steps end |
#timeCreated ⇒ Object
The time the workflow was created in milliseconds since epoch
16 17 18 |
# File 'lib/eso/workflow.rb', line 16 def timeCreated @timeCreated end |
Class Method Details
.load(conductor, id) ⇒ Workflow
Load an existing workflow from the API.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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 |
Instance Method Details
#get_step(type_name) ⇒ Step
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’.
61 62 63 64 65 |
# 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 ⇒ Hash{}
Return this object as a hash. The corresponding steps will still be objects.
97 98 99 100 101 |
# 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 ⇒ String
Return this object and the associated steps in a digestible JSON format.
84 85 86 87 88 89 90 91 |
# 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 ⇒ Step
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.
74 75 76 77 78 |
# File 'lib/eso/workflow.rb', line 74 def trigger @steps.find do |step| step.stepConfiguration.previousTypeName.nil? end end |