Class: A2::Client
- Inherits:
-
Object
- Object
- A2::Client
- Includes:
- ConfigMgmt, Nodes, Reporting, 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/reporting.rb,
lib/a2/client/config_mgmt.rb
Defined Under Namespace
Modules: ConfigMgmt, Nodes, Reporting, Teams, Users
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #download_file(path, json, output_file) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #post(path, json) ⇒ Object
- #put(path, json) ⇒ Object
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 Reporting
#export_node_reports, #list_reports
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_runs, #list_all_node_status_counts, #list_all_organizations, #show_attributes, #show_node_run
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 |
# File 'lib/a2/client.rb', line 15 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
62 63 64 65 66 67 68 |
# File 'lib/a2/client.rb', line 62 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 |
#download_file(path, json, output_file) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/a2/client.rb', line 50 def download_file(path, json, output_file) File.open(output_file, "w") do |file| HTTParty.post(File.join(@automate_url, path).to_s, { verify: !@ssl_no_verify, headers: {"api-token" => @automate_token}, body: json }) do |fragment| file.write(fragment) end end end |
#get(path) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/a2/client.rb', line 24 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
41 42 43 44 45 46 47 48 |
# File 'lib/a2/client.rb', line 41 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
32 33 34 35 36 37 38 39 |
# File 'lib/a2/client.rb', line 32 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 |