Module: AutomateSoup

Defined in:
lib/automate_soup.rb,
lib/automate_soup/api.rb,
lib/automate_soup/rest.rb,
lib/automate_soup/stage.rb,
lib/automate_soup/change.rb,
lib/automate_soup/version.rb,
lib/automate_soup/credentials.rb

Overview

Top level module

Defined Under Namespace

Modules: Rest Classes: API, Change, Credentials, Stage

Constant Summary

VERSION =
"0.1.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.apiObject

Returns the value of attribute api



14
15
16
# File 'lib/automate_soup.rb', line 14

def api
  @api
end

.credentialsObject

Returns the value of attribute credentials



14
15
16
# File 'lib/automate_soup.rb', line 14

def credentials
  @credentials
end

.enterpriseObject

Returns the value of attribute enterprise



14
15
16
# File 'lib/automate_soup.rb', line 14

def enterprise
  @enterprise
end

.organizationObject

Returns the value of attribute organization



14
15
16
# File 'lib/automate_soup.rb', line 14

def organization
  @organization
end

.pipeline(enterprise: 'default', organization: nil, project: nil, pipeline: nil) ⇒ Object

Fetch a projects pipeline under an enterprise, organization pair

default.

Parameters:

  • enterprise (Hash)

    a customizable set of options

  • organization (Hash)

    a customizable set of options

  • project (Hash)

    a customizable set of options

  • pipeline (Hash)

    a customizable set of options

Options Hash (enterprise:):

  • the (String)

    enterprise to fetch org from, defaults to

Options Hash (organization:):

  • the (String)

    organization to fetch from.

Options Hash (project:):

  • the (String)

    project to fetch from.

Options Hash (pipeline:):

  • the (String)

    pipeline to fetch from.



95
96
97
# File 'lib/automate_soup.rb', line 95

def pipeline
  @pipeline
end

.projectObject

Returns the value of attribute project



14
15
16
# File 'lib/automate_soup.rb', line 14

def project
  @project
end

.urlObject

Returns the value of attribute url



14
15
16
# File 'lib/automate_soup.rb', line 14

def url
  @url
end

Class Method Details

.approve_change(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil, wait: false, timeout: 10, retries: 5) ⇒ Boolean

Approve a change by change topic.

default. to 10

Parameters:

  • enterprise (Hash)

    a customizable set of options

  • organization (Hash)

    a customizable set of options

  • project (Hash)

    a customizable set of options

  • pipeline (Hash)

    a customizable set of options

  • topic (Hash)

    a customizable set of options

  • wait (Hash)

    a customizable set of options

  • timeout (Hash)

    a customizable set of options

  • retries (Hash)

    a customizable set of options

Options Hash (enterprise:):

  • the (String)

    enterprise to fetch org from, defaults to

Options Hash (organization:):

  • the (String)

    organization to fetch from.

Options Hash (project:):

  • the (String)

    project to fetch from.

Options Hash (pipeline:):

  • the (String)

    pipeline to fetch from.

Options Hash (topic:):

  • the (String)

    change topic to approve

Options Hash (wait:):

  • to (Boolean)

    wait for the approval stages to complete.

Options Hash (timeout:):

  • the (Integer)

    time in seconds to wait between requests defaults

Options Hash (retries:):

  • the (Integer)

    amount of retries to make, defaults to 5

Returns:

  • (Boolean)

    true if the change was approved, false otherwise.



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/automate_soup.rb', line 158

def approve_change(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil, wait: false, timeout: 10, retries: 5)
  o = self.change_by_topic(
    enterprise: enterprise,
    organization: organization,
    project: project,
    pipeline: pipeline,
    topic: topic
  )
  if wait && !o.approvable? && !o.deliverable?
    times = 1
    while times <= retries
      o = self.change_by_topic(
        enterprise: enterprise,
        organization: organization,
        project: project,
        pipeline: pipeline,
        topic: topic
      )
      break if o.approvable?
      return false if o.current_stage.failed?
      puts "Stage #{o.current_stage.stage}: #{o.current_stage.status} retries #{times}/#{retries}"
      sleep timeout
      times += 1
    end
  end

  o.approve
  return true if !wait && o.deliverable?
  times = 1
  while times <= retries
    o = self.change_by_topic(
      enterprise: enterprise,
      organization: organization,
      project: project,
      pipeline: pipeline,
      topic: topic
    )
    break if o.deliverable?
    return false if o.current_stage.failed?
    puts "Stage #{o.current_stage.stage}: #{o.current_stage.status} retries #{times}/#{retries}"
    times += 1
    sleep timeout
  end
  true
end

.change_by_topic(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil) ⇒ AutomateSoup::Change

Find a change by topic.

default.

Parameters:

  • enterprise (Hash)

    a customizable set of options

  • organization (Hash)

    a customizable set of options

  • project (Hash)

    a customizable set of options

  • pipeline (Hash)

    a customizable set of options

  • topic (Hash)

    a customizable set of options

Options Hash (enterprise:):

  • the (String)

    enterprise to fetch org from, defaults to

Options Hash (organization:):

  • the (String)

    organization to fetch from.

Options Hash (project:):

  • the (String)

    project to fetch from.

Options Hash (pipeline:):

  • the (String)

    pipeline to fetch from.

Options Hash (topic:):

  • the (String)

    topic to fetch a change from.

Returns:



133
134
135
136
137
138
139
140
141
# File 'lib/automate_soup.rb', line 133

def change_by_topic(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil)
  o = self.pipeline(
    enterprise: enterprise,
    organization: organization,
    project: project,
    pipeline: pipeline
  ).select { |p| p.topic.eql?(topic) }.first
  AutomateSoup::Change.new o
end

.deliver_change(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil, wait: false, timeout: 10, retries: 5) ⇒ Boolean

Delivery a change by a topic

default. to 10

Parameters:

  • enterprise (Hash)

    a customizable set of options

  • organization (Hash)

    a customizable set of options

  • project (Hash)

    a customizable set of options

  • pipeline (Hash)

    a customizable set of options

  • topic (Hash)

    a customizable set of options

  • wait (Hash)

    a customizable set of options

  • timeout (Hash)

    a customizable set of options

  • retries (Hash)

    a customizable set of options

Options Hash (enterprise:):

  • the (String)

    enterprise to fetch org from, defaults to

Options Hash (organization:):

  • the (String)

    organization to fetch from.

Options Hash (project:):

  • the (String)

    project to fetch from.

Options Hash (pipeline:):

  • the (String)

    pipeline to fetch from.

Options Hash (topic:):

  • the (String)

    change topic to approve

Options Hash (wait:):

  • to (Boolean)

    wait for the approval stages to complete.

Options Hash (timeout:):

  • the (Integer)

    time in seconds to wait between requests defaults

Options Hash (retries:):

  • the (Integer)

    amount of retries to make, defaults to 5

Returns:

  • (Boolean)

    true if the change was delivered, false otherwise.



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/automate_soup.rb', line 220

def deliver_change(enterprise: @enterprise, organization: @organization, project: @project, pipeline: @pipeline, topic: nil, wait: false, timeout: 10, retries: 5)
  o = self.change_by_topic(
    enterprise: enterprise,
    organization: organization,
    project: project,
    pipeline: pipeline,
    topic: topic
  )
  return false if !o.deliverable?
  if wait && !o.deliverable?
    times = 1
    while times <= retries
      o = self.change_by_topic(
        enterprise: enterprise,
        organization: organization,
        project: project,
        pipeline: pipeline,
        topic: topic
      )
      break if o.deliverable?
      return false if o.current_stage.failed?
      puts "Stage #{o.current_stage.stage}: #{o.current_stage.status} retries #{times}/#{retries}"
      sleep timeout
      times += 1
    end
  end

  o.deliver
  return true if !wait && o.delivered?
  times = 1
  while times <= retries
    o = self.change_by_topic(
      enterprise: enterprise,
      organization: organization,
      project: project,
      pipeline: pipeline,
      topic: topic
    )
    break if o.delivered?
    return false if o.current_stage.failed?
    puts "Stage #{o.current_stage.stage}: #{o.current_stage.status} retries #{times}/#{retries}"
    times += 1
    sleep timeout
  end
  true
end

.orgs(enterprise = 'default') ⇒ Object

Fetch all organizations under an enterprise



59
60
61
# File 'lib/automate_soup.rb', line 59

def orgs(enterprise = 'default')
  @api.orgs enterprise
end

.pipeline_topics(enterprise: 'default', organization: nil, project: nil, pipeline: nil) ⇒ Array

Filters out the topics from the pipelines changes .

default.

Parameters:

  • enterprise (Hash)

    a customizable set of options

  • organization (Hash)

    a customizable set of options

  • project (Hash)

    a customizable set of options

  • pipeline (Hash)

    a customizable set of options

Options Hash (enterprise:):

  • the (String)

    enterprise to fetch org from, defaults to

Options Hash (organization:):

  • the (String)

    organization to fetch from.

Options Hash (project:):

  • the (String)

    project to fetch from.

Options Hash (pipeline:):

  • the (String)

    pipeline to fetch from.

Returns:

  • (Array)

    an array of strings holding change topics.



113
114
115
116
117
118
119
120
# File 'lib/automate_soup.rb', line 113

def pipeline_topics(enterprise: 'default', organization: nil, project: nil, pipeline: nil)
  self.pipeline(
    enterprise: enterprise,
    organization: organization,
    project: project,
    pipeline: pipeline
  ).map { |p| p.topic }
end

.pipelines(enterprise: 'default', organization: nil, project: nil) ⇒ Object

Fetch all project pipelines under an enterprise, organization pair

default.

Parameters:

  • enterprise (Hash)

    a customizable set of options

  • organization (Hash)

    a customizable set of options

  • project (Hash)

    a customizable set of options

Options Hash (enterprise:):

  • the (String)

    enterprise to fetch org from, defaults to

Options Hash (organization:):

  • the (String)

    organization to fetch pipelines from.

Options Hash (project:):

  • the (String)

    project to fetch pipelines from.



82
83
84
# File 'lib/automate_soup.rb', line 82

def pipelines(enterprise: 'default', organization: nil, project: nil)
  @api.pipelines(enterprise: enterprise, organization: organization, project: project)
end

.projects(enterprise: 'default', organization: nil) ⇒ Object

Get the projects under and organization given the enterprise.

default.

Parameters:

  • enterprise (Hash)

    a customizable set of options

  • organization (Hash)

    a customizable set of options

Options Hash (enterprise:):

  • the (String)

    enterprise to fetch org from, defaults to

Options Hash (organization:):

  • the (String)

    organization to fetch projects from.



70
71
72
# File 'lib/automate_soup.rb', line 70

def projects(enterprise: 'default', organization: nil)
  @api.projects(enterprise: enterprise, organization: organization)
end

.setup(url: nil, username: nil, token: nil, password: nil, enterprise: 'default', organization: nil, project: nil, pipeline: nil) ⇒ Object

Setup Automate Soup client.

Parameters:

  • url (Hash)

    a customizable set of options

  • username (Hash)

    a customizable set of options

  • token (Hash)

    a customizable set of options

  • password (Hash)

    a customizable set of options

Options Hash (url:):

  • The (String)

    Chef Automate URL.

Options Hash (username:):

  • The (String)

    Chef Automate username.

Options Hash (token:):

  • The (String)

    Chef Automate user token.

Options Hash (password:):

  • The (String)

    Chef Automate user password.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/automate_soup.rb', line 24

def setup(
  url: nil,
  username: nil,
  token: nil,
  password: nil,
  enterprise: 'default',
  organization: nil,
  project: nil,
  pipeline: nil
)
  @url = url
  @credentials = if token
                   token_credentials(username, token)
                 else
                   password_credentials(username, password)
                 end
  @api = AutomateSoup::API.new(self)
  @enterprise = enterprise
  @organization = organization
  @project = project
  @pipeline = pipeline
  self
end

.statusObject

Check the status of Automate



51
52
53
54
# File 'lib/automate_soup.rb', line 51

def status
  o = @api.status
  OpenStruct.new o
end