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 collapse

VERSION =
'0.2.6'

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) (defaults to: 'default')

    a customizable set of options

  • organization (Hash) (defaults to: nil)

    a customizable set of options

  • project (Hash) (defaults to: nil)

    a customizable set of options

  • pipeline (Hash) (defaults to: nil)

    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) (defaults to: @enterprise)

    a customizable set of options

  • organization (Hash) (defaults to: @organization)

    a customizable set of options

  • project (Hash) (defaults to: @project)

    a customizable set of options

  • pipeline (Hash) (defaults to: @pipeline)

    a customizable set of options

  • topic (Hash) (defaults to: nil)

    a customizable set of options

  • wait (Hash) (defaults to: false)

    a customizable set of options

  • timeout (Hash) (defaults to: 10)

    a customizable set of options

  • retries (Hash) (defaults to: 5)

    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.



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
203
204
205
206
207
208
209
210
211
212
# File 'lib/automate_soup.rb', line 160

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
  )

  return true if !o.nil? && o.delivered?

  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

  app = o.approve
  return true if !wait && !app.nil? && o.deliverable?
  if app.nil? && !o.deliverable?
    puts "Could not approve change #{o.current_stage.stage}: #{o.current_stage.status}"
    return false
  end

  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) (defaults to: @enterprise)

    a customizable set of options

  • organization (Hash) (defaults to: @organization)

    a customizable set of options

  • project (Hash) (defaults to: @project)

    a customizable set of options

  • pipeline (Hash) (defaults to: @pipeline)

    a customizable set of options

  • topic (Hash) (defaults to: nil)

    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
142
143
# 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 = o.first
  raise "Cannot find topic #{topic} in #{o}" if first.nil?
  AutomateSoup::Change.new first
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) (defaults to: @enterprise)

    a customizable set of options

  • organization (Hash) (defaults to: @organization)

    a customizable set of options

  • project (Hash) (defaults to: @project)

    a customizable set of options

  • pipeline (Hash) (defaults to: @pipeline)

    a customizable set of options

  • topic (Hash) (defaults to: nil)

    a customizable set of options

  • wait (Hash) (defaults to: false)

    a customizable set of options

  • timeout (Hash) (defaults to: 10)

    a customizable set of options

  • retries (Hash) (defaults to: 5)

    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.



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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/automate_soup.rb', line 230

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

  de = o.deliver
  return true if !wait && !de.nil? && o.delivered?

  if de.nil? && !o.deliverable?
    puts "Could not deliver change #{o.current_stage.stage}: #{o.current_stage.status}"
    return false
  end

  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) (defaults to: 'default')

    a customizable set of options

  • organization (Hash) (defaults to: nil)

    a customizable set of options

  • project (Hash) (defaults to: nil)

    a customizable set of options

  • pipeline (Hash) (defaults to: nil)

    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) (defaults to: 'default')

    a customizable set of options

  • organization (Hash) (defaults to: nil)

    a customizable set of options

  • project (Hash) (defaults to: nil)

    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) (defaults to: 'default')

    a customizable set of options

  • organization (Hash) (defaults to: nil)

    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) (defaults to: nil)

    a customizable set of options

  • username (Hash) (defaults to: nil)

    a customizable set of options

  • token (Hash) (defaults to: nil)

    a customizable set of options

  • password (Hash) (defaults to: nil)

    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