[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 <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
changes/88/5651288/3
Allen Li 1 year ago committed by LUCI CQ
parent 3a5d348a0b
commit 24e9380bc5

@ -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

Loading…
Cancel
Save