class AutomateSoup::API

API class to interact with chef automate

Public Class Methods

new(soup) click to toggle source
# File lib/automate_soup/api.rb, line 5
def initialize(soup)
  @soup = soup
end

Public Instance Methods

orgs(enterprise = 'default') click to toggle source

Get the organizations given the enterprise.

@param enterprise [String] the enterprise to fetch orgs from, defaults to default.

# 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) click to toggle source

Fetch a projects pipeline under an enterprise, organization pair

@option enterprise [String] the enterprise to fetch org from, defaults to default. @option organization [String] the organization to fetch from. @option project [String] the project to fetch from. @option pipeline [String] the pipeline to fetch from.

# File lib/automate_soup/api.rb, line 103
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) click to toggle source

Fetch all project pipelines under an enterprise, organization pair

@option enterprise [String] the enterprise to fetch org from, defaults to default. @option organization [String] the organization to fetch pipelines from. @option project [String] the project to fetch pipelines from.

# File lib/automate_soup/api.rb, line 82
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) click to toggle source

Fetch a project under an enterprise, organization pair

@option enterprise [String] the enterprise to fetch org from, defaults to default. @option organization [String] the organization to fetch projects from. @option project [String] the organization to fetch projects from.

# File lib/automate_soup/api.rb, line 63
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) click to toggle source

Get the projects under and organization given the enterprise.

@option enterprise [String] the enterprise to fetch org from, defaults to default. @option organization [String] the organization to fetch projects from.

# File lib/automate_soup/api.rb, line 44
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
status() click to toggle source

Get the status of the Automate API

# 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