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

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 v2 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..8b338df680c7ae3ddb8bd1d05459b7f501eeea1c 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,42 @@ 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_proxy' (and variations) environment variable
+ and converts it to the corresponding Boto options that gsutil accepts.
+ """
+ proxy_variable = None
+ for env_var in ('http_proxy', 'HTTP_PROXY', 'https_proxy', 'HTTPS_PROXY'):
agable 2015/01/08 20:39:01 Shouldn't we prioritize an https proxy over an htt
Raphael Kubo da Costa (rakuco) 2015/01/08 22:29:02 I don't have a strong opinion here, as the whole t
+ if env_var in os.environ:
+ proxy_variable = env_var
+ break
+ if proxy_variable is None:
+ return []
+
+ proxy_url = urlparse.urlsplit(os.environ[proxy_variable])
+ if proxy_url.hostname is None or proxy_url.port is None:
+ raise EnvironmentError(
+ 'The "%s" environment is set, but has an invalid format. Its '
+ 'format must be "http://[user[:password]]host:port".' % proxy_variable)
agable 2015/01/08 20:39:01 [user[:password]@]host:port
+ 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