2021-01-04 13:52:13 +00:00
|
|
|
package query
|
2020-12-11 14:49:19 +00:00
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
import (
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/repository/policy"
|
2021-01-04 13:52:13 +00:00
|
|
|
)
|
2020-12-11 14:49:19 +00:00
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
type PasswordAgePolicyReadModel struct {
|
2020-12-11 14:49:19 +00:00
|
|
|
eventstore.ReadModel
|
|
|
|
|
|
|
|
ExpireWarnDays uint64
|
|
|
|
MaxAgeDays uint64
|
|
|
|
}
|
|
|
|
|
2021-01-04 13:52:13 +00:00
|
|
|
func (rm *PasswordAgePolicyReadModel) Reduce() error {
|
2020-12-11 14:49:19 +00:00
|
|
|
for _, event := range rm.Events {
|
|
|
|
switch e := event.(type) {
|
2021-01-04 13:52:13 +00:00
|
|
|
case *policy.PasswordAgePolicyAddedEvent:
|
2020-12-11 14:49:19 +00:00
|
|
|
rm.ExpireWarnDays = e.ExpireWarnDays
|
|
|
|
rm.MaxAgeDays = e.MaxAgeDays
|
2021-01-04 13:52:13 +00:00
|
|
|
case *policy.PasswordAgePolicyChangedEvent:
|
2021-01-06 10:12:56 +00:00
|
|
|
if e.ExpireWarnDays != nil {
|
|
|
|
rm.ExpireWarnDays = *e.ExpireWarnDays
|
|
|
|
}
|
|
|
|
if e.MaxAgeDays != nil {
|
|
|
|
rm.MaxAgeDays = *e.MaxAgeDays
|
|
|
|
}
|
2020-12-11 14:49:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rm.ReadModel.Reduce()
|
|
|
|
}
|