Skip to content

try_api: implement /patches endpoint (bug 1979247, bug 1983216)#473

Closed
shtrom wants to merge 1 commit intomainfrom
bug1979247/try/patches
Closed

try_api: implement /patches endpoint (bug 1979247, bug 1983216)#473
shtrom wants to merge 1 commit intomainfrom
bug1979247/try/patches

Conversation

@shtrom
Copy link
Member

@shtrom shtrom commented Aug 13, 2025

Reimplement the /try/patches endpoint from old lando, so mach try can submit Try job to this version of Lando using the same API.


  • repo: add is_try field (bug 1979247)
  • settings: add try_api to APPLICATIONS (bug 1979247)
  • create_environment_repos: add try repo in suite (bug 1986575)
  • try_api: patches endpoint (bug 1979247)
  • try_api: use django.test.clients (bug 2008895)
  • try_api: add error handling with RFC 7807 responses
  • try_api/tests: add client_post fixture
  • try_api: check user permission against target_repo
  • try_api: remove extra argument to logger
  • utils.ninja_auth: move AccessTokenLandoOIDCAuthenticationBackend to main.auth, and rename
  • CommitMap: add TRY_REPO_MAPPING to support determining where to lookup CommitMaps from
  • Repo: add user_can_push method to check direct required_permission on User
  • update for Repo.user_allowed
  • tests: update fixtures for Try repo parameters
  • create_environment_repos: disable commit message hook for try
  • auth: don't create Django users on API requests
  • try_api: use SCM rather than VCS in user messaging
  • try_api/tests: don't embed b64 literals
  • try_api: move some PatchHelper calls out of try/except

@shtrom shtrom force-pushed the bug1979247/try/patches branch 5 times, most recently from 9beacc1 to 19161a2 Compare August 15, 2025 06:44
@shtrom shtrom force-pushed the bug1909723/auth0-access_token branch 2 times, most recently from 6d1386e to 3ac4ed5 Compare August 18, 2025 08:06
@shtrom shtrom force-pushed the bug1979247/try/patches branch from 6bd2ed4 to 62e6e99 Compare August 26, 2025 04:28
Base automatically changed from bug1909723/auth0-access_token to main August 27, 2025 01:49
@shtrom shtrom force-pushed the bug1979247/try/patches branch 2 times, most recently from 59e52b1 to e28e179 Compare September 3, 2025 05:26
@shtrom shtrom changed the base branch from main to bug1983746/patchhelper-bytes September 3, 2025 05:46
@shtrom shtrom force-pushed the bug1979247/try/patches branch from e28e179 to 8ddf2d4 Compare September 3, 2025 08:20
Base automatically changed from bug1983746/patchhelper-bytes to main September 4, 2025 01:01
@shtrom shtrom force-pushed the bug1979247/try/patches branch 9 times, most recently from 04e0d91 to 69ac9bf Compare September 16, 2025 06:28
@shtrom shtrom force-pushed the bug1979247/try/patches branch 7 times, most recently from a82fb77 to 24c340d Compare September 22, 2025 08:55
@shtrom shtrom dismissed zzzeid’s stale review January 12, 2026 03:35

addressed + discussion

@shtrom shtrom changed the base branch from main to perm-check January 12, 2026 07:34
@shtrom
Copy link
Member Author

shtrom commented Jan 12, 2026

Now based on #476 as it relies on the permission checking logic.

@shtrom shtrom force-pushed the bug1979247/try/patches branch from 9b87c41 to cf95e87 Compare January 12, 2026 07:39
@shtrom shtrom changed the title try_api: implement /patches endpoint (bug 1979247) try_api: implement /patches endpoint (bug 1979247, bug 1983216) Jan 12, 2026
Copy link
Contributor

@zzzeid zzzeid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few more changes requested. Overall looking good, main comments are around permission checking.

@shtrom shtrom requested a review from zzzeid January 19, 2026 03:43
@shtrom
Copy link
Member Author

shtrom commented Jan 19, 2026

@zzzeid all comments addressed. The permission check changes are in #476, which can be reviewed/landed independently.

I'm not sure why this PR here shows conflicts at the moment, as I think it's up-to-date with main. In any case, it'll likely need a rebasing before landing, as I suspect we'll get conflicts when applying the patches in sequence.

Copy link
Contributor

@zzzeid zzzeid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great! Final stretch I think.

Copy link
Contributor

@zzzeid zzzeid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - just a bit of cleanup in src/lando/main/auth.py and I think this will be ready to land.

I think we should clean up some of this auth backend business in a separate follow up, I'll file a QoL bug for this. Ideally we'd be able to reuse this functionality as a standard auth backend.

@shtrom
Copy link
Member Author

shtrom commented Jan 30, 2026

Looks good - just a bit of cleanup in src/lando/main/auth.py and I think this will be ready to land.

Ok, done 😅

I think we should clean up some of this auth backend business in a separate follow up, I'll file a QoL bug for this. Ideally we'd be able to reuse this functionality as a standard auth backend.

Yeah, Ninja diverges ever so slightly from Django auth. That said, I think the way the Token backend currently is, it should be already usable by Django. The Ninja-specific adaptation is done in ninja_auth.AccessTokenAuth.

@shtrom
Copy link
Member Author

shtrom commented Jan 30, 2026

Ideally we'd be able to reuse this functionality as a standard auth backend.

Yeah, Ninja diverges ever so slightly from Django auth. That said, I think the way the Token backend currently is, it should be already usable by Django. The Ninja-specific adaptation is done in ninja_auth.AccessTokenAuth.

More on this: I think this is already the case.

I've removed the fallback for now, but I think this is what would make the auth backend less standard, as it would now only allow Token-based auth... Though I think that I now see where you're going: do you mean to aim for dedicated auth backends for token vs. OIDC flow, rather than one implementing both, so we can mix and match depending on need?

In a way, that's something that would sit better in the mozilla-django-oidc lib, but in a different way than how I implemented it (or maybe very much in the current state of the auth.AccessTokenLandoOIDCAuthenticationBackend) We do retain the fact that the LandoOIDCAuthenticationBackend has the post-user creation hooks, that would need to be shared between the two classes.

Anyway, I'm just rambling at this point, and trying to capture my understanding somewhere. Let's chat about it next time we catch up!

@shtrom shtrom requested a review from zzzeid January 30, 2026 02:08
Copy link
Contributor

@zzzeid zzzeid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! (with a couple of nits)

@shtrom shtrom force-pushed the bug1979247/try/patches branch 2 times, most recently from a1eb891 to c3318bb Compare February 4, 2026 04:14
@shtrom
Copy link
Member Author

shtrom commented Feb 4, 2026

@zzzeid I updated AccessTokenLandoOIDCAuthenticationBackend as per your suggestion, and I'm testing in develop. I'll merge this tomorrow.

@shtrom
Copy link
Member Author

shtrom commented Feb 24, 2026

As part of rebasing this to avoid conflicts, I've managed to cleanly separate

  • scm: add SCMType enum to helpers

into its own PR: #945

@shtrom shtrom force-pushed the bug1979247/try/patches branch from 03c4ef2 to e51e03f Compare February 25, 2026 05:08
@shtrom
Copy link
Member Author

shtrom commented Feb 25, 2026

Pfiou. Rebased on main, with the SCMType logic split out (and landed) to #945, and the line-ending fix for generate_requirements.py split out to #947.

diff from the force-push: https://github.com/mozilla-conduit/lando/compare/03c4ef2be7bfa79219f5d102329b77c3c3b97e63..e51e03fe56fb1ef056b7f47fb67e9421035c2d5c

@shtrom
Copy link
Member Author

shtrom commented Feb 26, 2026

Pushing one big squashed commit.

conftest: add try repo to mocked_repo_config

repo: add try_enabled field (bug 1979247)

settings: add try_api to APPLICATIONS (bug 1979247)

create_environment_repos: add try repo in suite (bug 1986575)

try_api: patches endpoint (bug 1979247)

try_api: use PatchHelper to parse patches (bug 1979247)

try_api: resolve base_commit at submission time (bug 1979247)

try_api: test SCM1 auth

auth: fix require_permission to return wrapped method

utils.auth: add PermissionAccessTokenAuth

(bug 1983216)

Update src/lando/try_api/api.py

Co-authored-by: Connor Sheehan <cosheehan@mozilla.com>

utils.auth: don't allow delegated permissions in PermissionAccessTokenAuth

utils.exceptions: move problem_exception_handler from treestatus (bug 2008894)

This allows us to reuse it verbatim from other modules.

utils.exception: add support for ForbiddenProblemException (bug 2008894)

try_api: use django.test.clients (bug 2008895)

try_api: add error handling with RFC 7807 responses

repo: coalesce try_enabled and is_try

try_api/tests: add client_post fixture

test_transplants: test blocker_scm_permission and add integrated_transplant_without_permissions

utils.auth: add user_has_direct_permission

models: move user_has_direct_permission to Profile model

try_api: check user permission against target_repo

try_api: remove extra argument to logger

utils.ninja_auth: move AccessTokenLandoOIDCAuthenticationBackend to main.auth, and rename

try_api.api: don't set priority on Try jobs

try_api.api: don't expose exceptions

CommitMap: add TRY_REPO_MAPPING to support determining where to lookup CommitMaps from

test_transplants: test blocker_scm_permission and add integrated_transplant_without_permissions

utils.auth: add user_has_direct_permission

models: move user_has_direct_permission to Profile model

Profile: support app_label in has_direct_perm

Update src/lando/main/models/profile.py

Co-authored-by: Connor Sheehan <cosheehan@mozilla.com>

Repo: add user_allowed method to check direct required_permission on User

update for Repo.user_allowed

tests: update fixtures for Try repo parameters

create_environment_repos: disable commit message hook for try

Update src/lando/try_api/api.py

Co-authored-by: Zeid <2043828+zzzeid@users.noreply.github.com>

auth: don't create Django users on API requests

try_api: add test for base_commit_vcs values

try_api: use SCM rather than VCS in user messaging

try_api/tests: don't embed b64 literals

create_environment_repos: DRY TRY_HOOKS

try_api: move some patchhelper calls out of try/except

auth: limit AccessTokenLandoOIDCAuthenticationBackend to token auth without fallback

test: ensure that AccessTokenLandoOIDCAuthenticationBackend creates users correctly

Apply suggestion from @shtrom

Update src/lando/main/auth.py

Co-authored-by: Zeid <2043828+zzzeid@users.noreply.github.com>

auth: make AccessTokenLandoOIDCAuthenticationBackend behave more closely to OIDCAuthenticationBackend
@shtrom
Copy link
Member Author

shtrom commented Feb 27, 2026

rebased on main

@lando-prod-mozilla
Copy link

Pull request closed by commit a9f2b20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants