[gerrit_util] Automatically re-warm SSO cookies.

In the event that `git-remote-sso` doesn't yield the expected
cookies, run `git ls-remote` on chromium/All-Projects.

This operation is fairly quick and robust - this fallback code
should only execute at most 1/day.

R=ayatane, yiwzhang

Change-Id: I5290f47e56341e9c4fd3b295ae117650f592dc7c
Bug: 342644760
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5741848
Auto-Submit: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
changes/48/5741848/2
Robert Iannucci 9 months ago committed by LUCI CQ
parent 64908716d7
commit 863573b665

@ -495,9 +495,22 @@ class SSOAuthenticator(_Authenticator):
@classmethod
def _get_sso_info(cls) -> SSOInfo:
with cls._sso_info_lock:
info = cls._sso_info
if not info:
info = cls._launch_sso_helper()
# HACK: `git-remote-sso` doesn't always properly warm up the
# cookies - in this case, run a canned git operation against
# a public repo to cause `git-remote-sso` to warm the cookies
# up, and then try pulling config again.
#
# BUG: b/342644760
if not any(c.domain == '.google.com' for c in info.cookies):
LOGGER.debug('SSO: Refreshing .google.com cookies.')
scm.GIT.Capture(['ls-remote', 'sso://chromium/All-Projects'])
info = cls._launch_sso_helper()
if not any(c.domain == '.google.com' for c in info.cookies):
raise ValueError('Unable to extract .google.com cookie.')
cls._sso_info = info
return info
@ -525,9 +538,7 @@ class SSOAuthenticator(_Authenticator):
# Finally, add cookies
sso_info.cookies.add_cookie_header(conn)
assert 'Cookie' in conn.req_headers, (
'sso_info.cookies.add_cookie_header failed to add Cookie'
' (try running `git ls-remote sso://chromium/All-Projects` and retrying)'
)
'sso_info.cookies.add_cookie_header failed to add Cookie.')
def debug_summary_state(self) -> str:
return ''

Loading…
Cancel
Save