Class: A2::Client

Inherits:
Object
  • Object
show all
Includes:
ConfigMgmt, Nodes, Teams, Users
Defined in:
lib/a2/client.rb,
lib/a2/client/nodes.rb,
lib/a2/client/teams.rb,
lib/a2/client/users.rb,
lib/a2/client/config_mgmt.rb

Defined Under Namespace

Modules: ConfigMgmt, Nodes, Teams, Users

Instance Method Summary collapse

Methods included from Users

#create_user, #delete_user, #get_user, #list_all_users, #update_user

Methods included from Teams

#add_membership, #create_team, #delete_team, #get_team, #get_teams_by_membership, #list_all_membership, #list_all_teams, #remove_membership, #update_team

Methods included from Nodes

#bulk_delete_managed_nodes_by_filter, #bulk_delete_managed_nodes_by_id, #delete_managed_node, #get_managed_node, #search_managed_nodes

Methods included from ConfigMgmt

#list_all_checked_in_nodes, #list_all_missing_nodes_count, #list_all_node_status_counts, #list_all_organizations, #show_attributes

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.

Raises:



13
14
15
16
17
18
19
20
# File 'lib/a2/client.rb', line 13

def initialize(opts = {})
  @automate_url = opts[:automate_url] || ENV['AUTOMATE_URL']
  @automate_token = opts[:automate_token] || ENV['AUTOMATE_TOKEN']
  @ssl_no_verify = opts[:ssl_no_verify] || ENV['AUTOMATE_SSL_NO_VERIFY'] || false

  raise A2::Error, "Must provide the URL for Chef Automate" if @automate_url.nil?
  raise A2::Error, "Must provide a token for Chef Automate" if @automate_token.nil?
end

Instance Method Details

#delete(path) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/a2/client.rb', line 48

def delete(path)
  response = HTTParty.delete(File.join(@automate_url, path).to_s, {
    verify: !@ssl_no_verify,
    headers: {"api-token" => @automate_token},
  })
  JSON.parse(response.body)
end

#get(path) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/a2/client.rb', line 22

def get(path)
  response = HTTParty.get(File.join(@automate_url, path).to_s, {
    verify: !@ssl_no_verify,
    headers: {"api-token" => @automate_token},
  })
  JSON.parse(response.body)
end

#post(path, json) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/a2/client.rb', line 39

def post(path, json)
  response = HTTParty.post(File.join(@automate_url, path).to_s, {
    verify: !@ssl_no_verify,
    headers: {"api-token" => @automate_token},
    body: json
  })
  JSON.parse(response.body)
end

#put(path, json) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/a2/client.rb', line 30

def put(path, json)
  response = HTTParty.put(File.join(@automate_url, path).to_s, {
    verify: !@ssl_no_verify,
    headers: {"api-token" => @automate_token},
    body: json
  })
  JSON.parse(response.body)
end