Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F1469261
shifter-patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Author
aubort
Created
May 5 2017, 17:17
Size
3 KB
Mime Type
text/x-diff
Engine
blob
Format
Raw Data
Handle
380263
Attached To
Restricted Maniphest Task
shifter-patch
View Options
diff --git a/imagegw/shifter_imagegw/dockerv2.py b/imagegw/shifter_imagegw/dockerv2.py
old mode 100755
new mode 100644
index ba70040..7cb4124
--- a/imagegw/shifter_imagegw/dockerv2.py
+++ b/imagegw/shifter_imagegw/dockerv2.py
@@ -22,6 +22,7 @@ includes pulling down the manifest, pulling layers, and unpacking the layers.
"""
import hashlib
+import urlparse
import httplib
import ssl
import json
@@ -46,6 +47,17 @@ if 'all_proxy' in os.environ:
socket.socket = socks.socksocket # dont add ()!!!
+def need_proxy(hostname):
+ """
+ Helper function to determine if a proxy should be used to connect to a host
+ """
+ if os.environ['no_proxy']:
+ domains = os.environ['no_proxy'].split(',')
+ ismatch = True in map(lambda x: hostname.endswith(x), domains)
+ return not ismatch
+ else:
+ return True
+
def _jose_decode_base64(input_string):
"""
Helper function to Decode base64
@@ -90,30 +102,62 @@ def _verify_manifest_signature(manifest, text, digest):
def _setup_http_conn(url, cacert=None):
"""Prepare http connection object and return it."""
- (protocol, url) = url.split('://', 1)
+ target = urlparse.urlparse(url)
conn = None
- if protocol == 'http':
- port = 80
- else:
- port = 443
- if url.find('/') >= 0:
- (server, _) = url.split('/', 1)
- else:
- server = url
- if ':' in server:
- (server, portstr) = server.split(':', 1)
- port = int(portstr)
- if protocol == 'http':
- conn = httplib.HTTPConnection(server, port=port)
- elif protocol == 'https':
+
+ if target.scheme == 'http':
+ if 'http_proxy' in os.environ and need_proxy(target.hostname):
+ proxy = urlparse.urlparse(os.environ['http_proxy'])
+ conn = httplib.HTTPConnection(proxy.netloc)
+ conn.set_tunnel(
+ target.hostname,
+ target.port if target.port else 80
+ )
+ conn.connect()
+ else:
+ conn = httplib.HTTPConnection(target.netloc)
+ elif target.scheme == 'https':
+ useproxy = False
+ if 'https_proxy' in os.environ and need_proxy(target.hostname):
+ proxy = urlparse.urlparse(os.environ['https_proxy'])
+ useproxy = True
try:
ssl_context = ssl.create_default_context()
if cacert is not None:
ssl_context = ssl.create_default_context(cafile=cacert)
- conn = httplib.HTTPSConnection(server, port=port,
- context=ssl_context)
+ if useproxy:
+ conn = httplib.HTTPSConnection(
+ proxy.netloc,
+ context=ssl_context
+ )
+ conn.set_tunnel(
+ target.hostname,
+ target.port if target.port else 443
+ )
+ conn.connect()
+ else:
+ conn = httplib.HTTPSConnection(
+ target.netloc,
+ context=ssl_context
+ )
except AttributeError:
- conn = httplib.HTTPSConnection(server, port, None, cacert)
+ if useproxy:
+ conn = httplib.HTTPSConnection(
+ proxy.netloc,
+ key_file=None,
+ cert_file=cacert
+ )
+ conn.set_tunnel(
+ target.hostname,
+ target.port if target.port else 443
+ )
+ conn.connect()
+ else:
+ conn = httplib.HTTPSConnection(
+ target.netloc,
+ key_file=None,
+ cert_file=cacert
+ )
else:
print "Error, unknown protocol %s" % protocol
return None
Event Timeline
Log In to Comment