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

Refactor Sites and Stats API authorization logic #4297

Merged
merged 6 commits into from
Jul 2, 2024

Conversation

zoldar
Copy link
Contributor

@zoldar zoldar commented Jul 1, 2024

Changes

This PR refactors authorization logic for Sites and Stats APIs, unifying it under a single plug. API keys already have a notion of "scopes" though it's merely utilized in a label-like fashion for Sites API key checks. The refactored version implements basic support for scopes. Due to the way API keys are currently provisioned (with a single explicit scope at a time), a notion of implicit scopes is introduced, which are considered as always matching provided the API key is valid.

The main point of this refactor is exposing read-only portion of Sites API to API keys without site provisioning scope. It also will serve as a basis for introducing further Sites API read-only endpoints needed for integrations we are currently working on.

Tests

  • Automated tests have been added

Changelog

  • This PR does not make a user-facing change

Documentation

  • Docs have been updated
  • This change does not need a documentation update

Dark mode

  • This PR does not change the UI

@zoldar zoldar force-pushed the sites-stats-api-fallback branch 2 times, most recently from 8433332 to e0a661d Compare July 2, 2024 08:31
@zoldar zoldar marked this pull request as ready for review July 2, 2024 11:04
@zoldar zoldar requested a review from a team July 2, 2024 11:04
@zoldar zoldar added deploy-to-staging Special label that triggers a deploy to a staging environment preview labels Jul 2, 2024
Copy link

github-actions bot commented Jul 2, 2024

Preview environment👷🏼‍♀️🏗️
PR-4297

1 similar comment
Copy link

github-actions bot commented Jul 2, 2024

Preview environment👷🏼‍♀️🏗️
PR-4297

Copy link
Contributor

@macobo macobo left a comment

Choose a reason for hiding this comment

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

Nice work!

lib/plausible_web/plugs/authorize_public_api.ex Outdated Show resolved Hide resolved
lib/plausible_web/plugs/authorize_public_api.ex Outdated Show resolved Hide resolved
lib/plausible_web/plugs/authorize_public_api.ex Outdated Show resolved Hide resolved
defp check_api_key_rate_limit(api_key) do
case RateLimit.check_rate(
"api_request:#{api_key.id}",
to_timeout(hour: 1),
Copy link
Member

Choose a reason for hiding this comment

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

whoa

@zoldar zoldar merged commit 790984e into master Jul 2, 2024
10 checks passed
@zoldar zoldar deleted the sites-stats-api-fallback branch July 2, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deploy-to-staging Special label that triggers a deploy to a staging environment preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants