142 lines
3.6 KiB
Go
Raw Normal View History

2022-07-08 10:07:17 +02:00
package main
import (
2022-07-08 11:27:19 +02:00
"bytes"
2022-07-08 10:07:17 +02:00
"context"
_ "embed"
"flag"
"fmt"
2022-07-27 09:42:18 +02:00
"strings"
2022-07-08 10:07:17 +02:00
"time"
2022-07-27 09:42:18 +02:00
"github.com/zitadel/zitadel/cmd"
2022-07-08 11:27:19 +02:00
cryptoDB "github.com/zitadel/zitadel/internal/crypto/database"
2022-07-08 10:07:17 +02:00
"github.com/zitadel/zitadel/internal/id"
"github.com/spf13/viper"
"github.com/zitadel/zitadel/internal/command"
"github.com/zitadel/zitadel/internal/database"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/webauthn"
"gopkg.in/yaml.v3"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/logging"
)
2022-07-08 11:27:19 +02:00
var (
//go:embed defaults.yaml
e2edefaults []byte
)
2022-07-08 10:07:17 +02:00
type userData struct {
desc, role, pw string
}
func main() {
2022-07-08 11:27:19 +02:00
masterkey := flag.String("materkey", "MasterkeyNeedsToHave32Characters", "the ZITADEL installations masterkey")
2022-07-08 10:07:17 +02:00
debug := flag.Bool("debug", false, "print information that is helpful for debugging")
2022-07-27 09:42:18 +02:00
viper.AutomaticEnv()
viper.SetEnvPrefix("ZITADEL")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetConfigType("yaml")
err := viper.ReadConfig(bytes.NewBuffer(cmd.DefaultConfig))
2022-07-08 11:27:19 +02:00
logging.OnError(err).Fatalf("unable to initialize zitadel config: %s", err)
2022-07-08 10:07:17 +02:00
flag.Parse()
2022-07-08 11:27:19 +02:00
err = viper.MergeConfig(bytes.NewBuffer(e2edefaults))
logging.OnError(err).Fatalf("unable to initialize e2e config: %s", err)
2022-07-08 10:07:17 +02:00
conf := MustNewConfig(viper.GetViper())
if *debug {
printConfig("config", conf)
}
logging.New().OnError(err).Fatal("validating e2e config failed")
2022-07-08 11:27:19 +02:00
startE2ESetup(conf, *masterkey)
2022-07-08 10:07:17 +02:00
}
2022-07-08 11:27:19 +02:00
func startE2ESetup(conf *Config, masterkey string) {
2022-07-08 10:07:17 +02:00
id.Configure(conf.Machine)
ctx := context.Background()
dbClient, err := database.Connect(conf.Database)
logging.New().OnError(err).Fatalf("cannot start client for projection: %s", err)
2022-07-20 18:15:25 +02:00
instanceID, zitadelProjectResourceID, err := ids(ctx, conf.E2E, dbClient)
2022-07-20 11:50:49 +02:00
logging.New().OnError(err).Fatalf("cannot get instance and project IDs: %s", err)
2022-07-08 11:27:19 +02:00
keyStorage, err := cryptoDB.NewKeyStorage(dbClient, masterkey)
logging.New().OnError(err).Fatalf("cannot start key storage: %s", err)
2022-07-08 10:07:17 +02:00
2022-07-08 11:27:19 +02:00
keys, err := ensureEncryptionKeys(conf.EncryptionKeys, keyStorage)
logging.New().OnError(err).Fatalf("failed ensuring encryption keys: %s", err)
2022-07-08 10:07:17 +02:00
eventstoreClient, err := eventstore.Start(dbClient)
logging.New().OnError(err).Fatalf("cannot start eventstore for queries: %s", err)
storage, err := conf.AssetStorage.NewStorage(dbClient)
logging.New().OnError(err).Fatalf("cannot start asset storage client: %s", err)
webAuthNConfig := &webauthn.Config{
DisplayName: conf.WebAuthNName,
ExternalSecure: conf.ExternalSecure,
}
commands, err := command.StartCommands(
eventstoreClient,
conf.SystemDefaults,
conf.InternalAuthZ.RolePermissionMappings,
storage,
webAuthNConfig,
conf.ExternalDomain,
conf.ExternalSecure,
conf.ExternalPort,
2022-07-08 11:27:19 +02:00
keys.IDPConfig,
keys.OTP,
keys.SMTP,
keys.SMS,
keys.User,
keys.DomainVerification,
keys.OIDC,
2022-07-08 10:07:17 +02:00
)
logging.New().OnError(err).Errorf("cannot start commands: %s", err)
users := []userData{{
desc: "org_owner",
pw: conf.E2E.OrgOwnerPassword,
role: domain.RoleOrgOwner,
}}
2022-07-20 11:50:49 +02:00
err = execute(ctx, commands, *conf.E2E, users, instanceID)
2022-07-08 11:27:19 +02:00
logging.New().OnError(err).Fatalf("failed to execute commands steps")
2022-07-08 10:07:17 +02:00
eventualConsistencyCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
defer cancel()
err = awaitConsistency(
eventualConsistencyCtx,
*conf.E2E,
users,
2022-07-20 11:50:49 +02:00
zitadelProjectResourceID,
2022-07-08 10:07:17 +02:00
)
logging.New().OnError(err).Fatal("failed to await consistency")
}
func printConfig(desc string, cfg interface{}) {
bytes, err := yaml.Marshal(cfg)
logging.New().OnError(err).Fatal("cannot marshal config")
logging.New().Info("got the following ", desc, " config")
fmt.Println(string(bytes))
}