mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
385a55bd21
* feat: enable limiting audit trail * support AddExclusiveQuery * fix invalid condition * register event mappers * fix NullDuration validity * test query side for limits * lint * acceptance test audit trail limit * fix acceptance test * translate limits not found * update tests * fix linting * add audit log retention to default instance * fix tests * update docs * remove todo * improve test name
87 lines
1.7 KiB
Go
87 lines
1.7 KiB
Go
package limits
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
)
|
|
|
|
const (
|
|
eventTypePrefix = eventstore.EventType("limits.")
|
|
SetEventType = eventTypePrefix + "set"
|
|
ResetEventType = eventTypePrefix + "reset"
|
|
)
|
|
|
|
// SetEvent describes that limits are added or modified and contains only changed properties
|
|
type SetEvent struct {
|
|
*eventstore.BaseEvent `json:"-"`
|
|
AuditLogRetention *time.Duration `json:"auditLogRetention,omitempty"`
|
|
}
|
|
|
|
func (e *SetEvent) Payload() any {
|
|
return e
|
|
}
|
|
|
|
func (e *SetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func (e *SetEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
e.BaseEvent = b
|
|
}
|
|
|
|
func NewSetEvent(
|
|
base *eventstore.BaseEvent,
|
|
changes ...LimitsChange,
|
|
) *SetEvent {
|
|
changedEvent := &SetEvent{
|
|
BaseEvent: base,
|
|
}
|
|
for _, change := range changes {
|
|
change(changedEvent)
|
|
}
|
|
return changedEvent
|
|
}
|
|
|
|
type LimitsChange func(*SetEvent)
|
|
|
|
func ChangeAuditLogRetention(auditLogRetention *time.Duration) LimitsChange {
|
|
return func(e *SetEvent) {
|
|
e.AuditLogRetention = auditLogRetention
|
|
}
|
|
}
|
|
|
|
var SetEventMapper = eventstore.GenericEventMapper[SetEvent]
|
|
|
|
type ResetEvent struct {
|
|
*eventstore.BaseEvent `json:"-"`
|
|
}
|
|
|
|
func (e *ResetEvent) Payload() any {
|
|
return e
|
|
}
|
|
|
|
func (e *ResetEvent) UniqueConstraints() []*eventstore.UniqueConstraint {
|
|
return nil
|
|
}
|
|
|
|
func (e *ResetEvent) SetBaseEvent(b *eventstore.BaseEvent) {
|
|
e.BaseEvent = b
|
|
}
|
|
|
|
func NewResetEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
) *ResetEvent {
|
|
return &ResetEvent{
|
|
BaseEvent: eventstore.NewBaseEventForPush(
|
|
ctx,
|
|
aggregate,
|
|
ResetEventType,
|
|
),
|
|
}
|
|
}
|
|
|
|
var ResetEventMapper = eventstore.GenericEventMapper[ResetEvent]
|