2020-05-18 09:32:16 +00:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-05-25 06:21:58 +00:00
|
|
|
|
2021-01-06 09:47:55 +00:00
|
|
|
"github.com/caos/logging"
|
|
|
|
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/command"
|
|
|
|
"github.com/caos/zitadel/internal/domain"
|
2021-01-06 09:47:55 +00:00
|
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
2021-02-23 14:13:04 +00:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
2020-05-18 09:32:16 +00:00
|
|
|
)
|
|
|
|
|
2021-02-24 10:17:39 +00:00
|
|
|
func Execute(ctx context.Context, setUpConfig IAMSetUp, iamID string, commands *command.Commands) error {
|
2021-01-06 09:47:55 +00:00
|
|
|
logging.Log("SETUP-JAK2q").Info("starting setup")
|
|
|
|
|
2021-01-12 11:59:51 +00:00
|
|
|
iam, err := commands.GetIAM(ctx)
|
2021-01-06 09:47:55 +00:00
|
|
|
if err != nil && !caos_errs.IsNotFound(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if iam != nil && (iam.SetUpDone == domain.StepCount-1 || iam.SetUpStarted != iam.SetUpDone) {
|
|
|
|
logging.Log("SETUP-VA2k1").Info("all steps done")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if iam == nil {
|
|
|
|
iam = &domain.IAM{ObjectRoot: models.ObjectRoot{AggregateID: iamID}}
|
|
|
|
}
|
|
|
|
|
|
|
|
steps, err := setUpConfig.Steps(iam.SetUpDone)
|
|
|
|
if err != nil || len(steps) == 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = commands.ExecuteSetupSteps(ctx, steps)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
logging.Log("SETUP-ds31h").Info("setup done")
|
|
|
|
return nil
|
2020-05-18 09:32:16 +00:00
|
|
|
}
|