Skip to content

Commit

Permalink
Support HTTP Proxy
Browse files Browse the repository at this point in the history
Fix #84
  • Loading branch information
ggiamarchi committed Jul 26, 2018
1 parent f5679ab commit 59a7d1a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions source/lib/vagrant-openstack-provider/client/rest_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,33 @@
module VagrantPlugins
module Openstack
module RestUtils
def self._set_proxy(config)
@logger = Log4r::Logger.new('vagrant_openstack::restutils')
if config.http.proxy
RestClient.proxy = config.http.proxy
@logger.info "Setting up HTTP proxy to '#{config.http.proxy}'"
end
end

def self.get(env, url, headers = {}, &block)
config = env[:machine].provider_config
_set_proxy(config)
RestClient::Request.execute(method: :get, url: url, headers: headers,
timeout: config.http.read_timeout, open_timeout: config.http.open_timeout,
ssl_ca_file: config.ssl_ca_file, verify_ssl: config.ssl_verify_peer, &block)
end

def self.post(env, url, payload, headers = {}, &block)
config = env[:machine].provider_config
_set_proxy(config)
RestClient::Request.execute(method: :post, url: url, payload: payload, headers: headers,
timeout: config.http.read_timeout, open_timeout: config.http.open_timeout,
ssl_ca_file: config.ssl_ca_file, verify_ssl: config.ssl_verify_peer, &block)
end

def self.delete(env, url, headers = {}, &block)
config = env[:machine].provider_config
_set_proxy(config)
RestClient::Request.execute(method: :delete, url: url, headers: headers,
timeout: config.http.read_timeout, open_timeout: config.http.open_timeout,
ssl_ca_file: config.ssl_ca_file, verify_ssl: config.ssl_verify_peer, &block)
Expand Down
6 changes: 6 additions & 0 deletions source/lib/vagrant-openstack-provider/config/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ class HttpConfig
# @return [Integer]
attr_accessor :read_timeout

#
# @return [Integer]
attr_accessor :proxy

def initialize
@open_timeout = UNSET_VALUE
@read_timeout = UNSET_VALUE
@proxy = UNSET_VALUE
end

def finalize!
@open_timeout = 60 if @open_timeout == UNSET_VALUE
@read_timeout = 30 if @read_timeout == UNSET_VALUE
@proxy = nil if @proxy == UNSET_VALUE
end

def merge(other)
Expand Down

0 comments on commit 59a7d1a

Please sign in to comment.