2021-01-04 13:52:13 +00:00
|
|
|
package policy
|
2020-12-11 14:49:19 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"github.com/caos/zitadel/internal/errors"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2/repository"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
PasswordAgePolicyAddedEventType = "policy.password.age.added"
|
|
|
|
PasswordAgePolicyChangedEventType = "policy.password.age.changed"
|
|
|
|
PasswordAgePolicyRemovedEventType = "policy.password.age.removed"
|
|
|
|
)
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type PasswordAgePolicyAddedEvent struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2021-01-06 09:47:55 +00:00
|
|
|
ExpireWarnDays uint64 `json:"expireWarnDays,omitempty"`
|
|
|
|
MaxAgeDays uint64 `json:"maxAgeDays,omitempty"`
|
2020-12-11 14:49:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *PasswordAgePolicyAddedEvent) Data() interface{} {
|
2020-12-11 14:49:19 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func NewPasswordAgePolicyAddedEvent(
|
2020-12-11 14:49:19 +00:00
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
expireWarnDays,
|
|
|
|
maxAgeDays uint64,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *PasswordAgePolicyAddedEvent {
|
2020-12-11 14:49:19 +00:00
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
return &PasswordAgePolicyAddedEvent{
|
2020-12-11 14:49:19 +00:00
|
|
|
BaseEvent: *base,
|
|
|
|
ExpireWarnDays: expireWarnDays,
|
|
|
|
MaxAgeDays: maxAgeDays,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func PasswordAgePolicyAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
e := &PasswordAgePolicyAddedEvent{
|
2020-12-11 14:49:19 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
|
|
|
err := json.Unmarshal(event.Data, e)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "POLIC-T3mGp", "unable to unmarshal policy")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type PasswordAgePolicyChangedEvent struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
ExpireWarnDays uint64 `json:"expireWarnDays,omitempty"`
|
|
|
|
MaxAgeDays uint64 `json:"maxAgeDays,omitempty"`
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *PasswordAgePolicyChangedEvent) Data() interface{} {
|
2020-12-11 14:49:19 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func NewPasswordAgePolicyChangedEvent(
|
2020-12-11 14:49:19 +00:00
|
|
|
base *eventstore.BaseEvent,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *PasswordAgePolicyChangedEvent {
|
|
|
|
return &PasswordAgePolicyChangedEvent{
|
2020-12-11 14:49:19 +00:00
|
|
|
BaseEvent: *base,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func PasswordAgePolicyChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
e := &PasswordAgePolicyChangedEvent{
|
2020-12-11 14:49:19 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
|
|
|
err := json.Unmarshal(event.Data, e)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "POLIC-PqaVq", "unable to unmarshal policy")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type PasswordAgePolicyRemovedEvent struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *PasswordAgePolicyRemovedEvent) Data() interface{} {
|
2020-12-11 14:49:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func NewPasswordAgePolicyRemovedEvent(
|
2020-12-11 14:49:19 +00:00
|
|
|
base *eventstore.BaseEvent,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *PasswordAgePolicyRemovedEvent {
|
|
|
|
return &PasswordAgePolicyRemovedEvent{
|
2020-12-11 14:49:19 +00:00
|
|
|
BaseEvent: *base,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func PasswordAgePolicyRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
e := &PasswordAgePolicyRemovedEvent{
|
2020-12-11 14:49:19 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}
|
|
|
|
|
|
|
|
err := json.Unmarshal(event.Data, e)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.ThrowInternal(err, "POLIC-02878", "unable to unmarshal policy")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|