class Chef::Knife::Raw
Public Instance Methods
run()
click to toggle source
# File lib/chef/knife/raw.rb, line 75 def run if name_args.length == 0 show_usage ui.fatal("You must provide the path you want to hit on the server") exit(1) elsif name_args.length > 1 show_usage ui.fatal("You must specify only a single path") exit(1) end path = name_args[0] data = false if config[:input] data = IO.read(config[:input]) end begin method = config[:method].to_sym headers = { "Content-Type" => "application/json" } if config[:proxy_auth] headers["x-ops-request-source"] = "web" end if config[:pretty] chef_rest = RawInputServerAPI.new result = chef_rest.request(method, name_args[0], headers, data) unless result.is_a?(String) result = Chef::JSONCompat.to_json_pretty(result) end else chef_rest = RawInputServerAPI.new(raw_output: true) result = chef_rest.request(method, name_args[0], headers, data) end output result rescue Timeout::Error => e ui.error "Server timeout" exit 1 rescue Net::HTTPClientException => e ui.error "Server responded with error #{e.response.code} \"#{e.response.message}\"" ui.error "Error Body: #{e.response.body}" if e.response.body && e.response.body != "" exit 1 end end