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 (
|
|
|
|
PasswordComplexityPolicyAddedEventType = "policy.password.complexity.added"
|
|
|
|
PasswordComplexityPolicyChangedEventType = "policy.password.complexity.changed"
|
|
|
|
PasswordComplexityPolicyRemovedEventType = "policy.password.complexity.removed"
|
|
|
|
)
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type PasswordComplexityPolicyAddedEvent struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
|
|
|
MinLength uint64 `json:"minLength,omitempty"`
|
2021-01-06 09:47:55 +00:00
|
|
|
HasLowercase bool `json:"hasLowercase,omitempty"`
|
|
|
|
HasUpperCase bool `json:"hasUppercase,omitempty"`
|
|
|
|
HasNumber bool `json:"hasNumber,omitempty"`
|
|
|
|
HasSymbol bool `json:"hasSymbol,omitempty"`
|
2020-12-11 14:49:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *PasswordComplexityPolicyAddedEvent) Data() interface{} {
|
2020-12-11 14:49:19 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func NewPasswordComplexityPolicyAddedEvent(
|
2020-12-11 14:49:19 +00:00
|
|
|
base *eventstore.BaseEvent,
|
|
|
|
minLength uint64,
|
|
|
|
hasLowerCase,
|
|
|
|
hasUpperCase,
|
|
|
|
hasNumber,
|
|
|
|
hasSymbol bool,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *PasswordComplexityPolicyAddedEvent {
|
|
|
|
return &PasswordComplexityPolicyAddedEvent{
|
2020-12-11 14:49:19 +00:00
|
|
|
BaseEvent: *base,
|
|
|
|
MinLength: minLength,
|
|
|
|
HasLowercase: hasLowerCase,
|
|
|
|
HasNumber: hasNumber,
|
|
|
|
HasSymbol: hasSymbol,
|
|
|
|
HasUpperCase: hasUpperCase,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func PasswordComplexityPolicyAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
e := &PasswordComplexityPolicyAddedEvent{
|
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-wYxlM", "unable to unmarshal policy")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type PasswordComplexityPolicyChangedEvent struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
|
2021-01-06 10:12:56 +00:00
|
|
|
MinLength *uint64 `json:"minLength,omitempty"`
|
|
|
|
HasLowercase *bool `json:"hasLowercase,omitempty"`
|
|
|
|
HasUpperCase *bool `json:"hasUppercase,omitempty"`
|
|
|
|
HasNumber *bool `json:"hasNumber,omitempty"`
|
|
|
|
HasSymbol *bool `json:"hasSymbol,omitempty"`
|
2020-12-11 14:49:19 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *PasswordComplexityPolicyChangedEvent) Data() interface{} {
|
2020-12-11 14:49:19 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func NewPasswordComplexityPolicyChangedEvent(
|
2020-12-11 14:49:19 +00:00
|
|
|
base *eventstore.BaseEvent,
|
2021-01-04 13:52:13 +00:00
|
|
|
) *PasswordComplexityPolicyChangedEvent {
|
|
|
|
return &PasswordComplexityPolicyChangedEvent{
|
2020-12-11 14:49:19 +00:00
|
|
|
BaseEvent: *base,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func PasswordComplexityPolicyChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
e := &PasswordComplexityPolicyChangedEvent{
|
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-zBGB0", "unable to unmarshal policy")
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type PasswordComplexityPolicyRemovedEvent struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
eventstore.BaseEvent `json:"-"`
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (e *PasswordComplexityPolicyRemovedEvent) Data() interface{} {
|
2020-12-11 14:49:19 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func NewPasswordComplexityPolicyRemovedEvent(base *eventstore.BaseEvent) *PasswordComplexityPolicyRemovedEvent {
|
|
|
|
return &PasswordComplexityPolicyRemovedEvent{
|
2020-12-11 14:49:19 +00:00
|
|
|
BaseEvent: *base,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func PasswordComplexityPolicyRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
|
|
|
|
return &PasswordComplexityPolicyRemovedEvent{
|
2020-12-11 14:49:19 +00:00
|
|
|
BaseEvent: *eventstore.BaseEventFromRepo(event),
|
|
|
|
}, nil
|
|
|
|
}
|