Class: AutomateSoup::API

Inherits:
Object
  • Object
show all
Defined in:
lib/automate_soup/api.rb

Overview

API class to interact with chef automate

Instance Method Summary collapse

Constructor Details

#initialize(soup) ⇒ API

Returns a new instance of API



5
6
7
# File 'lib/automate_soup/api.rb', line 5

def initialize(soup)
  @soup = soup
end

Instance Method Details

#orgs(enterprise = 'default') ⇒ Object

Get the organizations given the enterprise.

default.

Parameters:

  • enterprise (String) (defaults to: 'default')

    the enterprise to fetch orgs from, defaults to



26
27
28
29
30
31
32
33
34
# File 'lib/automate_soup/api.rb', line 26

def orgs(enterprise = 'default')
  @hash = AutomateSoup::Rest.get(
    url: "#{@soup.url}/api/v0/e/#{enterprise}/orgs",
    username: @soup.credentials.username,
    token: @soup.credentials.token
  )
  raise "Failed to fetch orgs under enterprise #{enterprise}" unless @hash['orgs']
  @hash['orgs']
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.



102
103
104
105
106
107
108
109
110
# File 'lib/automate_soup/api.rb', line 102

def pipeline(enterprise: 'default', organization: nil, project: nil, pipeline: nil)
  @hash = AutomateSoup::Rest.get(
    url: "#{@soup.url}/api/v0/e/#{enterprise}/orgs/#{organization}/projects/#{project}/changes?pipeline=#{pipeline}&limit=25",
    username: @soup.credentials.username,
    token: @soup.credentials.token
  )
rescue JSON::ParserError
  raise "Failed to fetch pipelines under organization #{organization} enterprise #{enterprise}"
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.



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/automate_soup/api.rb', line 81

def pipelines(enterprise: 'default', organization: nil, project: nil)
  @hash = AutomateSoup::Rest.get(
    url: "#{@soup.url}/api/v0/e/#{enterprise}/orgs/#{organization}/projects/#{project}/pipelines",
    username: @soup.credentials.username,
    token: @soup.credentials.token
  )
  @hash['pipelines']

rescue JSON::ParserError
  raise "Failed to fetch pipelines under organization #{organization} enterprise #{enterprise}"
end

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

Fetch a project 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 projects from.

Options Hash (project:):

  • the (String)

    organization to fetch projects from.



62
63
64
65
66
67
68
69
70
71
# File 'lib/automate_soup/api.rb', line 62

def project(enterprise: 'default', organization: nil, project: nil)
  @hash = AutomateSoup::Rest.get(
    url: "#{@soup.url}/api/v0/e/#{enterprise}/orgs/#{organization}/projects/#{project}/pipelines",
    username: @soup.credentials.username,
    token: @soup.credentials.token
  )

rescue JSON::ParserError
  raise "Failed to fetch projects under organization #{organization} enterprise #{enterprise}"
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.



43
44
45
46
47
48
49
50
51
52
# File 'lib/automate_soup/api.rb', line 43

def projects(enterprise: 'default', organization: nil)
  @hash = AutomateSoup::Rest.get(
    url: "#{@soup.url}/api/v0/e/#{enterprise}/orgs/#{organization}/projects",
    username: @soup.credentials.username,
    token: @soup.credentials.token
  )

rescue JSON::ParserError
  raise "Failed to fetch projects under organization #{organization} enterprise #{enterprise}"
end

#statusObject

Get the status of the Automate API



12
13
14
15
16
17
18
# File 'lib/automate_soup/api.rb', line 12

def status
  AutomateSoup::Rest.get(
    url: "#{@soup.url}/api/_status",
    username: @soup.credentials.username,
    token: @soup.credentials.token
  )
end