mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 13:28:42 -05:00
(#27) Handle URLs that do not have HTTP or HTTPS
Prior to this commit, if a user provided a url without HTTP or HTTPS Faraday would fail to make a connection to the pooler since it doesn't seem to handle urls without that. This commit adds a simple check to see what kind of URI the user gave us, and if its missing that protocol add it to the beginning of the URL before making a request.
This commit is contained in:
parent
93e842a2aa
commit
9a1d4a15d6
1 changed files with 23 additions and 0 deletions
|
|
@ -1,11 +1,30 @@
|
||||||
require 'faraday'
|
require 'faraday'
|
||||||
|
require 'uri'
|
||||||
|
|
||||||
class Http
|
class Http
|
||||||
|
def self.is_url(url)
|
||||||
|
# This method exists because it seems like Farady
|
||||||
|
# has no handling around if a user gives us a URI
|
||||||
|
# with no protocol on the beginning of the URL
|
||||||
|
|
||||||
|
uri = URI.parse(url)
|
||||||
|
|
||||||
|
if uri.kind_of?(URI::HTTP) or uri.kind_of?(URI::HTTPS)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
def self.get_conn(verbose, url)
|
def self.get_conn(verbose, url)
|
||||||
if url.nil?
|
if url.nil?
|
||||||
raise "Did not provide a url to connect to"
|
raise "Did not provide a url to connect to"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless is_url(url)
|
||||||
|
url = "https://#{url}"
|
||||||
|
end
|
||||||
|
|
||||||
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
|
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
|
||||||
faraday.request :url_encoded
|
faraday.request :url_encoded
|
||||||
faraday.response :logger if verbose
|
faraday.response :logger if verbose
|
||||||
|
|
@ -24,6 +43,10 @@ class Http
|
||||||
raise "You did not provide a user to authenticate with"
|
raise "You did not provide a user to authenticate with"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless is_url(url)
|
||||||
|
url = "https://#{url}"
|
||||||
|
end
|
||||||
|
|
||||||
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
|
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
|
||||||
faraday.request :url_encoded
|
faraday.request :url_encoded
|
||||||
faraday.request :basic_auth, user, password
|
faraday.request :basic_auth, user, password
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue