mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-18 19:25:13 +00:00
feat: add quotas (#4779)
adds possibilities to cap authenticated requests and execution seconds of actions on a defined intervall
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/repository/quota"
|
||||
)
|
||||
|
||||
func (c *Commands) GetCurrentQuotaPeriod(ctx context.Context, instanceID string, unit quota.Unit) (*quota.AddedEvent, time.Time, error) {
|
||||
wm, err := c.getQuotaWriteModel(ctx, instanceID, instanceID, unit)
|
||||
if err != nil || !wm.active {
|
||||
return nil, time.Time{}, err
|
||||
}
|
||||
|
||||
return wm.config, pushPeriodStart(wm.config.From, wm.config.ResetInterval, time.Now()), nil
|
||||
}
|
||||
|
||||
func pushPeriodStart(from time.Time, interval time.Duration, now time.Time) time.Time {
|
||||
next := from.Add(interval)
|
||||
if next.After(now) {
|
||||
return from
|
||||
}
|
||||
return pushPeriodStart(next, interval, now)
|
||||
}
|
||||
Reference in New Issue
Block a user