2020-05-18 11:32:16 +02:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-05-25 08:21:58 +02:00
|
|
|
|
2021-01-06 10:47:55 +01:00
|
|
|
"github.com/caos/logging"
|
|
|
|
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/command"
|
|
|
|
"github.com/caos/zitadel/internal/domain"
|
2021-01-06 10:47:55 +01:00
|
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
2021-02-23 15:13:04 +01:00
|
|
|
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
2020-05-18 11:32:16 +02:00
|
|
|
)
|
|
|
|
|
2021-02-24 11:17:39 +01:00
|
|
|
func Execute(ctx context.Context, setUpConfig IAMSetUp, iamID string, commands *command.Commands) error {
|
2021-01-06 10:47:55 +01:00
|
|
|
logging.Log("SETUP-JAK2q").Info("starting setup")
|
|
|
|
|
2021-01-12 12:59:51 +01:00
|
|
|
iam, err := commands.GetIAM(ctx)
|
2021-01-06 10:47:55 +01: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 11:32:16 +02:00
|
|
|
}
|