From 4c7021230467f7fccbc4a421dd3e61b2318811d5 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 6 Dec 2022 12:25:17 -0500 Subject: [PATCH] zrok admin bootstrap now checks frontend entry for frontend identity (#131) --- controller/bootstrap.go | 23 +++++++++++++++++++++++ controller/store/frontend.go | 8 ++++++++ 2 files changed, 31 insertions(+) diff --git a/controller/bootstrap.go b/controller/bootstrap.go index 587c92ff..0ca0cd37 100644 --- a/controller/bootstrap.go +++ b/controller/bootstrap.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/openziti-test-kitchen/zrok/controller/store" "github.com/openziti-test-kitchen/zrok/model" "github.com/openziti-test-kitchen/zrok/zrokdir" "github.com/openziti/edge/rest_management_api_client" @@ -26,6 +27,12 @@ import ( func Bootstrap(skipCtrl, skipFrontend bool, inCfg *Config) error { cfg = inCfg + if v, err := store.Open(cfg.Store); err == nil { + str = v + } else { + return errors.Wrap(err, "error opening store") + } + edge, err := edgeClient() if err != nil { return err @@ -65,6 +72,22 @@ func Bootstrap(skipCtrl, skipFrontend bool, inCfg *Config) error { if err := assertErpForIdentity("frontend", frontendZId, edge); err != nil { panic(err) } + + tx, err := str.Begin() + if err != nil { + panic(err) + } + defer func() { _ = tx.Rollback() }() + publicFe, err := str.FindFrontendWithZId(frontendZId, tx) + if err != nil { + logrus.Warnf("missing public frontend for ziti id '%v'; please use 'zrok admin create frontend' to create a frontend instance", frontendZId) + } else { + if publicFe.PublicName != nil && publicFe.UrlTemplate != nil { + logrus.Infof("found public frontend entry '%v' (%v) for ziti identity '%v'", *publicFe.PublicName, publicFe.Token, frontendZId) + } else { + logrus.Warnf("found frontend entry for ziti identity '%v'; missing either public name or url template") + } + } } if err := assertZrokProxyConfigType(edge); err != nil { diff --git a/controller/store/frontend.go b/controller/store/frontend.go index 9d9d5189..3ecf16b3 100644 --- a/controller/store/frontend.go +++ b/controller/store/frontend.go @@ -55,6 +55,14 @@ func (str *Store) FindFrontendWithToken(token string, tx *sqlx.Tx) (*Frontend, e return i, nil } +func (str *Store) FindFrontendWithZId(zId string, tx *sqlx.Tx) (*Frontend, error) { + i := &Frontend{} + if err := tx.QueryRowx("select frontends.* from frontends where z_id = $1", zId).StructScan(i); err != nil { + return nil, errors.Wrap(err, "error selecting frontend by ziti id") + } + return i, nil +} + func (str *Store) FindFrontendPubliclyNamed(publicName string, tx *sqlx.Tx) (*Frontend, error) { i := &Frontend{} if err := tx.QueryRowx("select frontends.* from frontends where public_name = $1", publicName).StructScan(i); err != nil {