forked from theforeman/foreman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_proxy.rb
41 lines (32 loc) · 777 Bytes
/
http_proxy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class HttpProxy < ApplicationRecord
include Authorizable
include Taxonomix
include Encryptable
audited
extend FriendlyId
encrypts :password
friendly_id :name
has_many :compute_resources
validates :name, :presence => true
validates :url, :presence => true
validates :url, :format => URI::regexp(["http", "https"])
scoped_search :on => :name
scoped_search :on => :url
def full_url
uri = URI(url)
uri.user = username unless username.blank?
uri.password = password unless username.blank?
uri.to_s
end
def test_connection(url)
RestClient::Request.execute(
method: :head,
url: url,
proxy: full_url,
timeout: 5,
open_timeout: 5
)
rescue Excon::Error::Socket => e
e.message
end
end