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

Unified Diff: gclient_utils.py

Issue 9214004: Add UpgradeToHttps() to reliably and forcibly upgrade all urls to https (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Saner processing. Had to workaround urlparse default behavior Created 8 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 | « gcl.py ('k') | git_cl.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gclient_utils.py
diff --git a/gclient_utils.py b/gclient_utils.py
index e5784ac4730dad01ea0f2deda30817f3e3df1aa4..35f8b3bf44ef69ed02c72422c73125e7f671f2c1 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -14,6 +14,7 @@ import sys
import tempfile
import threading
import time
+import urlparse
import subprocess2
@@ -734,6 +735,30 @@ def RunEditor(content, git):
os.remove(filename)
+def UpgradeToHttps(url):
+ """Upgrades random urls to https://.
+
+ Do not touch unknown urls like ssh:// or git://.
+ Do not touch http:// urls with a port number,
+ Fixes invalid GAE url.
+ """
+ if not url:
+ return url
+ if not re.match(r'[a-z\-]+\://.*', url):
+ # Make sure it is a valid uri. Otherwise, urlparse() will consider it a
+ # relative url and will use http:///foo. Note that it defaults to http://
+ # for compatibility with naked url like "localhost:8080".
+ url = 'http://%s' % url
+ parsed = list(urlparse.urlparse(url))
+ # Do not automatically upgrade http to https if a port number is provided.
+ if parsed[0] == 'http' and not re.match(r'^.+?\:\d+$', parsed[1]):
+ parsed[0] = 'https'
+ # Until GAE supports SNI, manually convert the url.
+ if parsed[1] == 'codereview.chromium.org':
+ parsed[1] = 'chromiumcodereview.appspot.com'
+ return urlparse.urlunparse(parsed)
+
+
def ParseCodereviewSettingsContent(content):
"""Process a codereview.settings file properly."""
lines = (l for l in content.splitlines() if not l.strip().startswith("#"))
@@ -742,5 +767,9 @@ def ParseCodereviewSettingsContent(content):
except ValueError:
raise Error(
'Failed to process settings, please fix. Content:\n\n%s' % content)
- # TODO(maruel): Post-process
+ def fix_url(key):
+ if keyvals.get(key):
+ keyvals[key] = UpgradeToHttps(keyvals[key])
+ fix_url('CODE_REVIEW_SERVER')
+ fix_url('VIEW_VC')
return keyvals
« no previous file with comments | « gcl.py ('k') | git_cl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698