module Puppet::HTTP::Proxy

Public Class Methods

http_proxy_env() click to toggle source
   # File lib/puppet/http/proxy.rb
17 def self.http_proxy_env
18   # Returns a URI object if proxy is set, or nil
19   proxy_env = ENV["http_proxy"] || ENV["HTTP_PROXY"]
20   begin
21     return URI.parse(proxy_env) if proxy_env
22   rescue URI::InvalidURIError
23     return nil
24   end
25   return nil
26 end
http_proxy_host() click to toggle source
   # File lib/puppet/http/proxy.rb
72 def self.http_proxy_host
73   env = self.http_proxy_env
74 
75   if env and env.host
76     return env.host
77   end
78 
79   if Puppet.settings[:http_proxy_host] == 'none'
80     return nil
81   end
82 
83   return Puppet.settings[:http_proxy_host]
84 end
http_proxy_password() click to toggle source
    # File lib/puppet/http/proxy.rb
110 def self.http_proxy_password
111   env = self.http_proxy_env
112 
113   if env and env.password
114     return env.password
115   end
116 
117   if Puppet.settings[:http_proxy_user] == 'none' or Puppet.settings[:http_proxy_password] == 'none'
118     return nil
119   end
120 
121   return Puppet.settings[:http_proxy_password]
122 end
http_proxy_port() click to toggle source
   # File lib/puppet/http/proxy.rb
86 def self.http_proxy_port
87   env = self.http_proxy_env
88 
89   if env and env.port
90     return env.port
91   end
92 
93   return Puppet.settings[:http_proxy_port]
94 end
http_proxy_user() click to toggle source
    # File lib/puppet/http/proxy.rb
 96 def self.http_proxy_user
 97   env = self.http_proxy_env
 98 
 99   if env and env.user
100     return env.user
101   end
102 
103   if Puppet.settings[:http_proxy_user] == 'none'
104     return nil
105   end
106 
107   return Puppet.settings[:http_proxy_user]
108 end
no_proxy() click to toggle source
    # File lib/puppet/http/proxy.rb
124 def self.no_proxy
125   no_proxy_env = ENV["no_proxy"] || ENV["NO_PROXY"]
126 
127   if no_proxy_env
128     return no_proxy_env
129   end
130 
131   if Puppet.settings[:no_proxy] == 'none'
132     return nil
133   end
134 
135   return Puppet.settings[:no_proxy]
136 end
no_proxy?(dest) click to toggle source

The documentation around the format of the no_proxy variable seems inconsistent. Some suggests the use of the * as a way of matching any hosts under a domain, e.g.:

*.example.com

Other documentation suggests that just a leading '.' indicates a domain level exclusion, e.g.:

.example.com

We'll accommodate both here.

   # File lib/puppet/http/proxy.rb
36 def self.no_proxy?(dest)
37   no_proxy = self.no_proxy
38   unless no_proxy
39     return false
40   end
41 
42   unless dest.is_a? URI
43     begin
44       dest = URI.parse(dest)
45     rescue URI::InvalidURIError
46       return false
47     end
48   end
49 
50   no_proxy.split(/\s*,\s*/).each do |d|
51     host, port = d.split(':')
52     host = Regexp.escape(host).gsub('\*', '.*')
53 
54     #If this no_proxy entry specifies a port, we want to match it against
55     #the destination port.  Otherwise just match hosts.
56     if port
57       no_proxy_regex  = %r(#{host}:#{port}$)
58       dest_string     = "#{dest.host}:#{dest.port}"
59     else
60       no_proxy_regex  = %r(#{host}$)
61       dest_string     = "#{dest.host}"
62     end
63 
64     if no_proxy_regex.match(dest_string)
65       return true
66     end
67   end
68 
69   return false
70 end
proxy(uri) click to toggle source
   # File lib/puppet/http/proxy.rb
 5 def self.proxy(uri)
 6   if http_proxy_host && !no_proxy?(uri)
 7     Net::HTTP.new(uri.host, uri.port, self.http_proxy_host, self.http_proxy_port, self.http_proxy_user, self.http_proxy_password)
 8   else
 9     http = Net::HTTP.new(uri.host, uri.port, nil, nil, nil, nil)
10     # Net::HTTP defaults the proxy port even though we said not to
11     # use one. Set it to nil so caller is not surprised
12     http.proxy_port = nil
13     http
14   end
15 end