2021-01-06 09:47:55 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-02-18 13:48:27 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
2021-01-06 09:47:55 +00:00
|
|
|
|
2021-01-12 11:59:51 +00:00
|
|
|
"github.com/caos/logging"
|
|
|
|
|
2021-01-06 09:47:55 +00:00
|
|
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
|
|
"github.com/caos/zitadel/internal/v2/domain"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Step3 struct {
|
|
|
|
DefaultPasswordAgePolicy iam_model.PasswordAgePolicy
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Step3) Step() domain.Step {
|
|
|
|
return domain.Step3
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Step3) execute(ctx context.Context, commandSide *CommandSide) error {
|
|
|
|
return commandSide.SetupStep3(ctx, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *CommandSide) SetupStep3(ctx context.Context, step *Step3) error {
|
2021-02-18 13:48:27 +00:00
|
|
|
fn := func(iam *IAMWriteModel) ([]eventstore.EventPusher, error) {
|
2021-01-06 09:47:55 +00:00
|
|
|
iamAgg := IAMAggregateFromWriteModel(&iam.WriteModel)
|
2021-02-18 13:48:27 +00:00
|
|
|
event, err := r.addDefaultPasswordAgePolicy(ctx, iamAgg, NewIAMPasswordAgePolicyWriteModel(), &domain.PasswordAgePolicy{
|
2021-01-06 09:47:55 +00:00
|
|
|
MaxAgeDays: step.DefaultPasswordAgePolicy.MaxAgeDays,
|
|
|
|
ExpireWarnDays: step.DefaultPasswordAgePolicy.ExpireWarnDays,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-12 11:59:51 +00:00
|
|
|
logging.Log("SETUP-DBqgq").Info("default password age policy set up")
|
2021-02-18 13:48:27 +00:00
|
|
|
return []eventstore.EventPusher{event}, nil
|
2021-01-06 09:47:55 +00:00
|
|
|
}
|
|
|
|
return r.setup(ctx, step, fn)
|
|
|
|
}
|