@@ -24,14 +24,13 @@ class RequestError < StandardError; end
2424 # Create a Prometheus API client:
2525 #
2626 # @param [Hash] options
27- # @option options [String] :url server base URL.
27+ # @option options [String] :url Server base URL.
2828 # @option options [Hash] :credentials Authentication credentials.
2929 # @option options [Hash] :options Options used to define connection.
30- # @option options [Hash] :params URI query unencoded key/value pairs.
3130 # @option options [Hash] :headers Unencoded HTTP header key/value pairs.
3231 # @option options [Hash] :request Request options.
3332 # @option options [Hash] :ssl SSL options.
34- # @option options [Hash ] :proxy Proxy options .
33+ # @option options [String ] :proxy Proxy url .
3534 #
3635 # A default client is created if options is omitted.
3736 def initialize ( options = { } )
@@ -109,39 +108,58 @@ def run_command(command, options)
109108
110109 # Helper function to evalueate the low level proxy option
111110 def faraday_proxy ( options )
112- options [ :http_proxy_uri ] if options [ :http_proxy_uri ]
111+ return options [ :proxy ] if options [ :proxy ]
112+
113+ proxy = options [ :options ]
114+ proxy [ :http_proxy_uri ] if proxy [ :http_proxy_uri ]
113115 end
114116
115117 # Helper function to evalueate the low level ssl option
116- def faraday_verify_ssl ( options )
117- return unless options [ :verify_ssl ]
118-
119- {
120- verify : options [ :verify_ssl ] != OpenSSL ::SSL ::VERIFY_NONE ,
121- cert_store : options [ :ssl_cert_store ] ,
122- }
118+ def faraday_ssl ( options )
119+ return options [ :ssl ] if options [ :ssl ]
120+
121+ ssl = options [ :options ]
122+ if ssl [ :verify_ssl ] || ssl [ :ssl_cert_store ]
123+ {
124+ verify : ssl [ :verify_ssl ] != OpenSSL ::SSL ::VERIFY_NONE ,
125+ cert_store : ssl [ :ssl_cert_store ] ,
126+ }
127+ end
123128 end
124129
125130 # Helper function to evalueate the low level headers option
126- def faraday_headers ( credentials )
127- return unless credentials [ :token ]
131+ def faraday_headers ( options )
132+ return options [ :headers ] if options [ :headers ]
133+
134+ headers = options [ :credentials ]
135+ if headers [ :token ]
136+ {
137+ Authorization : 'Bearer ' + headers [ :token ] . to_s ,
138+ }
139+ end
140+ end
128141
129- {
130- Authorization : 'Bearer ' + credentials [ :token ] . to_s ,
131- }
142+ # Helper function to evalueate the low level headers option
143+ def faraday_request ( options )
144+ return options [ :request ] if options [ :request ]
145+
146+ request = options [ :options ]
147+ if request [ :open_timeout ] || request [ :timeout ]
148+ {
149+ open_timeout : request [ :open_timeout ] ,
150+ timeout : request [ :timeout ] ,
151+ }
152+ end
132153 end
133154
134155 # Helper function to create the args for the low level client
135156 def faraday_options ( options )
136157 {
137158 url : options [ :url ] + options [ :path ] ,
138- proxy : faraday_proxy ( options [ :options ] ) ,
139- ssl : faraday_verify_ssl ( options [ :options ] ) ,
140- headers : faraday_headers ( options [ :credentials ] ) ,
141- request : {
142- open_timeout : options [ :options ] [ :open_timeout ] ,
143- timeout : options [ :options ] [ :timeout ] ,
144- } ,
159+ proxy : faraday_proxy ( options ) ,
160+ ssl : faraday_ssl ( options ) ,
161+ headers : faraday_headers ( options ) ,
162+ request : faraday_request ( options ) ,
145163 }
146164 end
147165 end
0 commit comments