-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add an optional burstable rate limiter (#1924)
The existing rate limiter was moved to a separate package and renamed to IntervalLimiter. Added BurstLimiter which is a wrapper around the "golang.org/x/time/rate" package. The conf.Rate type now has a private `typ` field that indicates if it is a `"interval"` or `"burst"` rate limiter. If the config value is in the form of `"<burst>/<rate>"` we set it to `"burst"`, otherwise `"interval"`. The `conf.Rate.GetRateType()` method is then called from the `ratelimit.New` function to determine the underlying type of `ratelimit.Limiter` it returns. Then changed `api.NewLimiterOptions` to call `ratelimit.New` instead of creating a specific type of rate limiter. --------- Co-authored-by: Chris Stockton <chris.stockton@supabase.io>
- Loading branch information
Showing
12 changed files
with
578 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package api | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/supabase/auth/internal/conf" | ||
) | ||
|
||
func TestNewLimiterOptions(t *testing.T) { | ||
cfg := &conf.GlobalConfiguration{} | ||
cfg.ApplyDefaults() | ||
|
||
rl := NewLimiterOptions(cfg) | ||
assert.NotNil(t, rl.Email) | ||
assert.NotNil(t, rl.Phone) | ||
assert.NotNil(t, rl.Signups) | ||
assert.NotNil(t, rl.AnonymousSignIns) | ||
assert.NotNil(t, rl.Recover) | ||
assert.NotNil(t, rl.Resend) | ||
assert.NotNil(t, rl.MagicLink) | ||
assert.NotNil(t, rl.Otp) | ||
assert.NotNil(t, rl.Token) | ||
assert.NotNil(t, rl.Verify) | ||
assert.NotNil(t, rl.User) | ||
assert.NotNil(t, rl.FactorVerify) | ||
assert.NotNil(t, rl.FactorChallenge) | ||
assert.NotNil(t, rl.SSO) | ||
assert.NotNil(t, rl.SAMLAssertion) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.