mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:57:32 +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:
43
internal/api/grpc/system/quota_converter.go
Normal file
43
internal/api/grpc/system/quota_converter.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/zitadel/zitadel/internal/command"
|
||||
"github.com/zitadel/zitadel/pkg/grpc/quota"
|
||||
"github.com/zitadel/zitadel/pkg/grpc/system"
|
||||
)
|
||||
|
||||
func instanceQuotaPbToCommand(req *system.AddQuotaRequest) *command.AddQuota {
|
||||
return &command.AddQuota{
|
||||
Unit: instanceQuotaUnitPbToCommand(req.Unit),
|
||||
From: req.From.AsTime(),
|
||||
ResetInterval: req.ResetInterval.AsDuration(),
|
||||
Amount: req.Amount,
|
||||
Limit: req.Limit,
|
||||
Notifications: instanceQuotaNotificationsPbToCommand(req.Notifications),
|
||||
}
|
||||
}
|
||||
|
||||
func instanceQuotaUnitPbToCommand(unit quota.Unit) command.QuotaUnit {
|
||||
switch unit {
|
||||
case quota.Unit_UNIT_REQUESTS_ALL_AUTHENTICATED:
|
||||
return command.QuotaRequestsAllAuthenticated
|
||||
case quota.Unit_UNIT_ACTIONS_ALL_RUN_SECONDS:
|
||||
return command.QuotaActionsAllRunsSeconds
|
||||
case quota.Unit_UNIT_UNIMPLEMENTED:
|
||||
fallthrough
|
||||
default:
|
||||
return command.QuotaUnit(unit.String())
|
||||
}
|
||||
}
|
||||
|
||||
func instanceQuotaNotificationsPbToCommand(req []*quota.Notification) command.QuotaNotifications {
|
||||
notifications := make([]*command.QuotaNotification, len(req))
|
||||
for idx, item := range req {
|
||||
notifications[idx] = &command.QuotaNotification{
|
||||
Percent: uint16(item.Percent),
|
||||
Repeat: item.Repeat,
|
||||
CallURL: item.CallUrl,
|
||||
}
|
||||
}
|
||||
return notifications
|
||||
}
|
Reference in New Issue
Block a user