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