mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-02 12:22:15 +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,45 @@
|
||||
package command
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/eventstore"
|
||||
"github.com/zitadel/zitadel/internal/repository/quota"
|
||||
)
|
||||
|
||||
type quotaNotificationsWriteModel struct {
|
||||
eventstore.WriteModel
|
||||
periodStart time.Time
|
||||
latestNotifiedThresholds map[string]uint16
|
||||
}
|
||||
|
||||
func newQuotaNotificationsWriteModel(aggregateId, instanceId, resourceOwner string, periodStart time.Time) *quotaNotificationsWriteModel {
|
||||
return "aNotificationsWriteModel{
|
||||
WriteModel: eventstore.WriteModel{
|
||||
AggregateID: aggregateId,
|
||||
InstanceID: instanceId,
|
||||
ResourceOwner: resourceOwner,
|
||||
},
|
||||
periodStart: periodStart,
|
||||
latestNotifiedThresholds: make(map[string]uint16),
|
||||
}
|
||||
}
|
||||
|
||||
func (wm *quotaNotificationsWriteModel) Query() *eventstore.SearchQueryBuilder {
|
||||
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
||||
ResourceOwner(wm.ResourceOwner).
|
||||
AddQuery().
|
||||
InstanceID(wm.InstanceID).
|
||||
AggregateTypes(quota.AggregateType).
|
||||
AggregateIDs(wm.AggregateID).
|
||||
CreationDateAfter(wm.periodStart).
|
||||
EventTypes(quota.NotifiedEventType).Builder()
|
||||
}
|
||||
|
||||
func (wm *quotaNotificationsWriteModel) Reduce() error {
|
||||
for _, event := range wm.Events {
|
||||
e := event.(*quota.NotifiedEvent)
|
||||
wm.latestNotifiedThresholds[e.ID] = e.Threshold
|
||||
}
|
||||
return wm.WriteModel.Reduce()
|
||||
}
|
||||
Reference in New Issue
Block a user