Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Unified Diff: gsutil.py

Issue 841823002: gsutil: Pass proxy information via Boto options. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Patch v3 with different order Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gsutil.py
diff --git a/gsutil.py b/gsutil.py
index 6578d7844171202eb787bf1414c4a371e15a75a0..623223a1a317b2e11443ac2fbc8b1c76f051209b 100755
--- a/gsutil.py
+++ b/gsutil.py
@@ -15,6 +15,7 @@ import shutil
import subprocess
import sys
import urllib2
+import urlparse
import zipfile
@@ -121,12 +122,43 @@ def ensure_gsutil(version, target):
return gsutil_bin
+def get_boto_proxy_options_from_environment():
+ """Derive proxy options for gsutil from the environment.
+
+ Parses the contents of the 'http[s]_proxy' (and variations) environment
+ variable and converts it to the corresponding Boto options that gsutil
+ accepts.
+ """
+ proxy_variable = None
Primiano Tucci (use gerrit) 2015/01/09 17:17:31 I think you can squeeze lines 132-136 in: vars = (
+ for env_var in ('https_proxy', 'HTTPS_PROXY', 'http_proxy', 'HTTP_PROXY'):
+ if env_var in os.environ:
+ proxy_variable = env_var
+ break
+ if proxy_variable is None:
Primiano Tucci (use gerrit) 2015/01/09 17:17:31 I think here you want to check: if not proxy_varia
Raphael Kubo da Costa 2015/01/09 17:54:12 Doing this works, but if I only store os.environ[v
+ return []
+
+ proxy_url = urlparse.urlsplit(os.environ[proxy_variable])
+ if proxy_url.hostname is None or proxy_url.port is None:
+ raise EnvironmentError(
Primiano Tucci (use gerrit) 2015/01/09 17:17:31 Not sure you want to be so strict on the port. Wha
Raphael Kubo da Costa 2015/01/09 17:54:12 As far as I can see, httplib2 (which gsutil uses)
+ 'The "%s" environment is set, but has an invalid format. Its '
+ 'format must be "http://[user[:password]@]host:port".' % proxy_variable)
+ boto_options = ['-o', 'Boto:proxy=%s' % proxy_url.hostname,
+ '-o', 'Boto:proxy_port=%d' % proxy_url.port]
+ if proxy_url.username:
+ boto_options.extend(['-o', 'Boto:proxy_user=%s' % proxy_url.username])
+ if proxy_url.password:
+ boto_options.extend(['-o', 'Boto:proxy_pass=%s' % proxy_url.password])
+ return boto_options
+
+
def run_gsutil(force_version, fallback, target, args):
if force_version:
gsutil_bin = ensure_gsutil(force_version, target)
+ proxy_options = get_boto_proxy_options_from_environment()
else:
gsutil_bin = fallback
- cmd = [sys.executable, gsutil_bin] + args
+ proxy_options = [] # Not available in the fallback gsutil.
+ cmd = [sys.executable, gsutil_bin] + proxy_options + args
try:
call(cmd)
except SubprocessError as e:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698