Class: Puppet::Rest::Client
Instance Attribute Summary collapse
-
#dns_resolver ⇒ Object
readonly
Returns the value of attribute dns_resolver.
Instance Method Summary collapse
-
#get(url, query: nil, header: nil, &block) ⇒ Object
Make a GET request to the specified URL with the specified params.
-
#initialize(ssl_context:, receive_timeout: Puppet[:http_read_timeout], client: HTTPClient.new(agent_name: nil, default_header: { 'User-Agent' => Puppet[:http_user_agent], 'X-PUPPET-VERSION' => Puppet::PUPPETVERSION })) ⇒ Client
constructor
Create a new HTTP client for querying the given API.
-
#put(url, body:, query: nil, header: nil) ⇒ Puppet::Rest::Response
Make a PUT request to the specified URL with the specified params.
Constructor Details
#initialize(ssl_context:, receive_timeout: Puppet[:http_read_timeout], client: HTTPClient.new(agent_name: nil, default_header: { 'User-Agent' => Puppet[:http_user_agent], 'X-PUPPET-VERSION' => Puppet::PUPPETVERSION })) ⇒ Client
Create a new HTTP client for querying the given API.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/puppet/rest/client.rb', line 18 def initialize(ssl_context:, receive_timeout: Puppet[:http_read_timeout], client: HTTPClient.new(agent_name: nil, default_header: { 'User-Agent' => Puppet[:http_user_agent], 'X-PUPPET-VERSION' => Puppet::PUPPETVERSION })) @client = client @client.tcp_keepalive = true @client.connect_timeout = Puppet[:http_connect_timeout] @client.receive_timeout = receive_timeout @client.transparent_gzip_decompression = true if Puppet[:http_debug] @client.debug_dev = $stderr end @ca_path = Puppet[:ssl_client_ca_auth] || Puppet[:localcacert] @verifier = Puppet::SSL::Validator::DefaultValidator.new(@ca_path) configure_verify_mode(ssl_context) @dns_resolver = Puppet::Network::Resolver.new end |
Instance Attribute Details
#dns_resolver ⇒ Object (readonly)
Returns the value of attribute dns_resolver.
10 11 12 |
# File 'lib/puppet/rest/client.rb', line 10 def dns_resolver @dns_resolver end |
Instance Method Details
#get(url, query: nil, header: nil, &block) ⇒ Object
Make a GET request to the specified URL with the specified params.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet/rest/client.rb', line 48 def get(url, query: nil, header: nil, &block) begin @client.get_content(url.to_s, { query: query, header: header }) do |chunk| block.call(chunk) end rescue HTTPClient::BadResponseError => e raise Puppet::Rest::ResponseError.new(e., Puppet::Rest::Response.new(e.res)) rescue OpenSSL::OpenSSLError => e Puppet::Util::SSL.handle_connection_error(e, @verifier, url.host) end end |
#put(url, body:, query: nil, header: nil) ⇒ Puppet::Rest::Response
Make a PUT request to the specified URL with the specified params.
66 67 68 69 70 71 72 73 |
# File 'lib/puppet/rest/client.rb', line 66 def put(url, body:, query: nil, header: nil) begin response = @client.put(url.to_s, body: body, query: query, header: header) Puppet::Rest::Response.new(response) rescue OpenSSL::OpenSSLError => e Puppet::Util::SSL.handle_connection_error(e, @verifier, url.host) end end |