Skip to content

Commit 1368562

Browse files
committed
retrieve credential from proxy_host
1 parent 358bc56 commit 1368562

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

.travis.s3cfg

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,8 @@ multipart_chunk_size_mb = 15
4747
multipart_max_chunks = 10000
4848
preserve_attrs = True
4949
progress_meter = True
50-
proxy_host =
50+
proxy_host =
5151
proxy_port = 0
52-
proxy_username =
53-
proxy_password =
5452
put_continue = False
5553
recursive = False
5654
recv_chunk = 65536

S3/Config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ class Config(object):
153153
acl_revokes = []
154154
proxy_host = u""
155155
proxy_port = 3128
156-
proxy_username = u""
157-
proxy_password = u""
158156
encrypt = False
159157
dry_run = False
160158
add_encoding_exts = u""

S3/ConnMan.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from .Config import Config
2929
from .Exceptions import ParameterError, S3SSLCertificateError
30-
from .Utils import getBucketFromHostname
30+
from .Utils import getBucketFromHostname, deunicodise_s, unicodise_s
3131

3232

3333

@@ -231,17 +231,21 @@ def __init__(self, id, hostname, ssl, cfg):
231231
debug(u'non-proxied HTTPConnection(%s, %s)', self.hostname, self.port)
232232
else:
233233
headers = {}
234-
if cfg.proxy_username and cfg.proxy_password:
234+
proxy_hostname = cfg.proxy_host
235+
if '@' in cfg.proxy_host:
236+
credential, proxy_hostname = cfg.proxy_host.split('@')
237+
# FIXME: Following line can't handle username or password including colon
238+
proxy_username, proxy_password = credential.split(':')
235239
headers['Proxy-Authorization'] = 'Basic ' + \
236-
b64encode(('%s:%s' % (cfg.proxy_username, cfg.proxy_password)).encode('utf-8')).decode('ascii')
240+
unicodise_s(b64encode(deunicodise_s(('%s:%s' % (proxy_username, proxy_password)))))
237241
if ssl:
238-
self.c = http_connection._https_connection(cfg.proxy_host, cfg.proxy_port)
242+
self.c = http_connection._https_connection(proxy_hostname, cfg.proxy_port)
239243
debug(u'proxied HTTPSConnection(%s, %s)', cfg.proxy_host, cfg.proxy_port)
240244
port = self.port and self.port or 443
241245
self.c.set_tunnel(self.hostname, port, headers)
242246
debug(u'tunnel to %s, %s', self.hostname, port)
243247
else:
244-
self.c = httplib.HTTPConnection(cfg.proxy_host, cfg.proxy_port)
248+
self.c = httplib.HTTPConnection(proxy_hostname, cfg.proxy_port)
245249
debug(u'proxied HTTPConnection(%s, %s)', cfg.proxy_host, cfg.proxy_port)
246250
# No tunnel here for the moment
247251

0 commit comments

Comments
 (0)