2021-01-04 14:52:13 +01:00
|
|
|
package query
|
2020-12-11 15:49:19 +01:00
|
|
|
|
2021-01-04 14:52:13 +01:00
|
|
|
import (
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
2021-01-04 14:52:13 +01:00
|
|
|
)
|
2020-12-11 15:49:19 +01:00
|
|
|
|
2021-08-11 08:36:32 +02:00
|
|
|
type LockoutPolicyReadModel struct {
|
2020-12-11 15:49:19 +01:00
|
|
|
eventstore.ReadModel
|
|
|
|
|
|
|
|
MaxAttempts uint64
|
|
|
|
ShowLockOutFailures bool
|
|
|
|
}
|
|
|
|
|
2021-08-11 08:36:32 +02:00
|
|
|
func (rm *LockoutPolicyReadModel) Reduce() error {
|
2020-12-11 15:49:19 +01:00
|
|
|
for _, event := range rm.Events {
|
|
|
|
switch e := event.(type) {
|
2021-08-11 08:36:32 +02:00
|
|
|
case *policy.LockoutPolicyAddedEvent:
|
|
|
|
rm.MaxAttempts = e.MaxPasswordAttempts
|
2020-12-11 15:49:19 +01:00
|
|
|
rm.ShowLockOutFailures = e.ShowLockOutFailures
|
2021-08-11 08:36:32 +02:00
|
|
|
case *policy.LockoutPolicyChangedEvent:
|
|
|
|
if e.MaxPasswordAttempts != nil {
|
|
|
|
rm.MaxAttempts = *e.MaxPasswordAttempts
|
2021-01-06 11:12:56 +01:00
|
|
|
}
|
|
|
|
if e.ShowLockOutFailures != nil {
|
|
|
|
rm.ShowLockOutFailures = *e.ShowLockOutFailures
|
|
|
|
}
|
2020-12-11 15:49:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rm.ReadModel.Reduce()
|
|
|
|
}
|