increase api_keys.hourly_request_limit in CE (#4200)

* increase api_keys.hourly_request_limit in CE

* changelog

* add tests
This commit is contained in:
ruslandoga 2024-06-10 12:21:58 +07:00 committed by GitHub
parent 823f7a8800
commit 22ea56a779
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 1 deletions

View File

@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file.
### Changed
- Increase hourly request limit for API keys in CE from 600 to 1000000 (practically removing the limit) plausible/analytics#4200
### Fixed
## v2.1.1 - 2024-06-06

View File

@ -1,4 +1,5 @@
defmodule Plausible.Auth.ApiKey do
use Plausible
use Ecto.Schema
import Ecto.Changeset
@ -9,7 +10,7 @@ defmodule Plausible.Auth.ApiKey do
schema "api_keys" do
field :name, :string
field :scopes, {:array, :string}, default: ["stats:read:*"]
field :hourly_request_limit, :integer, default: 600
field :hourly_request_limit, :integer, default: on_ee(do: 600, else: 1_000_000)
field :key, :string, virtual: true
field :key_hash, :string

View File

@ -57,6 +57,26 @@ defmodule Plausible.AuthTest do
assert {:ok, %Auth.ApiKey{}} = Auth.create_api_key(user, "my new key", key)
end
@tag :ee_only
test "defaults to 600 requests per hour limit in EE" do
user = insert(:user)
{:ok, %Auth.ApiKey{hourly_request_limit: hourly_request_limit}} =
Auth.create_api_key(user, "my new EE key", Ecto.UUID.generate())
assert hourly_request_limit == 600
end
@tag :ce_build_only
test "defaults to 1000000 requests per hour limit in CE" do
user = insert(:user)
{:ok, %Auth.ApiKey{hourly_request_limit: hourly_request_limit}} =
Auth.create_api_key(user, "my new CE key", Ecto.UUID.generate())
assert hourly_request_limit == 1_000_000
end
test "errors when key already exists" do
u1 = insert(:user)
u2 = insert(:user)