2022-03-24 16:21:34 +00:00
|
|
|
package instance
|
2021-01-04 13:52:13 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-01-03 08:19:07 +00:00
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
2021-01-18 10:24:15 +00:00
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
|
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
2021-01-04 13:52:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-03-24 16:21:34 +00:00
|
|
|
LockoutPolicyAddedEventType = instanceEventTypePrefix + policy.LockoutPolicyAddedEventType
|
|
|
|
LockoutPolicyChangedEventType = instanceEventTypePrefix + policy.LockoutPolicyChangedEventType
|
2021-01-04 13:52:13 +00:00
|
|
|
)
|
|
|
|
|
2021-08-11 06:36:32 +00:00
|
|
|
type LockoutPolicyAddedEvent struct {
|
|
|
|
policy.LockoutPolicyAddedEvent
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 06:36:32 +00:00
|
|
|
func NewLockoutPolicyAddedEvent(
|
2021-01-04 13:52:13 +00:00
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-04 13:52:13 +00:00
|
|
|
maxAttempts uint64,
|
|
|
|
showLockoutFailure bool,
|
2021-08-11 06:36:32 +00:00
|
|
|
) *LockoutPolicyAddedEvent {
|
|
|
|
return &LockoutPolicyAddedEvent{
|
|
|
|
LockoutPolicyAddedEvent: *policy.NewLockoutPolicyAddedEvent(
|
2021-02-18 13:48:27 +00:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
2021-08-11 06:36:32 +00:00
|
|
|
LockoutPolicyAddedEventType),
|
2021-01-04 13:52:13 +00:00
|
|
|
maxAttempts,
|
|
|
|
showLockoutFailure),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func LockoutPolicyAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-08-11 06:36:32 +00:00
|
|
|
e, err := policy.LockoutPolicyAddedEventMapper(event)
|
2021-01-04 13:52:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-08-11 06:36:32 +00:00
|
|
|
return &LockoutPolicyAddedEvent{LockoutPolicyAddedEvent: *e.(*policy.LockoutPolicyAddedEvent)}, nil
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 06:36:32 +00:00
|
|
|
type LockoutPolicyChangedEvent struct {
|
|
|
|
policy.LockoutPolicyChangedEvent
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 06:36:32 +00:00
|
|
|
func NewLockoutPolicyChangedEvent(
|
2021-01-04 13:52:13 +00:00
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-08-11 06:36:32 +00:00
|
|
|
changes []policy.LockoutPolicyChanges,
|
|
|
|
) (*LockoutPolicyChangedEvent, error) {
|
|
|
|
changedEvent, err := policy.NewLockoutPolicyChangedEvent(
|
2021-02-18 13:48:27 +00:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
2021-08-11 06:36:32 +00:00
|
|
|
LockoutPolicyChangedEventType),
|
2021-01-18 10:24:15 +00:00
|
|
|
changes,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
2021-08-11 06:36:32 +00:00
|
|
|
return &LockoutPolicyChangedEvent{LockoutPolicyChangedEvent: *changedEvent}, nil
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func LockoutPolicyChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-08-11 06:36:32 +00:00
|
|
|
e, err := policy.LockoutPolicyChangedEventMapper(event)
|
2021-01-04 13:52:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-08-11 06:36:32 +00:00
|
|
|
return &LockoutPolicyChangedEvent{LockoutPolicyChangedEvent: *e.(*policy.LockoutPolicyChangedEvent)}, nil
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|