Commit Graph

234 Commits (cb5069bb8e7f9f98e50cd71184fabcd7ccd5c57a)

Author SHA1 Message Date
Allen Li e73ad0d422 [newauth] Remove SkipSSO support
This was only for testing.

Bug: b/404613530
Change-Id: I8e79f14036f027aed91933158805b6ec4c03b266
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6373672
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
1 month ago
Josip Sokcevic 04d6a4baa4 gerrit_util: Correctly handle abandon OK response
Recipe-Manual-Change: chrome_release
Bug: 403543870
Change-Id: I5137aa51fa43e696475a654811785c28d0283a08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6357156
Auto-Submit: Josip Sokcevic <sokcevic@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
1 month ago
Josip Sokcevic 454f6ce8e2 gerrit_util: Handle already abandoned change
R=keybo@google.com

Bug: 402023825
Change-Id: I104b0868152714384642ff0ea41bb9844e8d54db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6352741
Reviewed-by: Keybo Qian <keybo@google.com>
Auto-Submit: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Keybo Qian <keybo@google.com>
1 month ago
Allen Li b0d4f7c473 [gerrit_util] Add CheckShouldUseSSO function
This exposes the reason for the SSO detection, to be used in the auth
config wizard.

There are some minor changes to fix pyright (type checking) errors on
these lines.

Bug: b/401338175
Change-Id: Ibf63a1a078a9ae82598796e329d075f19de58ea7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6334613
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
2 months ago
Allen Li c4e7c8717c gerrit_util: Delete temporary text about auth testing setup
Change-Id: I6c61998c1fca2681f6dc0f33468a8ae5b378f12e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6306289
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
2 months ago
Allen Li 4ac4d26e80 gerrit_util: Always use SSO in Cog
Bug: 396027841
Change-Id: I0e4f8442b0b630afaf1b716115007af3cbf6ee38
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6306288
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
2 months ago
Allen Li a2fcf8d776 [auth] Fix luci-auth reference in comment
Unfixed when we migrated Gerrit auth to git-credential-luci

Bug: b/342261857
Change-Id: I6660f03de830337b14b822a0245f6e0d18a58366
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6174308
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
3 months ago
Mike Frysinger 232ffd8df3 gerrit: addmessage: support attention set control
Sometimes I want to add a message without touching the attention set.
The default review call will automatically update it regardless.  Add
a flag to explicitly control behavior.

Test:
	# No attention set option.
	$ ./gerrit_client.py ...
	-> ignore_automatic_attention_set_rules not included in body of request
	$ ./gerrit_client.py ... --automatic-attention
	-> body has {'ignore_automatic_attention_set_rules': False}
	$ ./gerrit_client.py ... --no-automatic-attention
	-> body has {'ignore_automatic_attention_set_rules': True}

Change-Id: Idcf7975ba691942cfe385a2156ef3a3ec064a0b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6172486
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
3 months ago
Alex Kravchuk 7bff40f521 Reduce gerrit_util.SubmitChange max retries from 6 to 2.
gerrit_utils retries failed HTTP requests 6 times by default. For SubmitChange the failure reason is often 409 on a merge conflict, which doesn't make sense to retry as the conflict remains.

This is being done as part of improving efficiency of submitting Chrome signing request changes. We currently spend a lot of time just retrying to submit a conflicting change. Reducing the number of retries in gerrit_util will free up the time for more retries that include fully recreating the change on top of the latest changes.

Bug: 365827690
Change-Id: Ifae83c14da7ca829a155c1cd6e79398e5ea0cf85
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6172303
Reviewed-by: Brian Ryner <bryner@google.com>
Commit-Queue: Alex Kravchuk <alexanderkr@google.com>
3 months ago
Allen Li f5637e5439 Fix caching Gerrit account presence outside of repos
This fixes the case where a user tries to fetch new repos but isn't in
a Git directory (probably true for most people if they don't have,
e.g., their home directory as a Git repo).

There are a couple of ways to bikeshed a solution for this, but the
most straightforward/easiest is to skip since we're just caching the
account presence check.

Bug: b/328682976
Change-Id: I87a0b210451e6952839eef73616d012c41ad300f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6154836
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
4 months ago
Allen Li 93954a51a1 Fix exception handling when checking account existence
Didn't catch changing the exception name when switching to
git-credential-luci earlier.

Issue can be seen in
https://groups.google.com/a/chromium.org/g/chromium-dev/c/Co66Vjzrbew/m/er7P7m6vAgAJ

Change-Id: I89674c1654980b1e2478868072ab28aa0d0bc7a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6120690
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
4 months ago
Allen Li 7415741889 Add missing luci_auth property to GitCredsAuthenticator
Missed copying this in
https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6073043

Bug: b/382341041
Change-Id: I39b8ea654be603b020dd944cc8cd0404b063e496
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6082492
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Auto-Submit: Allen Li <ayatane@chromium.org>
5 months ago
Allen Li 522f5a4bd1 gerrit_util: Use git-credential-luci instead of luci-auth
git-credential-luci is very similar to luci-auth, except that it is
expressly for git/Gerrit.  Therefore, it hard codes the scopes needed
for git/Gerrit.  It's also a separate binary, which makes it more
convenient for us to configure it for ReAuth later.

Bug: b/382341041
Change-Id: I7de56d3922adac7eb4671849eb6e30be310d4de7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6073043
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
5 months ago
Yiwei Zhang ff14128b8a gerrit_util: add revision kwarg to SetReview
This will allow the caller to specify which revision to modify.

Bug: 378480632
Change-Id: I4cb184932f923d9bd43eb556097cb52029c185a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6012698
Auto-Submit: Yiwei Zhang <yiwzhang@google.com>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
6 months ago
Anne Redulla d6528a124b [git-sso] Read sso helper output line by line
On Windows, the subprocess running the sso helper does not
complete the `read()` in time. This CL reads the output
line by line, and stops reading once the required fields
have been specified.

Bug: b/360206460
Change-Id: Ib5f95093cd6f9bbbe5093a7e16393ecd97934cf2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5992110
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Anne Redulla <aredulla@google.com>
6 months ago
Allen Li 4b94130034 [gerrit_util] Add fallback if missing Gerrit account
Bug: b/366261039
Change-Id: I7d22c4f03ad9bd837190dee7a511af3437a30434
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5869050
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
7 months ago
Allen Li 74ec765457 [gerrit_util] Skip gitcookies help with newauth enabled
Change-Id: Ie74761efd7bbb50051994a83f21ed150ddf8e4c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5871206
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
7 months ago
Allen Li b32c4f1abc [gerrit_util] Add auth parameter to GetAccountDetails
We need to use this to determine if an account exists to determine
what auth to use, so we have to be able to override the default auth
detection.

Bug: b/366261039
Change-Id: I814b47ac1518170846ff9a7e5dc210f26db3e985
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5869049
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
7 months ago
Allen Li 6429a2f9e5 [gerrit_util] Fix ShouldUseSSO with no account
Bug: b/366261039
Change-Id: I77cd3a45ebb6e67eebcae6dc44a30b46b954a545
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5867127
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
7 months ago
Allen Li 3a7d070966 [gerrit_utils] Add caching to ShouldUseSSO
This only lasts per process invocation, so we don't worry about cache
size (and it's a minor performance save).

Bug: b/350806563
Change-Id: Ie8e1aa2933c5582a3a2e2f75f04590f6bb432c4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5833280
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
8 months ago
Allen Li dc8d502d13 [gerrit_util] Don't try to use SSO on non-googlesource hosts
In case you're getting funny thoughts, these requests would not attach
any cookies anyway because the domain doesn't match.  It just allows
requests to properly fallback to OAuth path.

Bug: b/362741558
Change-Id: Iaf83ad640501ff45671dbc358e676cbeaf04d686
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5824222
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
8 months ago
Gavin Mak 2836a02f55 Make "git cl cherry-pick" handle failed cherry picks better
"Better" means:
1. Retrying a failed gerrit_util.CherryPick only once instead
   of 5 times for faster feedback since more retries don't help.
2. Gracefully handling GerritErrors raised by gerrit_util.CherryPick

This CL also fixes a minor bug where the "Remaining commit(s) to
cherry pick" message would always print even if there were no more
commits left.

Bug: 341792235
Change-Id: I1712a6b080b14396463f3bceeeac84772f1253b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5825626
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Joanna Wang <jojwang@chromium.org>
8 months ago
Allen Li 617f167a13 [gerrit_util] Add proxy support for other HTTP methods
Bug: b/351039944
Change-Id: If65096cd1023d695270ee4285a9ed27fcd944738
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5805746
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
8 months ago
Gavin Mak d4c6d40d50 Reduce RebaseChange max tries from 6 to 2
On failure, gerrit_util always retries HTTP requests the maximum
number of times. This doesn't always make sense, e.g. for RebaseChange
which gets 409 on a merge conflict and can't be retried into
succeeding.

Bug: b/341792235
Change-Id: I6f9e212c5b0365236a99768f056bab2eb60cddc6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5773566
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
9 months ago
Gavin Mak ec800aa077 Add "git cl cherry-pick" for cherry picking a chain of CLs via Gerrit
Users who want to upload multiple cherry picks usually run "git
cherry-pick" locally, multiple times. Gerrit does not recognize
these changes as cherry picks and neither do other services that
query cherry pick info from Gerrit, e.g. rubber stamper.

For Gerrit to identify a change as a true cherry pick, you need to
use their Cherry Pick Revision REST API endpoint. This new command
uses it to create a chain of cherry pick CLs recognized by Gerrit.

Bug: b/341792235
Change-Id: I4ba75da3901f6ea68c1debd65820e802da681798
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5756161
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
9 months ago
Allen Li 29838db8fe [gerrit_util] Add type annotations
Bug: b/351071334
Change-Id: I9e31f14120953e89f6cef3759f595f6aca79cd33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5754253
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
9 months ago
Robert Iannucci 863573b665 [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>
9 months ago
Gavin Mak 7a0c603984 Add CherryPickCommit to gerrit_util
This adds a helper function for this cherrypick endpoint:
https://gerrit-review.googlesource.com/Documentation/rest-api-projects.html#cherry-pick-commit

Compared to gerrit_util.CherryPick, this doesn't require the caller to
provide a change id.

Bug: b/341792235
Change-Id: I874321d182464af45837194d5cef9d650361b8c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5731033
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
9 months ago
Allen Li 397bf12548 [git_cl] Default to SSO with missing email
This is a safer default if SSO is available

Bug: b/351071334
Change-Id: I2d6b3b5c0fbe3fb7b9783de3d7548be7f14d7391
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5723448
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
9 months ago
Allen Li 91937bf196 [git_cl] Parametrize email in ShouldUseSSO
Moves the dependency on Git+cwd up the call stack

Bug: b/351071334
Change-Id: Ia313f9d4720ee10398b757217c333118e9fc7341
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5723091
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
9 months ago
Allen Li 4986d4a74b [git_cl] Parametrize cwd in ShouldUseSSO
Remove implicit/global assumptions which could affect tests.

Bug: b/351071334
Change-Id: Ie266228f404b768cb539fdc17dddbbb13693e939
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5723208
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
9 months ago
Robert Iannucci 779f70fd7c [gerrit_util] Move Authenticator to be private in gerrit_util.
This should help give additional confidence while refactoring in
gerrit_util.

R=ayatane, yiwzhang

Change-Id: I03927e072e62f6109571ab699f90db7c51ccc6c0
Bug: b/335483238
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5665455
Auto-Submit: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
10 months ago
Daniel Rubery 9e9fc99280 Fallback to looking up CL issue from triplet_id
In nosquash mode, `git cl` is pretty challenging to use since we don't
have issue numbers. All three parts of the triplet id are readily
available though. This CL adds a fallback to `git cl` which looks up the
issue number by getting the change details by triplet_id.

Change-Id: I0839fe75bcb4bc8d60ff36b4da26dc0e419a1493
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5633186
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
10 months ago
Allen Li 21b86f4b1c [gerrit_util] Fix typo
Bug: b/351039944
Change-Id: If906ddfdae10b6ba9051eced2b1e7a2c24d54aad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5677486
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Auto-Submit: Allen Li <ayatane@chromium.org>
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
10 months ago
Allen Li 3c93933ce9 [gerrit_util] Add note about workaround
Bug: b/349433100
Change-Id: I287499a339e1f5d3eab9c5a63068ad68ecd67a11
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5677617
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Auto-Submit: Allen Li <ayatane@chromium.org>
10 months ago
Allen Li ca091f0d16 [gerrit_util] Update docstring for new param
Change-Id: Ifb6106ad0063183ee0a0377bb3564c4fc99d88ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5673779
Auto-Submit: Allen Li <ayatane@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
10 months ago
Allen Li ea366e35f0 [gerrit_util] Use shared SSO logic for SSOAuthenticator
Bug: b/348024314
Change-Id: I1bc9aa297360421fad3fd11b157be3c439f944c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5665454
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
10 months ago
Gavin Mak 280b823136 Link to the new password URL when authentication fails
Instead of just telling users their credentials are missing, link them to the new password URL so they can fix it.

Change-Id: I9559868ae948e6d18cef1205083aee0ad5c2489a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5665862
Commit-Queue: Joanna Wang <jojwang@chromium.org>
Auto-Submit: Gavin Mak <gavinmak@google.com>
Reviewed-by: Joanna Wang <jojwang@chromium.org>
10 months ago
Allen Li f4e8e13e8b [gerrit_util] Add linked account detection for SSO
Bug: b/348024314
Change-Id: Ic982de2892769870805407c6a00856943133dd62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5651293
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
10 months ago
Allen Li 459e1a54a5 [gerrit_util] Add ChainedAuthenticator
Because we need to dynamically determine whether to use SSO.

Bug: b/348024314
Change-Id: I5ac768f1e0c20254b4cfd4815270ee4e2b9a5544
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5660884
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
10 months ago
Allen Li 334a3acddb [gerrit_util] Fix typo
Bug: b/348024314
Change-Id: I6419ad006535d2763b190d2e4f354816e3fd1c8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5651991
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
10 months ago
Allen Li 24e9380bc5 [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>
10 months ago
Allen Li 3a5d348a0b [gerrit_util] Add ShouldUseSSO helper
Bug: b/348024314
Change-Id: I5b061bc6afeffbc84aee12250732e96a0ad0f32b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5651287
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
10 months ago
Allen Li bb38aa2f8e [gerrit_util] Use SSO only if configured with appropriate email
So you can use chromium.org or other accounts in some repos

Bug: b/348024314
Change-Id: Ice6b6d9e6e827a606a2ce7f3b127d4660df1aedf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5641255
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
10 months ago
Robert Iannucci 005e60ceda [git_cl] Make EnsureCanUploadPatchset work for all auth methods.
Previously EnsureCanUploadPatchset only had a working implementation
for the CookiesAuthenticator, relying on being able to parse the
user name out of the .gitcookies file.

Additionally, the previous implementation assumed that you would
always authenticate as your primary Gerrit account OR you had
a matching `user.email` gitconfig entry, even though neither of these
is a strict requirement for the upload to work.

The new implementation still short-circuits if issue_owner matches
the configured user.email, but other than this it just asks Gerrit
what the full list of linked emails is for the currently authenticated
account.

The new approach is not only correct, but will now work for all auth
schemes in exactly the same way.

When the accounts do mismatch, you will now see output like:

```
WARNING: Change 5590262 is owned by iannucci@chromium.org, but Gerrit knows you as:
  * user@example.org
  * other.user@example.com
  * primary@real.example.com (preferred)
Uploading may fail due to lack of permissions.
```

R=ayatane@chromium.org, yiwzhang@google.com

Bug: 336351842
Change-Id: I89c1b121c9110e00d1348884aaf025fc783542d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5590262
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Auto-Submit: Robbie Iannucci <iannucci@chromium.org>
10 months ago
mlcui 6592795601 gerrit_util: Fix NameError in GceAuthenticator._get
Bug: None
Change-Id: I6a6a210069da0f77ebbed4c6ef530864cb2d8109
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5644850
Reviewed-by: Gavin Mak <gavinmak@google.com>
Auto-Submit: Michael Cui <mlcui@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
10 months ago
Robert Iannucci 6daca50597 [git_cl] Refactor EnsureAuthenticated logic.
This will allow us to implement EnsureAuthenticated for other
Authenticator implementations.

R=ayatane@chromium.org

Bug: 336351842
Change-Id: I5ff4efd45eb5baa6baa048842510ec6e18e1b8fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5588510
Auto-Submit: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
10 months ago
Robert Iannucci 137bb69871 [gerrit_util] Cache resolved Authenticator as a class variable.
I noticed that the Authenticator is resolved maybe 5 or 6 times per
git-cl invocation. This should lead to more consistent behavior and
will likely be a bit faster, especially for SSOAuthenticator and
LuciAuthAuthenticator which involve subprocess invocations.

R=ayatane@chromium.org

Bug: 336351842
Change-Id: Id6c2873a6960a171305560acb98afe2c4f397295
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5589865
Auto-Submit: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
10 months ago
Allen Li bdf64705c3 [gerrit_util] Factor out SSOHelper
Add a layer of abstraction/isolation for general organization.

Also, this logic needs to be used in Git setup too, not just Gerrit
authentication.

Bug: b/348024314
Change-Id: Ie1310a9b8e71c05c72a4b987dcbff76b70c67945
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5645906
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
10 months ago
Robert Iannucci c4c3d5326e [gerrit_util] Add some additional tests and fixes for SSOAuthenticator.
Unfortunately, the depot_tools presubmit builders are incredibly slow
which make the subprocess based tests fail flakily. I've marked them
all as `skip` with an optional way to run them locally.

R=ayatane, yiwzhang

Bug: b/335483238
Change-Id: I407aed3a1ed01563a0a80973b679aca405b9cde9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5641259
Auto-Submit: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
10 months ago