lib/prometheus/api_client/client.rb in prometheus-api-client-0.3.4 vs lib/prometheus/api_client/client.rb in prometheus-api-client-0.4.1
- old
+ new
@@ -22,18 +22,17 @@
}.freeze
# Create a Prometheus API client:
#
# @param [Hash] options
- # @option options [String] :url server base URL.
+ # @option options [String] :url Server base URL.
# @option options [Hash] :credentials Authentication credentials.
# @option options [Hash] :options Options used to define connection.
- # @option options [Hash] :params URI query unencoded key/value pairs.
# @option options [Hash] :headers Unencoded HTTP header key/value pairs.
# @option options [Hash] :request Request options.
# @option options [Hash] :ssl SSL options.
- # @option options [Hash] :proxy Proxy options.
+ # @option options [String] :proxy Proxy url.
#
# A default client is created if options is omitted.
def initialize(options = {})
options = DEFAULT_ARGS.merge(options)
@@ -107,42 +106,61 @@
raise RequestError, 'Bad response from server'
end
# Helper function to evalueate the low level proxy option
def faraday_proxy(options)
- options[:http_proxy_uri] if options[:http_proxy_uri]
+ return options[:proxy] if options[:proxy]
+
+ proxy = options[:options]
+ proxy[:http_proxy_uri] if proxy[:http_proxy_uri]
end
# Helper function to evalueate the low level ssl option
- def faraday_verify_ssl(options)
- return unless options[:verify_ssl]
+ def faraday_ssl(options)
+ return options[:ssl] if options[:ssl]
- {
- verify: options[:verify_ssl] != OpenSSL::SSL::VERIFY_NONE,
- cert_store: options[:ssl_cert_store],
- }
+ ssl = options[:options]
+ if ssl[:verify_ssl] || ssl[:ssl_cert_store]
+ {
+ verify: ssl[:verify_ssl] != OpenSSL::SSL::VERIFY_NONE,
+ cert_store: ssl[:ssl_cert_store],
+ }
+ end
end
# Helper function to evalueate the low level headers option
- def faraday_headers(credentials)
- return unless credentials[:token]
+ def faraday_headers(options)
+ return options[:headers] if options[:headers]
- {
- Authorization: 'Bearer ' + credentials[:token].to_s,
- }
+ headers = options[:credentials]
+ if headers[:token]
+ {
+ Authorization: 'Bearer ' + headers[:token].to_s,
+ }
+ end
end
+ # Helper function to evalueate the low level headers option
+ def faraday_request(options)
+ return options[:request] if options[:request]
+
+ request = options[:options]
+ if request[:open_timeout] || request[:timeout]
+ {
+ open_timeout: request[:open_timeout],
+ timeout: request[:timeout],
+ }
+ end
+ end
+
# Helper function to create the args for the low level client
def faraday_options(options)
{
url: options[:url] + options[:path],
- proxy: faraday_proxy(options[:options]),
- ssl: faraday_verify_ssl(options[:options]),
- headers: faraday_headers(options[:credentials]),
- request: {
- open_timeout: options[:options][:open_timeout],
- timeout: options[:options][:timeout],
- },
+ proxy: faraday_proxy(options),
+ ssl: faraday_ssl(options),
+ headers: faraday_headers(options),
+ request: faraday_request(options),
}
end
end
end
end