From 447507ed82fec1c1225652dfa726d9de0d5356a4 Mon Sep 17 00:00:00 2001 From: Edward Lemur Date: Tue, 31 Mar 2020 17:33:54 +0000 Subject: [PATCH] git-cl: Move GCE detection when creating a connection. Print it unconditionally when creating the HTTP connection. The previous check was not capturing all possible failure modes. Change-Id: Ie519f3c3afdbb2e452fbea2385cd75c3d5d1af84 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2129148 Reviewed-by: Josip Sokcevic Commit-Queue: Edward Lesmes --- gerrit_util.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gerrit_util.py b/gerrit_util.py index d22c7f1ed..87884705c 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -366,7 +366,13 @@ def CreateHttpConn(host, path, reqtype='GET', headers=None, body=None): headers = headers or {} bare_host = host.partition(':')[0] - a = Authenticator.get().get_auth_header(bare_host) + a = Authenticator.get() + # TODO(crbug.com/1059384): Automatically detect when running on cloudtop. + if isinstance(a, GceAuthenticator): + print('If you\'re on a cloudtop instance, export ' + 'SKIP_GCE_AUTH_FOR_GIT=1 in your env.') + + a = a.get_auth_header(bare_host) if a: headers.setdefault('Authorization', a) else: @@ -467,10 +473,6 @@ def ReadHttpResponse(conn, accept_statuses=frozenset([200])): host = auth_match.group(1) if auth_match else conn.req_host print('Authentication failed. Please make sure your .gitcookies ' 'file has credentials for %s.' % host) - # TODO(crbug.com/1059384): Automatically detect when running on cloudtop. - if isinstance(Authenticator.get(), GceAuthenticator): - print('If you\'re on a cloudtop instance, export ' - 'SKIP_GCE_AUTH_FOR_GIT=1 in your env.') print('Try:\n git cl creds-check') reason = '%s: %s' % (response.reason, contents)