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

Unified Diff: gerrit_util.py

Issue 278203002: gerrit_util is aware of auth errors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: moved auth check into the retry loop Created 6 years, 7 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 | trychange.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gerrit_util.py
diff --git a/gerrit_util.py b/gerrit_util.py
index c8d838c7eaced6565fbb08ec12991cac2e37ba6d..984fa101458c996f1e582072f91e5369644e1ac8 100755
--- a/gerrit_util.py
+++ b/gerrit_util.py
@@ -14,6 +14,7 @@ import json
import logging
import netrc
import os
+import re
import time
import urllib
from cStringIO import StringIO
@@ -38,6 +39,10 @@ class GerritError(Exception):
self.message = '(%d) %s' % (self.http_status, self.message)
+class GerritAuthenticationError(GerritError):
+ """Exception class for authentication errors during Gerrit communication."""
+
+
def _QueryString(param_dict, first_param=None):
"""Encodes query parameters in the key:val[+key:val...] format specified here:
@@ -115,6 +120,17 @@ def ReadHttpResponse(conn, expect_status=200, ignore_404=True):
sleep_time = 0.5
for idx in range(TRY_LIMIT):
response = conn.getresponse()
+
+ # Check if this is an authentication issue.
+ www_authenticate = response.getheader('www-authenticate')
+ if (response.status in (httplib.UNAUTHORIZED, httplib.FOUND) and
+ www_authenticate):
+ auth_match = re.search('realm="([^"]+)"', www_authenticate, re.I)
+ host = auth_match.group(1) if auth_match else conn.req_host
+ reason = ('Authentication failed. Please make sure your .netrc file '
+ 'has credentials for %s' % host)
+ raise GerritAuthenticationError(response.status, reason)
+
# If response.status < 500 then the result is final; break retry loop.
if response.status < 500:
break
« no previous file with comments | « no previous file | trychange.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698