mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Allow Ansible to honor the "no_proxy" environment varaible.
This commit is contained in:
parent
12968acd5f
commit
38dbce1527
1 changed files with 24 additions and 0 deletions
|
@ -252,9 +252,33 @@ class SSLValidationHandler(urllib2.BaseHandler):
|
|||
except:
|
||||
self.module.fail_json(msg='Connection to proxy failed')
|
||||
|
||||
def detect_no_proxy(self, url):
|
||||
'''
|
||||
Detect if the 'no_proxy' environment variable is set and honor those locations.
|
||||
'''
|
||||
env_no_proxy = os.environ.get('no_proxy')
|
||||
if env_no_proxy:
|
||||
env_no_proxy = env_no_proxy.split(',')
|
||||
netloc = urlparse.urlparse(url).netloc
|
||||
|
||||
for host in env_no_proxy:
|
||||
if netloc.endswith(host) or netloc.split(':')[0].endswith(host):
|
||||
# Our requested URL matches something in no_proxy, so don't
|
||||
# use the proxy for this
|
||||
return False
|
||||
return True
|
||||
|
||||
def http_request(self, req):
|
||||
tmp_ca_cert_path, paths_checked = self.get_ca_certs()
|
||||
https_proxy = os.environ.get('https_proxy')
|
||||
|
||||
# Detect if 'no_proxy' environment variable is set and if our URL is included
|
||||
use_proxy = self.detect_no_proxy(req.get_full_url())
|
||||
|
||||
if not use_proxy:
|
||||
# ignore proxy settings for this host request
|
||||
return req
|
||||
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
if https_proxy:
|
||||
|
|
Loading…
Reference in a new issue