Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow default route dependencies #705

Merged
merged 6 commits into from
Jun 12, 2024

Conversation

rhysrevans3
Copy link
Contributor

@rhysrevans3 rhysrevans3 commented Jun 10, 2024

Description:
Allows for * to be used for the path or method variables in a route dependencies' scope to match all allowable routes.

PR Checklist:

  • pre-commit hooks pass locally
  • Tests pass (run make test)
  • Documentation has been updated to reflect changes, if applicable, and docs build successfully (run make docs)
  • Changes are added to the CHANGELOG.

@rhysrevans3 rhysrevans3 marked this pull request as ready for review June 10, 2024 10:16
@vincentsarago
Copy link
Member

@alukach would you be able to review this one? 🙏

Copy link
Collaborator

@jonhealy1 jonhealy1 left a comment

Choose a reason for hiding this comment

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

LGTM nice work!

Copy link
Contributor

@alukach alukach left a comment

Choose a reason for hiding this comment

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

This is a nice convenience feature. I think it makes sense. At first I thought a user should instead just do something like:

routes.add_route_dependencies(
    app.router.routes,
    [
        {"path": route.path, "method": method, "type": "http"}
        for route in app.router.routes
        for method in route.methods
    ],
    [Depends(auth.basic_auth)],
)

However, the value of being able to something like this seems really enticing:

routes.add_route_dependencies(
    app.router.routes,
    [
        {"path": "*", "method": method, "type": "http"}
        for method in ("POST", "PUT", "DELETE")
    ],
    [Depends(auth.basic_auth)],
)

Left a minor code style suggestion, but 👍 💯

stac_fastapi/api/stac_fastapi/api/routes.py Outdated Show resolved Hide resolved
rhysrevans3 and others added 2 commits June 12, 2024 08:32
Co-authored-by: Anthony Lukach <anthonylukach@gmail.com>
@vincentsarago vincentsarago merged commit 9a8ab84 into stac-utils:main Jun 12, 2024
7 checks passed
@rhysrevans3 rhysrevans3 deleted the default_routes_dependency branch August 21, 2024 07:29
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.

4 participants