mirror of
https://github.com/openziti/zrok.git
synced 2025-06-26 20:52:33 +02:00
bootstrapper refactoring to accomodate new secrets listener boostrapping (#968)
This commit is contained in:
parent
632632e0bf
commit
21f055e590
@ -13,8 +13,9 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type adminBootstrap struct {
|
type adminBootstrap struct {
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
skipFrontend bool
|
skipFrontend bool
|
||||||
|
skipSecretsListener bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAdminBootstrap() *adminBootstrap {
|
func newAdminBootstrap() *adminBootstrap {
|
||||||
@ -26,6 +27,7 @@ func newAdminBootstrap() *adminBootstrap {
|
|||||||
command := &adminBootstrap{cmd: cmd}
|
command := &adminBootstrap{cmd: cmd}
|
||||||
cmd.Run = command.run
|
cmd.Run = command.run
|
||||||
cmd.Flags().BoolVar(&command.skipFrontend, "skip-frontend", false, "Skip frontend identity bootstrapping")
|
cmd.Flags().BoolVar(&command.skipFrontend, "skip-frontend", false, "Skip frontend identity bootstrapping")
|
||||||
|
cmd.Flags().BoolVar(&command.skipSecretsListener, "skip-secrets-listener", false, "Skip secrets listener bootstrapping")
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +38,11 @@ func (cmd *adminBootstrap) run(_ *cobra.Command, args []string) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
logrus.Info(cf.Dump(inCfg, cf.DefaultOptions()))
|
logrus.Info(cf.Dump(inCfg, cf.DefaultOptions()))
|
||||||
if err := controller.Bootstrap(cmd.skipFrontend, inCfg); err != nil {
|
bootCfg := &controller.BootstrapConfig{
|
||||||
|
SkipFrontend: cmd.skipFrontend,
|
||||||
|
SkipSecretsListener: cmd.skipSecretsListener,
|
||||||
|
}
|
||||||
|
if err := controller.Bootstrap(bootCfg, inCfg); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
logrus.Info("bootstrap complete!")
|
logrus.Info("bootstrap complete!")
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/openziti/edge-api/rest_management_api_client"
|
"github.com/openziti/edge-api/rest_management_api_client"
|
||||||
restMgmtEdgeConfig "github.com/openziti/edge-api/rest_management_api_client/config"
|
restMgmtEdgeConfig "github.com/openziti/edge-api/rest_management_api_client/config"
|
||||||
"github.com/openziti/edge-api/rest_management_api_client/edge_router_policy"
|
"github.com/openziti/edge-api/rest_management_api_client/edge_router_policy"
|
||||||
@ -16,23 +18,26 @@ import (
|
|||||||
"github.com/openziti/zrok/controller/store"
|
"github.com/openziti/zrok/controller/store"
|
||||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||||
"github.com/openziti/zrok/environment"
|
"github.com/openziti/zrok/environment"
|
||||||
|
"github.com/openziti/zrok/environment/env_core"
|
||||||
"github.com/openziti/zrok/sdk/golang/sdk"
|
"github.com/openziti/zrok/sdk/golang/sdk"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Bootstrap(skipFrontend bool, inCfg *config.Config) error {
|
type BootstrapConfig struct {
|
||||||
cfg = inCfg
|
SkipFrontend bool
|
||||||
|
SkipSecretsListener bool
|
||||||
|
}
|
||||||
|
|
||||||
if v, err := store.Open(cfg.Store); err == nil {
|
func Bootstrap(bootCfg *BootstrapConfig, ctrlCfg *config.Config) error {
|
||||||
|
if v, err := store.Open(ctrlCfg.Store); err == nil {
|
||||||
str = v
|
str = v
|
||||||
} else {
|
} else {
|
||||||
return errors.Wrap(err, "error opening store")
|
return errors.Wrap(err, "error opening store")
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Info("connecting to the ziti edge management api")
|
logrus.Info("connecting to the ziti edge management api")
|
||||||
edge, err := zrokEdgeSdk.Client(cfg.Ziti)
|
edge, err := zrokEdgeSdk.Client(ctrlCfg.Ziti)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error connecting to the ziti edge management api")
|
return errors.Wrap(err, "error connecting to the ziti edge management api")
|
||||||
}
|
}
|
||||||
@ -42,17 +47,30 @@ func Bootstrap(skipFrontend bool, inCfg *config.Config) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := assertFrontendIdentity(bootCfg, env, edge); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := assertZrokProxyConfigType(edge); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertFrontendIdentity(cfg *BootstrapConfig, env env_core.Root, edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||||
var frontendZId string
|
var frontendZId string
|
||||||
if !skipFrontend {
|
if !cfg.SkipFrontend {
|
||||||
logrus.Info("creating identity for public frontend access")
|
logrus.Info("creating identity for public frontend access")
|
||||||
|
|
||||||
if frontendZId, err = getIdentityId(env.PublicIdentityName()); err == nil {
|
if frontendZId, err := getIdentityId(env.PublicIdentityName()); err == nil {
|
||||||
logrus.Infof("frontend identity: %v", frontendZId)
|
logrus.Infof("frontend identity: %v", frontendZId)
|
||||||
} else {
|
} else {
|
||||||
frontendZId, err = bootstrapIdentity(env.PublicIdentityName(), edge)
|
frontendZId, err = bootstrapIdentity(env.PublicIdentityName(), edge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
logrus.Infof("created frontend identity (%v) '%v'", env.PublicIdentityName(), frontendZId)
|
||||||
}
|
}
|
||||||
if err := assertIdentity(frontendZId, edge); err != nil {
|
if err := assertIdentity(frontendZId, edge); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -76,12 +94,9 @@ func Bootstrap(skipFrontend bool, inCfg *config.Config) error {
|
|||||||
logrus.Warnf("found frontend entry for ziti identity '%v'; missing either public name or url template", frontendZId)
|
logrus.Warnf("found frontend entry for ziti identity '%v'; missing either public name or url template", frontendZId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logrus.Warnf("skipping frontend identity bootstrap")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := assertZrokProxyConfigType(edge); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user