-
Notifications
You must be signed in to change notification settings - Fork 461
/
policy_password_age.go
138 lines (110 loc) · 3.51 KB
/
policy_password_age.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package policy
import (
"encoding/json"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
)
const (
PasswordAgePolicyAddedEventType = "policy.password.age.added"
PasswordAgePolicyChangedEventType = "policy.password.age.changed"
PasswordAgePolicyRemovedEventType = "policy.password.age.removed"
)
type PasswordAgePolicyAddedEvent struct {
eventstore.BaseEvent `json:"-"`
ExpireWarnDays uint64 `json:"expireWarnDays,omitempty"`
MaxAgeDays uint64 `json:"maxAgeDays,omitempty"`
}
func (e *PasswordAgePolicyAddedEvent) Data() interface{} {
return e
}
func (e *PasswordAgePolicyAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewPasswordAgePolicyAddedEvent(
base *eventstore.BaseEvent,
expireWarnDays,
maxAgeDays uint64,
) *PasswordAgePolicyAddedEvent {
return &PasswordAgePolicyAddedEvent{
BaseEvent: *base,
ExpireWarnDays: expireWarnDays,
MaxAgeDays: maxAgeDays,
}
}
func PasswordAgePolicyAddedEventMapper(event *repository.Event) (eventstore.Event, error) {
e := &PasswordAgePolicyAddedEvent{
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
}
type PasswordAgePolicyChangedEvent struct {
eventstore.BaseEvent `json:"-"`
ExpireWarnDays *uint64 `json:"expireWarnDays,omitempty"`
MaxAgeDays *uint64 `json:"maxAgeDays,omitempty"`
}
func (e *PasswordAgePolicyChangedEvent) Data() interface{} {
return e
}
func (e *PasswordAgePolicyChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewPasswordAgePolicyChangedEvent(
base *eventstore.BaseEvent,
changes []PasswordAgePolicyChanges,
) (*PasswordAgePolicyChangedEvent, error) {
if len(changes) == 0 {
return nil, errors.ThrowPreconditionFailed(nil, "POLICY-DAgt5", "Errors.NoChangesFound")
}
changeEvent := &PasswordAgePolicyChangedEvent{
BaseEvent: *base,
}
for _, change := range changes {
change(changeEvent)
}
return changeEvent, nil
}
type PasswordAgePolicyChanges func(*PasswordAgePolicyChangedEvent)
func ChangeExpireWarnDays(expireWarnDay uint64) func(*PasswordAgePolicyChangedEvent) {
return func(e *PasswordAgePolicyChangedEvent) {
e.ExpireWarnDays = &expireWarnDay
}
}
func ChangeMaxAgeDays(maxAgeDays uint64) func(*PasswordAgePolicyChangedEvent) {
return func(e *PasswordAgePolicyChangedEvent) {
e.MaxAgeDays = &maxAgeDays
}
}
func PasswordAgePolicyChangedEventMapper(event *repository.Event) (eventstore.Event, error) {
e := &PasswordAgePolicyChangedEvent{
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
}
type PasswordAgePolicyRemovedEvent struct {
eventstore.BaseEvent `json:"-"`
}
func (e *PasswordAgePolicyRemovedEvent) Data() interface{} {
return nil
}
func (e *PasswordAgePolicyRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewPasswordAgePolicyRemovedEvent(base *eventstore.BaseEvent) *PasswordAgePolicyRemovedEvent {
return &PasswordAgePolicyRemovedEvent{
BaseEvent: *base,
}
}
func PasswordAgePolicyRemovedEventMapper(event *repository.Event) (eventstore.Event, error) {
return &PasswordAgePolicyRemovedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}, nil
}