2020-11-12 21:50:01 +00:00
|
|
|
package org
|
|
|
|
|
|
|
|
import (
|
2021-01-18 10:24:15 +00:00
|
|
|
"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"
|
2020-11-12 21:50:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-01-04 13:52:13 +00:00
|
|
|
PasswordAgePolicyAddedEventType = orgEventTypePrefix + policy.PasswordAgePolicyAddedEventType
|
|
|
|
PasswordAgePolicyChangedEventType = orgEventTypePrefix + policy.PasswordAgePolicyChangedEventType
|
2021-01-18 10:24:15 +00:00
|
|
|
PasswordAgePolicyRemovedEventType = orgEventTypePrefix + policy.PasswordAgePolicyRemovedEventType
|
2020-11-12 21:50:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type PasswordAgePolicyAddedEvent struct {
|
2021-01-04 13:52:13 +00:00
|
|
|
policy.PasswordAgePolicyAddedEvent
|
2020-11-12 21:50:01 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 10:24:15 +00:00
|
|
|
func NewPasswordAgePolicyAddedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-18 10:24:15 +00:00
|
|
|
expireWarnDays,
|
|
|
|
maxAgeDays uint64,
|
|
|
|
) *PasswordAgePolicyAddedEvent {
|
|
|
|
return &PasswordAgePolicyAddedEvent{
|
|
|
|
PasswordAgePolicyAddedEvent: *policy.NewPasswordAgePolicyAddedEvent(
|
2021-02-18 13:48:27 +00:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
PasswordAgePolicyAddedEventType),
|
2021-01-18 10:24:15 +00:00
|
|
|
expireWarnDays,
|
|
|
|
maxAgeDays),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func PasswordAgePolicyAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-18 10:24:15 +00:00
|
|
|
e, err := policy.PasswordAgePolicyAddedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &PasswordAgePolicyAddedEvent{PasswordAgePolicyAddedEvent: *e.(*policy.PasswordAgePolicyAddedEvent)}, nil
|
|
|
|
}
|
|
|
|
|
2020-11-12 21:50:01 +00:00
|
|
|
type PasswordAgePolicyChangedEvent struct {
|
2021-01-04 13:52:13 +00:00
|
|
|
policy.PasswordAgePolicyChangedEvent
|
2020-11-12 21:50:01 +00:00
|
|
|
}
|
2021-01-18 10:24:15 +00:00
|
|
|
|
|
|
|
func NewPasswordAgePolicyChangedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-18 10:24:15 +00:00
|
|
|
changes []policy.PasswordAgePolicyChanges,
|
|
|
|
) (*PasswordAgePolicyChangedEvent, error) {
|
|
|
|
changedEvent, err := policy.NewPasswordAgePolicyChangedEvent(
|
2021-02-18 13:48:27 +00:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
PasswordAgePolicyChangedEventType),
|
2021-01-18 10:24:15 +00:00
|
|
|
changes,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &PasswordAgePolicyChangedEvent{PasswordAgePolicyChangedEvent: *changedEvent}, nil
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func PasswordAgePolicyChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-18 10:24:15 +00:00
|
|
|
e, err := policy.PasswordAgePolicyChangedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &PasswordAgePolicyChangedEvent{PasswordAgePolicyChangedEvent: *e.(*policy.PasswordAgePolicyChangedEvent)}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type PasswordAgePolicyRemovedEvent struct {
|
|
|
|
policy.PasswordAgePolicyRemovedEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPasswordAgePolicyRemovedEvent(
|
|
|
|
ctx context.Context,
|
2021-02-18 13:48:27 +00:00
|
|
|
aggregate *eventstore.Aggregate,
|
2021-01-18 10:24:15 +00:00
|
|
|
) *PasswordAgePolicyRemovedEvent {
|
|
|
|
return &PasswordAgePolicyRemovedEvent{
|
|
|
|
PasswordAgePolicyRemovedEvent: *policy.NewPasswordAgePolicyRemovedEvent(
|
2021-02-18 13:48:27 +00:00
|
|
|
eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
aggregate,
|
|
|
|
PasswordAgePolicyRemovedEventType),
|
2021-01-18 10:24:15 +00:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 08:19:07 +00:00
|
|
|
func PasswordAgePolicyRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
|
2021-01-18 10:24:15 +00:00
|
|
|
e, err := policy.PasswordAgePolicyRemovedEventMapper(event)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &PasswordAgePolicyRemovedEvent{PasswordAgePolicyRemovedEvent: *e.(*policy.PasswordAgePolicyRemovedEvent)}, nil
|
|
|
|
}
|