2020-11-06 17:25:07 +01:00
|
|
|
package policy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-11-06 22:09:19 +01:00
|
|
|
PasswordAgePolicyAddedEventType = "policy.password.age.added"
|
|
|
|
PasswordAgePolicyChangedEventType = "policy.password.age.changed"
|
|
|
|
PasswordAgePolicyRemovedEventType = "policy.password.age.removed"
|
2020-11-06 17:25:07 +01:00
|
|
|
)
|
|
|
|
|
2020-11-06 22:09:19 +01:00
|
|
|
type PasswordAgePolicyAggregate struct {
|
|
|
|
eventstore.Aggregate
|
|
|
|
|
|
|
|
ExpireWarnDays int
|
|
|
|
MaxAgeDays int
|
|
|
|
}
|
|
|
|
|
2020-11-11 17:51:44 +01:00
|
|
|
type PasswordAgePolicyReadModel struct {
|
|
|
|
eventstore.ReadModel
|
|
|
|
|
|
|
|
ExpireWarnDays int
|
|
|
|
MaxAgeDays int
|
|
|
|
}
|
|
|
|
|
2020-11-06 17:25:07 +01:00
|
|
|
type PasswordAgePolicyAddedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ExpireWarnDays int `json:"expireWarnDays"`
|
|
|
|
MaxAgeDays int `json:"maxAgeDays"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PasswordAgePolicyAddedEvent) CheckPrevious() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PasswordAgePolicyAddedEvent) Data() interface{} {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPasswordAgePolicyAddedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
expireWarnDays,
|
|
|
|
maxAgeDays int,
|
|
|
|
) *PasswordAgePolicyAddedEvent {
|
2020-11-06 22:09:19 +01:00
|
|
|
|
2020-11-06 17:25:07 +01:00
|
|
|
return &PasswordAgePolicyAddedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
PasswordAgePolicyAddedEventType,
|
|
|
|
),
|
|
|
|
ExpireWarnDays: expireWarnDays,
|
|
|
|
MaxAgeDays: maxAgeDays,
|
|
|
|
}
|
|
|
|
}
|
2020-11-06 22:09:19 +01:00
|
|
|
|
|
|
|
type PasswordAgePolicyChangedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2020-11-11 17:51:44 +01:00
|
|
|
ExpireWarnDays int `json:"expireWarnDays,omitempty"`
|
|
|
|
MaxAgeDays int `json:"maxAgeDays,omitempty"`
|
2020-11-06 22:09:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PasswordAgePolicyChangedEvent) CheckPrevious() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PasswordAgePolicyChangedEvent) Data() interface{} {
|
2020-11-11 17:51:44 +01:00
|
|
|
return e
|
2020-11-06 22:09:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewPasswordAgePolicyChangedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
current,
|
|
|
|
changed *PasswordAgePolicyAggregate,
|
|
|
|
) *PasswordAgePolicyChangedEvent {
|
|
|
|
|
2020-11-11 17:51:44 +01:00
|
|
|
e := &PasswordAgePolicyChangedEvent{
|
2020-11-06 22:09:19 +01:00
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
|
|
|
PasswordAgePolicyChangedEventType,
|
|
|
|
),
|
|
|
|
}
|
2020-11-11 17:51:44 +01:00
|
|
|
|
|
|
|
if current.ExpireWarnDays != changed.ExpireWarnDays {
|
|
|
|
e.ExpireWarnDays = changed.ExpireWarnDays
|
|
|
|
}
|
|
|
|
if current.MaxAgeDays != changed.MaxAgeDays {
|
|
|
|
e.MaxAgeDays = changed.ExpireWarnDays
|
|
|
|
}
|
|
|
|
|
|
|
|
return e
|
2020-11-06 22:09:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type PasswordAgePolicyRemovedEvent struct {
|
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PasswordAgePolicyRemovedEvent) CheckPrevious() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PasswordAgePolicyRemovedEvent) Data() interface{} {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewPasswordAgePolicyRemovedEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
current,
|
|
|
|
changed *PasswordAgePolicyRemovedEvent,
|
|
|
|
) *PasswordAgePolicyChangedEvent {
|
|
|
|
|
|
|
|
return &PasswordAgePolicyChangedEvent{
|
|
|
|
BaseEvent: *eventstore.NewBaseEventForPush(
|
|
|
|
ctx,
|
2020-11-11 17:51:44 +01:00
|
|
|
PasswordAgePolicyRemovedEventType,
|
2020-11-06 22:09:19 +01:00
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|