mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 04:18:01 +00:00
25ef3da9d5
chore(fmt): run gci on complete project Fix global import formatting in go code by running the `gci` command. This allows us to just use the command directly, instead of fixing the import order manually for the linter, on each PR. Co-authored-by: Elio Bischof <elio@zitadel.com>
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package system
|
|
|
|
import (
|
|
"google.golang.org/protobuf/types/known/durationpb"
|
|
"google.golang.org/protobuf/types/known/timestamppb"
|
|
|
|
"github.com/zitadel/zitadel/internal/command"
|
|
"github.com/zitadel/zitadel/pkg/grpc/quota"
|
|
)
|
|
|
|
type setQuotaRequest interface {
|
|
GetUnit() quota.Unit
|
|
GetFrom() *timestamppb.Timestamp
|
|
GetResetInterval() *durationpb.Duration
|
|
GetAmount() uint64
|
|
GetLimit() bool
|
|
GetNotifications() []*quota.Notification
|
|
}
|
|
|
|
func instanceQuotaPbToCommand(req setQuotaRequest) *command.SetQuota {
|
|
return &command.SetQuota{
|
|
Unit: instanceQuotaUnitPbToCommand(req.GetUnit()),
|
|
From: req.GetFrom().AsTime(),
|
|
ResetInterval: req.GetResetInterval().AsDuration(),
|
|
Amount: req.GetAmount(),
|
|
Limit: req.GetLimit(),
|
|
Notifications: instanceQuotaNotificationsPbToCommand(req.GetNotifications()),
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|