From 24e9380bc582fb7eb5c889d9842fc1e41ddd8ca9 Mon Sep 17 00:00:00 2001 From: Allen Li Date: Mon, 24 Jun 2024 23:07:12 +0000 Subject: [PATCH] [gerrit_util] Add explicit authenticator param We need this to figure out which authenticator to use, so we need to override the initial "bootstrap" authenticator. Bug: b/348024314 Change-Id: I52c5b1db83bc4e2a0a1ec2a07155d352b593cde4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5651288 Reviewed-by: Yiwei Zhang Commit-Queue: Allen Li --- gerrit_util.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gerrit_util.py b/gerrit_util.py index cac3327b4..f8c6f66cd 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -826,7 +826,9 @@ def CreateHttpConn(host, reqtype='GET', headers: Optional[Dict[str, str]] = None, body: Optional[Dict] = None, - timeout=300) -> HttpConn: + timeout=300, + *, + authenticator: Optional[Authenticator] = None) -> HttpConn: """Opens an HTTPS connection to a Gerrit service, and sends a request.""" headers = headers or {} bare_host = host.partition(':')[0] @@ -850,7 +852,8 @@ def CreateHttpConn(host, req_headers=headers, req_body=rendered_body) - authenticator = Authenticator.get() + if authenticator is None: + authenticator = Authenticator.get() # TODO(crbug.com/1059384): Automatically detect when running on cloudtop. if isinstance(authenticator, GceAuthenticator): print('If you\'re on a cloudtop instance, export ' @@ -1658,7 +1661,11 @@ class EmailRecord(TypedDict): preferred: bool # This should be NotRequired[bool] in 3.11+ -def GetAccountEmails(host, account_id='self') -> Optional[List[EmailRecord]]: +def GetAccountEmails(host, + account_id='self', + *, + authenticatator: Optional[Authenticator] = None + ) -> Optional[List[EmailRecord]]: """Returns all emails for this account, and an indication of which of these is preferred. @@ -1672,7 +1679,9 @@ def GetAccountEmails(host, account_id='self') -> Optional[List[EmailRecord]]: Returns None if account is not found (i.e. Gerrit returned 404). """ - conn = CreateHttpConn(host, '/accounts/%s/emails' % account_id) + conn = CreateHttpConn(host, + '/accounts/%s/emails' % account_id, + authenticator=authenticator) resp = ReadHttpJsonResponse(conn, accept_statuses=[200, 404]) if resp is None: return None