From cf02910c307f5da66544a080427aa60179a1ac2e Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:57:49 -0500 Subject: [PATCH 01/16] add a prototype xweb handler for thoughts --- common/zac/handler.go | 86 +++++++++++++++++++++++++++++++++ controller/controller.go | 5 ++ ziti/cmd/edge/quickstart.go | 6 --- ziti/cmd/helpers/env_helpers.go | 4 ++ 4 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 common/zac/handler.go diff --git a/common/zac/handler.go b/common/zac/handler.go new file mode 100644 index 000000000..0eeb1b776 --- /dev/null +++ b/common/zac/handler.go @@ -0,0 +1,86 @@ +/* + Copyright NetFoundry Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package zac + +import ( + gosundheit "github.com/AppsFlyer/go-sundheit" + "github.com/openziti/xweb/v2" + "net/http" + "strings" +) + +const ( + Binding = "zac" +) + +type ZitiAdminConsoleFactory struct { + healthChecker gosundheit.Health +} + +var _ xweb.ApiHandlerFactory = &ZitiAdminConsoleFactory{} + +func NewZitiAdminConsoleFactory() *ZitiAdminConsoleFactory { + return &ZitiAdminConsoleFactory{} +} + +func (factory ZitiAdminConsoleFactory) Validate(*xweb.InstanceConfig) error { + return nil +} + +func (factory ZitiAdminConsoleFactory) Binding() string { + return Binding +} + +func (factory ZitiAdminConsoleFactory) New(_ *xweb.ServerConfig, options map[interface{}]interface{}) (xweb.ApiHandler, error) { + loc := "./" + if options["location"] != "" { + loc = options["location"].(string) + } + zac := &ZitiAdminConsoleHandler{ + httpHandler: http.FileServer(http.Dir(loc)), + } + + return zac, nil +} + +type ZitiAdminConsoleHandler struct { + options map[interface{}]interface{} + httpHandler http.Handler +} + +func (self *ZitiAdminConsoleHandler) Binding() string { + return Binding +} + +func (self *ZitiAdminConsoleHandler) Options() map[interface{}]interface{} { + return nil +} + +func (self *ZitiAdminConsoleHandler) RootPath() string { + return "/" + Binding +} + +func (self *ZitiAdminConsoleHandler) IsHandler(r *http.Request) bool { + return strings.HasPrefix(r.URL.Path, self.RootPath()) || strings.HasPrefix(r.URL.Path, "/assets") +} + +func (self *ZitiAdminConsoleHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { + if !strings.HasPrefix(request.URL.Path, self.RootPath()) { + request.URL.Path = self.RootPath() + "/" + request.URL.Path + } + self.httpHandler.ServeHTTP(writer, request) +} diff --git a/controller/controller.go b/controller/controller.go index 00931edc9..ccf50b4d7 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -25,6 +25,7 @@ import ( "github.com/openziti/transport/v2" "github.com/openziti/ziti/common/capabilities" "github.com/openziti/ziti/common/config" + "github.com/openziti/ziti/common/zac" "github.com/openziti/ziti/controller/event" "github.com/openziti/ziti/controller/events" "github.com/openziti/ziti/controller/handler_peer_ctrl" @@ -247,6 +248,10 @@ func (c *Controller) initWeb() { logrus.WithError(err).Fatalf("failed to create metrics api factory") } + if err := c.xweb.GetRegistry().Add(zac.NewZitiAdminConsoleFactory()); err != nil { + logrus.WithError(err).Fatalf("failed to create myXweb factory") + } + } func (c *Controller) Run() error { diff --git a/ziti/cmd/edge/quickstart.go b/ziti/cmd/edge/quickstart.go index b77b3bb91..20084e7b9 100644 --- a/ziti/cmd/edge/quickstart.go +++ b/ziti/cmd/edge/quickstart.go @@ -335,18 +335,12 @@ func (o *QuickstartOpts) createMinimalPki() { //ziti pki create server --pki-root="${ZITI_HOME}/pki" --ca-name "intermediate-ca" --server-name "server" --server-file "server" --dns "localhost,${ZITI_HOSTNAME}" svr := pki.NewCmdPKICreateServer(o.out, o.errOut) - var ips = "127.0.0.1,::1" - ip_override := os.Getenv("ZITI_CTRL_EDGE_IP_OVERRIDE") - if ip_override != "" { - ips = ips + "," + ip_override - } svr.SetArgs([]string{ fmt.Sprintf("--pki-root=%s", where), fmt.Sprintf("--ca-name=%s", "intermediate-ca"), fmt.Sprintf("--server-name=%s", "server"), fmt.Sprintf("--server-file=%s", "server"), fmt.Sprintf("--dns=%s,%s", "localhost", helpers.GetCtrlAdvertisedAddress()), - fmt.Sprintf("--ip=%s", ips), }) svrErr := svr.Execute() if svrErr != nil { diff --git a/ziti/cmd/helpers/env_helpers.go b/ziti/cmd/helpers/env_helpers.go index 78c90105d..9960b24d2 100644 --- a/ziti/cmd/helpers/env_helpers.go +++ b/ziti/cmd/helpers/env_helpers.go @@ -96,6 +96,10 @@ func GetCtrlAdvertisedAddress() string { return getFromEnv(constants.CtrlAdvertisedAddressVarName, HostnameOrNetworkName) } +func GetCtrlIpOverride() string { + return getFromEnv(constants.CtrlAdvertisedAddressVarName, HostnameOrNetworkName) +} + func GetEdgeRouterIpOvderride() string { return getFromEnv(constants.ZitiEdgeRouterIPOverrideVarName, defaultValue("")) } From 870517a6783a6ad83217a142f542018a6c8d1bb6 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 29 Nov 2023 16:26:47 -0500 Subject: [PATCH 02/16] update spa handling --- common/zac/handler.go | 54 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/common/zac/handler.go b/common/zac/handler.go index 0eeb1b776..0bce71264 100644 --- a/common/zac/handler.go +++ b/common/zac/handler.go @@ -19,7 +19,10 @@ package zac import ( gosundheit "github.com/AppsFlyer/go-sundheit" "github.com/openziti/xweb/v2" + log "github.com/sirupsen/logrus" "net/http" + "os" + "path/filepath" "strings" ) @@ -46,12 +49,16 @@ func (factory ZitiAdminConsoleFactory) Binding() string { } func (factory ZitiAdminConsoleFactory) New(_ *xweb.ServerConfig, options map[interface{}]interface{}) (xweb.ApiHandler, error) { - loc := "./" - if options["location"] != "" { - loc = options["location"].(string) + loc := options["location"] + if loc == nil || loc == "" { + log.Panic("location must be supplied in zac options") + } + indexFile := options["indexFile"] + if indexFile == nil || indexFile == "" { + indexFile = "index.html" } zac := &ZitiAdminConsoleHandler{ - httpHandler: http.FileServer(http.Dir(loc)), + httpHandler: SpaHandler(loc.(string), "/"+Binding, indexFile.(string)), } return zac, nil @@ -79,8 +86,41 @@ func (self *ZitiAdminConsoleHandler) IsHandler(r *http.Request) bool { } func (self *ZitiAdminConsoleHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { - if !strings.HasPrefix(request.URL.Path, self.RootPath()) { - request.URL.Path = self.RootPath() + "/" + request.URL.Path - } self.httpHandler.ServeHTTP(writer, request) } + +// Thanks to https://github.com/roberthodgen/spa-server +// Serve from a public directory with specific index +type spaHandler struct { + content string // The directory from which to serve + contextRoot string // The context root to remove + indexFile string // The fallback/default file to serve +} + +// Falls back to a supplied index (indexFile) when either condition is true: +// (1) Request (file) path is not found +// (2) Request path is a directory +// Otherwise serves the requested file. +func (h *spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if strings.HasPrefix(r.URL.Path, h.contextRoot) { + // strip off the path + r.URL.Path = r.URL.Path[len(h.contextRoot):] + } + p := filepath.Join(h.content, filepath.Clean(r.URL.Path)) + + if info, err := os.Stat(p); err != nil { + http.ServeFile(w, r, filepath.Join(h.content, h.indexFile)) + return + } else if info.IsDir() { + http.ServeFile(w, r, filepath.Join(h.content, h.indexFile)) + return + } + + http.ServeFile(w, r, p) +} + +// Returns a request handler (http.Handler) that serves a single +// page application from a given public directory (publicDir). +func SpaHandler(publicDir string, contextRoot string, indexFile string) http.Handler { + return &spaHandler{publicDir, contextRoot, indexFile} +} From 928ad4ae91c5539942a3b591da36d45e5e55b020 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 29 Nov 2023 16:49:53 -0500 Subject: [PATCH 03/16] undo extra commits --- ziti/cmd/edge/quickstart.go | 6 ++++++ ziti/cmd/helpers/env_helpers.go | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ziti/cmd/edge/quickstart.go b/ziti/cmd/edge/quickstart.go index 20084e7b9..b77b3bb91 100644 --- a/ziti/cmd/edge/quickstart.go +++ b/ziti/cmd/edge/quickstart.go @@ -335,12 +335,18 @@ func (o *QuickstartOpts) createMinimalPki() { //ziti pki create server --pki-root="${ZITI_HOME}/pki" --ca-name "intermediate-ca" --server-name "server" --server-file "server" --dns "localhost,${ZITI_HOSTNAME}" svr := pki.NewCmdPKICreateServer(o.out, o.errOut) + var ips = "127.0.0.1,::1" + ip_override := os.Getenv("ZITI_CTRL_EDGE_IP_OVERRIDE") + if ip_override != "" { + ips = ips + "," + ip_override + } svr.SetArgs([]string{ fmt.Sprintf("--pki-root=%s", where), fmt.Sprintf("--ca-name=%s", "intermediate-ca"), fmt.Sprintf("--server-name=%s", "server"), fmt.Sprintf("--server-file=%s", "server"), fmt.Sprintf("--dns=%s,%s", "localhost", helpers.GetCtrlAdvertisedAddress()), + fmt.Sprintf("--ip=%s", ips), }) svrErr := svr.Execute() if svrErr != nil { diff --git a/ziti/cmd/helpers/env_helpers.go b/ziti/cmd/helpers/env_helpers.go index 9960b24d2..78c90105d 100644 --- a/ziti/cmd/helpers/env_helpers.go +++ b/ziti/cmd/helpers/env_helpers.go @@ -96,10 +96,6 @@ func GetCtrlAdvertisedAddress() string { return getFromEnv(constants.CtrlAdvertisedAddressVarName, HostnameOrNetworkName) } -func GetCtrlIpOverride() string { - return getFromEnv(constants.CtrlAdvertisedAddressVarName, HostnameOrNetworkName) -} - func GetEdgeRouterIpOvderride() string { return getFromEnv(constants.ZitiEdgeRouterIPOverrideVarName, defaultValue("")) } From 9d47580002bdf95e51b210e4f622cb2b1dea7983 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 29 Nov 2023 16:53:45 -0500 Subject: [PATCH 04/16] make the linter proud --- common/zac/handler.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/common/zac/handler.go b/common/zac/handler.go index 0bce71264..f7f93864b 100644 --- a/common/zac/handler.go +++ b/common/zac/handler.go @@ -17,7 +17,6 @@ package zac import ( - gosundheit "github.com/AppsFlyer/go-sundheit" "github.com/openziti/xweb/v2" log "github.com/sirupsen/logrus" "net/http" @@ -31,7 +30,6 @@ const ( ) type ZitiAdminConsoleFactory struct { - healthChecker gosundheit.Health } var _ xweb.ApiHandlerFactory = &ZitiAdminConsoleFactory{} @@ -65,7 +63,6 @@ func (factory ZitiAdminConsoleFactory) New(_ *xweb.ServerConfig, options map[int } type ZitiAdminConsoleHandler struct { - options map[interface{}]interface{} httpHandler http.Handler } @@ -104,7 +101,7 @@ type spaHandler struct { func (h *spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { if strings.HasPrefix(r.URL.Path, h.contextRoot) { // strip off the path - r.URL.Path = r.URL.Path[len(h.contextRoot):] + r.URL.Path = strings.TrimPrefix(r.URL.Path, h.contextRoot) } p := filepath.Join(h.content, filepath.Clean(r.URL.Path)) From 137fc08054246fd72f26d458a30b843b00546eff Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 29 Nov 2023 17:14:56 -0500 Subject: [PATCH 05/16] publicDir -> location --- common/zac/handler.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/zac/handler.go b/common/zac/handler.go index f7f93864b..435068993 100644 --- a/common/zac/handler.go +++ b/common/zac/handler.go @@ -117,7 +117,7 @@ func (h *spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // Returns a request handler (http.Handler) that serves a single -// page application from a given public directory (publicDir). -func SpaHandler(publicDir string, contextRoot string, indexFile string) http.Handler { - return &spaHandler{publicDir, contextRoot, indexFile} +// page application from a given public directory (location). +func SpaHandler(location string, contextRoot string, indexFile string) http.Handler { + return &spaHandler{location, contextRoot, indexFile} } From f0463d831f463a1d386844cabbe6388bca000efc Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Wed, 29 Nov 2023 17:24:59 -0500 Subject: [PATCH 06/16] forgot to remove the if --- common/zac/handler.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/common/zac/handler.go b/common/zac/handler.go index 435068993..af759611a 100644 --- a/common/zac/handler.go +++ b/common/zac/handler.go @@ -99,10 +99,7 @@ type spaHandler struct { // (2) Request path is a directory // Otherwise serves the requested file. func (h *spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if strings.HasPrefix(r.URL.Path, h.contextRoot) { - // strip off the path - r.URL.Path = strings.TrimPrefix(r.URL.Path, h.contextRoot) - } + r.URL.Path = strings.TrimPrefix(r.URL.Path, h.contextRoot) p := filepath.Join(h.content, filepath.Clean(r.URL.Path)) if info, err := os.Stat(p); err != nil { From c7dd1757a3d0abda3a11eb6511970b48c9a87600 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Mon, 12 Feb 2024 15:31:17 -0500 Subject: [PATCH 07/16] renamed the handler to a more generic name updated the controller config to have a zac binding in place by default Signed-off-by: gberl002 --- common/{zac => spa_handler}/handler.go | 18 ++++++++++-------- controller/controller.go | 4 ++-- .../cmd/create/config_templates/controller.yml | 2 ++ 3 files changed, 14 insertions(+), 10 deletions(-) rename common/{zac => spa_handler}/handler.go (86%) diff --git a/common/zac/handler.go b/common/spa_handler/handler.go similarity index 86% rename from common/zac/handler.go rename to common/spa_handler/handler.go index af759611a..1f325269e 100644 --- a/common/zac/handler.go +++ b/common/spa_handler/handler.go @@ -14,7 +14,7 @@ limitations under the License. */ -package zac +package spa_handler import ( "github.com/openziti/xweb/v2" @@ -55,34 +55,34 @@ func (factory ZitiAdminConsoleFactory) New(_ *xweb.ServerConfig, options map[int if indexFile == nil || indexFile == "" { indexFile = "index.html" } - zac := &ZitiAdminConsoleHandler{ + zac := &SPAHTTPHandler{ httpHandler: SpaHandler(loc.(string), "/"+Binding, indexFile.(string)), } return zac, nil } -type ZitiAdminConsoleHandler struct { +type SPAHTTPHandler struct { httpHandler http.Handler } -func (self *ZitiAdminConsoleHandler) Binding() string { +func (self *SPAHTTPHandler) Binding() string { return Binding } -func (self *ZitiAdminConsoleHandler) Options() map[interface{}]interface{} { +func (self *SPAHTTPHandler) Options() map[interface{}]interface{} { return nil } -func (self *ZitiAdminConsoleHandler) RootPath() string { +func (self *SPAHTTPHandler) RootPath() string { return "/" + Binding } -func (self *ZitiAdminConsoleHandler) IsHandler(r *http.Request) bool { +func (self *SPAHTTPHandler) IsHandler(r *http.Request) bool { return strings.HasPrefix(r.URL.Path, self.RootPath()) || strings.HasPrefix(r.URL.Path, "/assets") } -func (self *ZitiAdminConsoleHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { +func (self *SPAHTTPHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { self.httpHandler.ServeHTTP(writer, request) } @@ -99,8 +99,10 @@ type spaHandler struct { // (2) Request path is a directory // Otherwise serves the requested file. func (h *spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + log.Debugf("incoming r.URL.Path: %s", r.URL.Path) r.URL.Path = strings.TrimPrefix(r.URL.Path, h.contextRoot) p := filepath.Join(h.content, filepath.Clean(r.URL.Path)) + log.Debugf("outgoing r.URL.Path: %s", p) if info, err := os.Stat(p); err != nil { http.ServeFile(w, r, filepath.Join(h.content, h.indexFile)) diff --git a/controller/controller.go b/controller/controller.go index ccf50b4d7..0f11c0f8d 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -25,7 +25,7 @@ import ( "github.com/openziti/transport/v2" "github.com/openziti/ziti/common/capabilities" "github.com/openziti/ziti/common/config" - "github.com/openziti/ziti/common/zac" + "github.com/openziti/ziti/common/spa_handler" "github.com/openziti/ziti/controller/event" "github.com/openziti/ziti/controller/events" "github.com/openziti/ziti/controller/handler_peer_ctrl" @@ -248,7 +248,7 @@ func (c *Controller) initWeb() { logrus.WithError(err).Fatalf("failed to create metrics api factory") } - if err := c.xweb.GetRegistry().Add(zac.NewZitiAdminConsoleFactory()); err != nil { + if err := c.xweb.GetRegistry().Add(spa_handler.NewZitiAdminConsoleFactory()); err != nil { logrus.WithError(err).Fatalf("failed to create myXweb factory") } diff --git a/ziti/cmd/create/config_templates/controller.yml b/ziti/cmd/create/config_templates/controller.yml index cd421a677..906a69657 100644 --- a/ziti/cmd/create/config_templates/controller.yml +++ b/ziti/cmd/create/config_templates/controller.yml @@ -215,3 +215,5 @@ web: options: { } - binding: fabric options: { } + - binding: zac + options: { } From 5aa6558061f7601795be2709383ab7112b3e5777 Mon Sep 17 00:00:00 2001 From: gberl002 Date: Tue, 27 Feb 2024 13:23:37 -0500 Subject: [PATCH 08/16] Changed panic to lesser level, commented zac binding by default Signed-off-by: gberl002 --- common/spa_handler/handler.go | 2 +- ziti/cmd/create/config_templates/controller.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/spa_handler/handler.go b/common/spa_handler/handler.go index 1f325269e..86a461242 100644 --- a/common/spa_handler/handler.go +++ b/common/spa_handler/handler.go @@ -49,7 +49,7 @@ func (factory ZitiAdminConsoleFactory) Binding() string { func (factory ZitiAdminConsoleFactory) New(_ *xweb.ServerConfig, options map[interface{}]interface{}) (xweb.ApiHandler, error) { loc := options["location"] if loc == nil || loc == "" { - log.Panic("location must be supplied in zac options") + log.Fatal("location must be supplied in zac options") } indexFile := options["indexFile"] if indexFile == nil || indexFile == "" { diff --git a/ziti/cmd/create/config_templates/controller.yml b/ziti/cmd/create/config_templates/controller.yml index 906a69657..1da02492b 100644 --- a/ziti/cmd/create/config_templates/controller.yml +++ b/ziti/cmd/create/config_templates/controller.yml @@ -215,5 +215,5 @@ web: options: { } - binding: fabric options: { } - - binding: zac - options: { } +# - binding: zac +# options: { } From 261e12043cb2c28fd8f422fa8b500fc5a50a0d0f Mon Sep 17 00:00:00 2001 From: gberl002 Date: Tue, 27 Feb 2024 14:34:02 -0500 Subject: [PATCH 09/16] Changing xweb to SPA for clarification Signed-off-by: gberl002 --- controller/controller.go | 38 ++++++++++---------- controller/env/appenv.go | 2 +- controller/internal/routes/version_router.go | 6 ++-- controller/server/controller.go | 6 ++-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/controller/controller.go b/controller/controller.go index d2cff2978..7476e4290 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -73,8 +73,8 @@ type Controller struct { xctrls []xctrl.Xctrl xmgmts []xmgmt.Xmgmt - xwebFactoryRegistry xweb.Registry - xweb xweb.Instance + spaFactoryRegistry xweb.Registry + spaHandler xweb.Instance ctrlListener channel.UnderlayListener mgmtListener channel.UnderlayListener @@ -170,12 +170,12 @@ func NewController(cfg *Config, versionProvider versions.VersionProvider) (*Cont log := pfxlog.Logger() c := &Controller{ - config: cfg, - shutdownC: shutdownC, - xwebFactoryRegistry: xweb.NewRegistryMap(), - metricsRegistry: metricRegistry, - versionProvider: versionProvider, - eventDispatcher: events.NewDispatcher(shutdownC), + config: cfg, + shutdownC: shutdownC, + spaFactoryRegistry: xweb.NewRegistryMap(), + metricsRegistry: metricRegistry, + versionProvider: versionProvider, + eventDispatcher: events.NewDispatcher(shutdownC), } if cfg.Raft != nil { @@ -234,22 +234,22 @@ func (c *Controller) initWeb() { logrus.WithError(err).Fatalf("failed to create health checker") } - c.xweb = xweb.NewDefaultInstance(c.xwebFactoryRegistry, c.config.Id) + c.spaHandler = xweb.NewDefaultInstance(c.spaFactoryRegistry, c.config.Id) - if err := c.xweb.GetRegistry().Add(health.NewHealthCheckApiFactory(healthChecker)); err != nil { + if err := c.spaHandler.GetRegistry().Add(health.NewHealthCheckApiFactory(healthChecker)); err != nil { logrus.WithError(err).Fatalf("failed to create health checks api factory") } - if err := c.xweb.GetRegistry().Add(api_impl.NewManagementApiFactory(c.config.Id, c.network, c.xmgmts)); err != nil { + if err := c.spaHandler.GetRegistry().Add(api_impl.NewManagementApiFactory(c.config.Id, c.network, c.xmgmts)); err != nil { logrus.WithError(err).Fatalf("failed to create management api factory") } - if err := c.xweb.GetRegistry().Add(api_impl.NewMetricsApiFactory(c.config.Id, c.network, c.xmgmts)); err != nil { + if err := c.spaHandler.GetRegistry().Add(api_impl.NewMetricsApiFactory(c.config.Id, c.network, c.xmgmts)); err != nil { logrus.WithError(err).Fatalf("failed to create metrics api factory") } - if err := c.xweb.GetRegistry().Add(spa_handler.NewZitiAdminConsoleFactory()); err != nil { - logrus.WithError(err).Fatalf("failed to create myXweb factory") + if err := c.spaHandler.GetRegistry().Add(spa_handler.NewZitiAdminConsoleFactory()); err != nil { + logrus.WithError(err).Fatalf("failed to create single page application factory") } } @@ -313,11 +313,11 @@ func (c *Controller) Run() error { go underlayDispatcher.Run() - if err := c.config.Configure(c.xweb); err != nil { + if err := c.config.Configure(c.spaHandler); err != nil { panic(err) } - go c.xweb.Run() + go c.spaHandler.Run() // event handlers if err := c.eventDispatcher.WireEventHandlers(c.getEventHandlerConfigs()); err != nil { @@ -373,7 +373,7 @@ func (c *Controller) Shutdown() { } } - go c.xweb.Shutdown() + go c.spaHandler.Shutdown() } } @@ -436,8 +436,8 @@ func (c *Controller) RegisterXmgmt(x xmgmt.Xmgmt) error { return nil } -func (c *Controller) GetXWebInstance() xweb.Instance { - return c.xweb +func (c *Controller) GetSPAInstance() xweb.Instance { + return c.spaHandler } func (c *Controller) GetNetwork() *network.Network { diff --git a/controller/env/appenv.go b/controller/env/appenv.go index c4e5bd314..10cc9ba3f 100644 --- a/controller/env/appenv.go +++ b/controller/env/appenv.go @@ -201,7 +201,7 @@ type HostController interface { RegisterAgentBindHandler(bindHandler channel.BindHandler) RegisterXctrl(x xctrl.Xctrl) error RegisterXmgmt(x xmgmt.Xmgmt) error - GetXWebInstance() xweb.Instance + GetSPAInstance() xweb.Instance GetNetwork() *network.Network GetCloseNotifyChannel() <-chan struct{} Shutdown() diff --git a/controller/internal/routes/version_router.go b/controller/internal/routes/version_router.go index be613c91f..bf82e66c3 100644 --- a/controller/internal/routes/version_router.go +++ b/controller/internal/routes/version_router.go @@ -22,12 +22,12 @@ import ( clientInformational "github.com/openziti/edge-api/rest_client_api_server/operations/informational" managementInformational "github.com/openziti/edge-api/rest_management_api_server/operations/informational" "github.com/openziti/edge-api/rest_model" + "github.com/openziti/xweb/v2" + "github.com/openziti/ziti/common/build" "github.com/openziti/ziti/controller" "github.com/openziti/ziti/controller/env" "github.com/openziti/ziti/controller/internal/permissions" "github.com/openziti/ziti/controller/response" - "github.com/openziti/ziti/common/build" - "github.com/openziti/xweb/v2" "runtime" "sync" ) @@ -118,7 +118,7 @@ func (ir *VersionRouter) List(ae *env.AppEnv, rc *response.RequestContext) { oidcEnabled := false - for _, serverConfig := range ae.HostController.GetXWebInstance().GetConfig().ServerConfigs { + for _, serverConfig := range ae.HostController.GetSPAInstance().GetConfig().ServerConfigs { for _, api := range serverConfig.APIs { if api.Binding() == controller.OidcApiBinding { oidcEnabled = true diff --git a/controller/server/controller.go b/controller/server/controller.go index 579b86eb4..4ce5f944f 100644 --- a/controller/server/controller.go +++ b/controller/server/controller.go @@ -291,15 +291,15 @@ func (c *Controller) Run() { clientApiFactory := NewClientApiFactory(c.AppEnv) oidcApiFactory := NewOidcApiFactory(c.AppEnv) - if err := c.AppEnv.HostController.GetXWebInstance().GetRegistry().Add(managementApiFactory); err != nil { + if err := c.AppEnv.HostController.GetSPAInstance().GetRegistry().Add(managementApiFactory); err != nil { pfxlog.Logger().Fatalf("failed to create Edge Management API factory: %v", err) } - if err := c.AppEnv.HostController.GetXWebInstance().GetRegistry().Add(clientApiFactory); err != nil { + if err := c.AppEnv.HostController.GetSPAInstance().GetRegistry().Add(clientApiFactory); err != nil { pfxlog.Logger().Fatalf("failed to create Edge Client API factory: %v", err) } - if err := c.AppEnv.HostController.GetXWebInstance().GetRegistry().Add(oidcApiFactory); err != nil { + if err := c.AppEnv.HostController.GetSPAInstance().GetRegistry().Add(oidcApiFactory); err != nil { pfxlog.Logger().Fatalf("failed to create OIDC API factory: %v", err) } From 5ebaf90f6b0f132482c159191e1c6897a212ce8d Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 27 Feb 2024 18:17:19 -0500 Subject: [PATCH 10/16] update template and rename zac to spa --- common/spa_handler/handler.go | 37 +++++++++---------- .../create/config_templates/controller.yml | 2 +- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/common/spa_handler/handler.go b/common/spa_handler/handler.go index 86a461242..2b9659726 100644 --- a/common/spa_handler/handler.go +++ b/common/spa_handler/handler.go @@ -26,63 +26,64 @@ import ( ) const ( - Binding = "zac" + Binding = "spa" ) -type ZitiAdminConsoleFactory struct { +type SinglePageAppFactory struct { } -var _ xweb.ApiHandlerFactory = &ZitiAdminConsoleFactory{} +var _ xweb.ApiHandlerFactory = &SinglePageAppFactory{} -func NewZitiAdminConsoleFactory() *ZitiAdminConsoleFactory { - return &ZitiAdminConsoleFactory{} +func NewSinglePageAppFactory() *SinglePageAppFactory { + return &SinglePageAppFactory{} } -func (factory ZitiAdminConsoleFactory) Validate(*xweb.InstanceConfig) error { +func (factory SinglePageAppFactory) Validate(*xweb.InstanceConfig) error { return nil } -func (factory ZitiAdminConsoleFactory) Binding() string { +func (factory SinglePageAppFactory) Binding() string { return Binding } -func (factory ZitiAdminConsoleFactory) New(_ *xweb.ServerConfig, options map[interface{}]interface{}) (xweb.ApiHandler, error) { +func (factory SinglePageAppFactory) New(_ *xweb.ServerConfig, options map[interface{}]interface{}) (xweb.ApiHandler, error) { loc := options["location"] if loc == nil || loc == "" { - log.Fatal("location must be supplied in zac options") + log.Panic("location must be supplied in spa options") } indexFile := options["indexFile"] if indexFile == nil || indexFile == "" { indexFile = "index.html" } - zac := &SPAHTTPHandler{ + spa := &SinglePageAppHandler{ httpHandler: SpaHandler(loc.(string), "/"+Binding, indexFile.(string)), } - return zac, nil + log.Infof("intializing SPA Handler from %s", loc) + return spa, nil } -type SPAHTTPHandler struct { +type SinglePageAppHandler struct { httpHandler http.Handler } -func (self *SPAHTTPHandler) Binding() string { +func (self *SinglePageAppHandler) Binding() string { return Binding } -func (self *SPAHTTPHandler) Options() map[interface{}]interface{} { +func (self *SinglePageAppHandler) Options() map[interface{}]interface{} { return nil } -func (self *SPAHTTPHandler) RootPath() string { +func (self *SinglePageAppHandler) RootPath() string { return "/" + Binding } -func (self *SPAHTTPHandler) IsHandler(r *http.Request) bool { +func (self *SinglePageAppHandler) IsHandler(r *http.Request) bool { return strings.HasPrefix(r.URL.Path, self.RootPath()) || strings.HasPrefix(r.URL.Path, "/assets") } -func (self *SPAHTTPHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { +func (self *SinglePageAppHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { self.httpHandler.ServeHTTP(writer, request) } @@ -99,10 +100,8 @@ type spaHandler struct { // (2) Request path is a directory // Otherwise serves the requested file. func (h *spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - log.Debugf("incoming r.URL.Path: %s", r.URL.Path) r.URL.Path = strings.TrimPrefix(r.URL.Path, h.contextRoot) p := filepath.Join(h.content, filepath.Clean(r.URL.Path)) - log.Debugf("outgoing r.URL.Path: %s", p) if info, err := os.Stat(p); err != nil { http.ServeFile(w, r, filepath.Join(h.content, h.indexFile)) diff --git a/ziti/cmd/create/config_templates/controller.yml b/ziti/cmd/create/config_templates/controller.yml index 1da02492b..d476983e9 100644 --- a/ziti/cmd/create/config_templates/controller.yml +++ b/ziti/cmd/create/config_templates/controller.yml @@ -216,4 +216,4 @@ web: - binding: fabric options: { } # - binding: zac -# options: { } +# options: { "location": "./zac", "indexFile":"index.html" } From 26698531c46cb864f29dc3459398bd114067f7b0 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 27 Feb 2024 18:18:59 -0500 Subject: [PATCH 11/16] rename from NewZitiAdminConsoleFactory to NewSinglePageAppFactory --- controller/controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/controller.go b/controller/controller.go index 7476e4290..a600aecfb 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -248,7 +248,7 @@ func (c *Controller) initWeb() { logrus.WithError(err).Fatalf("failed to create metrics api factory") } - if err := c.spaHandler.GetRegistry().Add(spa_handler.NewZitiAdminConsoleFactory()); err != nil { + if err := c.spaHandler.GetRegistry().Add(spa_handler.NewSinglePageAppFactory()); err != nil { logrus.WithError(err).Fatalf("failed to create single page application factory") } From 1f94fd5ebe5e95e01cf74a697090e35135f0ffa2 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 27 Feb 2024 18:31:33 -0500 Subject: [PATCH 12/16] fix refactor gone awry --- controller/controller.go | 2 +- controller/env/appenv.go | 2 +- controller/internal/routes/version_router.go | 2 +- controller/server/controller.go | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/controller/controller.go b/controller/controller.go index a600aecfb..c8d129227 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -436,7 +436,7 @@ func (c *Controller) RegisterXmgmt(x xmgmt.Xmgmt) error { return nil } -func (c *Controller) GetSPAInstance() xweb.Instance { +func (c *Controller) GetXWebInstance() xweb.Instance { return c.spaHandler } diff --git a/controller/env/appenv.go b/controller/env/appenv.go index 10cc9ba3f..c4e5bd314 100644 --- a/controller/env/appenv.go +++ b/controller/env/appenv.go @@ -201,7 +201,7 @@ type HostController interface { RegisterAgentBindHandler(bindHandler channel.BindHandler) RegisterXctrl(x xctrl.Xctrl) error RegisterXmgmt(x xmgmt.Xmgmt) error - GetSPAInstance() xweb.Instance + GetXWebInstance() xweb.Instance GetNetwork() *network.Network GetCloseNotifyChannel() <-chan struct{} Shutdown() diff --git a/controller/internal/routes/version_router.go b/controller/internal/routes/version_router.go index bf82e66c3..9b2663d3c 100644 --- a/controller/internal/routes/version_router.go +++ b/controller/internal/routes/version_router.go @@ -118,7 +118,7 @@ func (ir *VersionRouter) List(ae *env.AppEnv, rc *response.RequestContext) { oidcEnabled := false - for _, serverConfig := range ae.HostController.GetSPAInstance().GetConfig().ServerConfigs { + for _, serverConfig := range ae.HostController.GetXWebInstance().GetConfig().ServerConfigs { for _, api := range serverConfig.APIs { if api.Binding() == controller.OidcApiBinding { oidcEnabled = true diff --git a/controller/server/controller.go b/controller/server/controller.go index 4ce5f944f..579b86eb4 100644 --- a/controller/server/controller.go +++ b/controller/server/controller.go @@ -291,15 +291,15 @@ func (c *Controller) Run() { clientApiFactory := NewClientApiFactory(c.AppEnv) oidcApiFactory := NewOidcApiFactory(c.AppEnv) - if err := c.AppEnv.HostController.GetSPAInstance().GetRegistry().Add(managementApiFactory); err != nil { + if err := c.AppEnv.HostController.GetXWebInstance().GetRegistry().Add(managementApiFactory); err != nil { pfxlog.Logger().Fatalf("failed to create Edge Management API factory: %v", err) } - if err := c.AppEnv.HostController.GetSPAInstance().GetRegistry().Add(clientApiFactory); err != nil { + if err := c.AppEnv.HostController.GetXWebInstance().GetRegistry().Add(clientApiFactory); err != nil { pfxlog.Logger().Fatalf("failed to create Edge Client API factory: %v", err) } - if err := c.AppEnv.HostController.GetSPAInstance().GetRegistry().Add(oidcApiFactory); err != nil { + if err := c.AppEnv.HostController.GetXWebInstance().GetRegistry().Add(oidcApiFactory); err != nil { pfxlog.Logger().Fatalf("failed to create OIDC API factory: %v", err) } From 5b2d67e80bae94ec5cc65ddd0c0b67bfa89d1c29 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:24:39 -0500 Subject: [PATCH 13/16] rearrange where the zac handler goes and keep spa handler separate --- common/spa_handler/handler.go | 51 +++++------------------------------ controller/controller.go | 4 +-- controller/zac/factory.go | 46 +++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 47 deletions(-) create mode 100644 controller/zac/factory.go diff --git a/common/spa_handler/handler.go b/common/spa_handler/handler.go index 2b9659726..95150de16 100644 --- a/common/spa_handler/handler.go +++ b/common/spa_handler/handler.go @@ -17,58 +17,19 @@ package spa_handler import ( - "github.com/openziti/xweb/v2" - log "github.com/sirupsen/logrus" "net/http" "os" "path/filepath" "strings" ) -const ( - Binding = "spa" -) - -type SinglePageAppFactory struct { -} - -var _ xweb.ApiHandlerFactory = &SinglePageAppFactory{} - -func NewSinglePageAppFactory() *SinglePageAppFactory { - return &SinglePageAppFactory{} -} - -func (factory SinglePageAppFactory) Validate(*xweb.InstanceConfig) error { - return nil -} - -func (factory SinglePageAppFactory) Binding() string { - return Binding -} - -func (factory SinglePageAppFactory) New(_ *xweb.ServerConfig, options map[interface{}]interface{}) (xweb.ApiHandler, error) { - loc := options["location"] - if loc == nil || loc == "" { - log.Panic("location must be supplied in spa options") - } - indexFile := options["indexFile"] - if indexFile == nil || indexFile == "" { - indexFile = "index.html" - } - spa := &SinglePageAppHandler{ - httpHandler: SpaHandler(loc.(string), "/"+Binding, indexFile.(string)), - } - - log.Infof("intializing SPA Handler from %s", loc) - return spa, nil -} - type SinglePageAppHandler struct { - httpHandler http.Handler + HttpHandler http.Handler + BindingKey string } func (self *SinglePageAppHandler) Binding() string { - return Binding + return self.BindingKey } func (self *SinglePageAppHandler) Options() map[interface{}]interface{} { @@ -76,7 +37,7 @@ func (self *SinglePageAppHandler) Options() map[interface{}]interface{} { } func (self *SinglePageAppHandler) RootPath() string { - return "/" + Binding + return "/" + self.BindingKey } func (self *SinglePageAppHandler) IsHandler(r *http.Request) bool { @@ -84,7 +45,7 @@ func (self *SinglePageAppHandler) IsHandler(r *http.Request) bool { } func (self *SinglePageAppHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { - self.httpHandler.ServeHTTP(writer, request) + self.HttpHandler.ServeHTTP(writer, request) } // Thanks to https://github.com/roberthodgen/spa-server @@ -114,7 +75,7 @@ func (h *spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, p) } -// Returns a request handler (http.Handler) that serves a single +// SpaHandler returns a request handler (http.Handler) that serves a single // page application from a given public directory (location). func SpaHandler(location string, contextRoot string, indexFile string) http.Handler { return &spaHandler{location, contextRoot, indexFile} diff --git a/controller/controller.go b/controller/controller.go index c8d129227..4656d5572 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -25,10 +25,10 @@ import ( "github.com/openziti/transport/v2" "github.com/openziti/ziti/common/capabilities" "github.com/openziti/ziti/common/config" - "github.com/openziti/ziti/common/spa_handler" "github.com/openziti/ziti/controller/event" "github.com/openziti/ziti/controller/events" "github.com/openziti/ziti/controller/handler_peer_ctrl" + "github.com/openziti/ziti/controller/zac" "math/big" "os" "sync/atomic" @@ -248,7 +248,7 @@ func (c *Controller) initWeb() { logrus.WithError(err).Fatalf("failed to create metrics api factory") } - if err := c.spaHandler.GetRegistry().Add(spa_handler.NewSinglePageAppFactory()); err != nil { + if err := c.spaHandler.GetRegistry().Add(zac.NewZitiAdminConsoleFactory()); err != nil { logrus.WithError(err).Fatalf("failed to create single page application factory") } diff --git a/controller/zac/factory.go b/controller/zac/factory.go new file mode 100644 index 000000000..ebd58e32f --- /dev/null +++ b/controller/zac/factory.go @@ -0,0 +1,46 @@ +package zac + +import ( + "github.com/openziti/xweb/v2" + "github.com/openziti/ziti/common/spa_handler" + log "github.com/sirupsen/logrus" +) + +const ( + Binding = "zac" +) + +type ZitiAdminConsoleFactory struct { +} + +var _ xweb.ApiHandlerFactory = &ZitiAdminConsoleFactory{} + +func NewZitiAdminConsoleFactory() *ZitiAdminConsoleFactory { + return &ZitiAdminConsoleFactory{} +} + +func (factory ZitiAdminConsoleFactory) Validate(*xweb.InstanceConfig) error { + return nil +} + +func (factory ZitiAdminConsoleFactory) Binding() string { + return Binding +} + +func (factory ZitiAdminConsoleFactory) New(_ *xweb.ServerConfig, options map[interface{}]interface{}) (xweb.ApiHandler, error) { + loc := options["location"] + if loc == nil || loc == "" { + log.Panic("location must be supplied in spa options") + } + indexFile := options["indexFile"] + if indexFile == nil || indexFile == "" { + indexFile = "index.html" + } + spa := &spa_handler.SinglePageAppHandler{ + HttpHandler: spa_handler.SpaHandler(loc.(string), "/"+Binding, indexFile.(string)), + BindingKey: Binding, + } + + log.Infof("intializing ZAC SPA Handler from %s", loc) + return spa, nil +} From e8080bdd1bb4dfceb339f1236a7f84755496ecae Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:26:16 -0500 Subject: [PATCH 14/16] minor refactor --- common/spa_handler/handler.go | 18 +++++++++--------- controller/zac/factory.go | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/common/spa_handler/handler.go b/common/spa_handler/handler.go index 95150de16..11d310eba 100644 --- a/common/spa_handler/handler.go +++ b/common/spa_handler/handler.go @@ -28,24 +28,24 @@ type SinglePageAppHandler struct { BindingKey string } -func (self *SinglePageAppHandler) Binding() string { - return self.BindingKey +func (spa *SinglePageAppHandler) Binding() string { + return spa.BindingKey } -func (self *SinglePageAppHandler) Options() map[interface{}]interface{} { +func (spa *SinglePageAppHandler) Options() map[interface{}]interface{} { return nil } -func (self *SinglePageAppHandler) RootPath() string { - return "/" + self.BindingKey +func (spa *SinglePageAppHandler) RootPath() string { + return "/" + spa.BindingKey } -func (self *SinglePageAppHandler) IsHandler(r *http.Request) bool { - return strings.HasPrefix(r.URL.Path, self.RootPath()) || strings.HasPrefix(r.URL.Path, "/assets") +func (spa *SinglePageAppHandler) IsHandler(r *http.Request) bool { + return strings.HasPrefix(r.URL.Path, spa.RootPath()) || strings.HasPrefix(r.URL.Path, "/assets") } -func (self *SinglePageAppHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { - self.HttpHandler.ServeHTTP(writer, request) +func (spa *SinglePageAppHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) { + spa.HttpHandler.ServeHTTP(writer, request) } // Thanks to https://github.com/roberthodgen/spa-server diff --git a/controller/zac/factory.go b/controller/zac/factory.go index ebd58e32f..6f814b491 100644 --- a/controller/zac/factory.go +++ b/controller/zac/factory.go @@ -30,7 +30,7 @@ func (factory ZitiAdminConsoleFactory) Binding() string { func (factory ZitiAdminConsoleFactory) New(_ *xweb.ServerConfig, options map[interface{}]interface{}) (xweb.ApiHandler, error) { loc := options["location"] if loc == nil || loc == "" { - log.Panic("location must be supplied in spa options") + log.Fatal("location must be supplied in " + Binding + " options") } indexFile := options["indexFile"] if indexFile == nil || indexFile == "" { From a7a6c82a0a06aa3f856d43c855e432f1bc61e142 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:28:13 -0500 Subject: [PATCH 15/16] initializing --- controller/zac/factory.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/zac/factory.go b/controller/zac/factory.go index 6f814b491..be2721433 100644 --- a/controller/zac/factory.go +++ b/controller/zac/factory.go @@ -41,6 +41,6 @@ func (factory ZitiAdminConsoleFactory) New(_ *xweb.ServerConfig, options map[int BindingKey: Binding, } - log.Infof("intializing ZAC SPA Handler from %s", loc) + log.Infof("initializing ZAC SPA Handler from %s", loc) return spa, nil } From 8d2b239db96039e611fdb4c45fd05c03a6345ab7 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Tue, 27 Feb 2024 20:43:58 -0500 Subject: [PATCH 16/16] actually undo unexpected refactor --- controller/controller.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/controller/controller.go b/controller/controller.go index 4656d5572..aefec258a 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -73,8 +73,8 @@ type Controller struct { xctrls []xctrl.Xctrl xmgmts []xmgmt.Xmgmt - spaFactoryRegistry xweb.Registry - spaHandler xweb.Instance + xwebFactoryRegistry xweb.Registry + xweb xweb.Instance ctrlListener channel.UnderlayListener mgmtListener channel.UnderlayListener @@ -170,12 +170,12 @@ func NewController(cfg *Config, versionProvider versions.VersionProvider) (*Cont log := pfxlog.Logger() c := &Controller{ - config: cfg, - shutdownC: shutdownC, - spaFactoryRegistry: xweb.NewRegistryMap(), - metricsRegistry: metricRegistry, - versionProvider: versionProvider, - eventDispatcher: events.NewDispatcher(shutdownC), + config: cfg, + shutdownC: shutdownC, + xwebFactoryRegistry: xweb.NewRegistryMap(), + metricsRegistry: metricRegistry, + versionProvider: versionProvider, + eventDispatcher: events.NewDispatcher(shutdownC), } if cfg.Raft != nil { @@ -234,21 +234,21 @@ func (c *Controller) initWeb() { logrus.WithError(err).Fatalf("failed to create health checker") } - c.spaHandler = xweb.NewDefaultInstance(c.spaFactoryRegistry, c.config.Id) + c.xweb = xweb.NewDefaultInstance(c.xwebFactoryRegistry, c.config.Id) - if err := c.spaHandler.GetRegistry().Add(health.NewHealthCheckApiFactory(healthChecker)); err != nil { + if err := c.xweb.GetRegistry().Add(health.NewHealthCheckApiFactory(healthChecker)); err != nil { logrus.WithError(err).Fatalf("failed to create health checks api factory") } - if err := c.spaHandler.GetRegistry().Add(api_impl.NewManagementApiFactory(c.config.Id, c.network, c.xmgmts)); err != nil { + if err := c.xweb.GetRegistry().Add(api_impl.NewManagementApiFactory(c.config.Id, c.network, c.xmgmts)); err != nil { logrus.WithError(err).Fatalf("failed to create management api factory") } - if err := c.spaHandler.GetRegistry().Add(api_impl.NewMetricsApiFactory(c.config.Id, c.network, c.xmgmts)); err != nil { + if err := c.xweb.GetRegistry().Add(api_impl.NewMetricsApiFactory(c.config.Id, c.network, c.xmgmts)); err != nil { logrus.WithError(err).Fatalf("failed to create metrics api factory") } - if err := c.spaHandler.GetRegistry().Add(zac.NewZitiAdminConsoleFactory()); err != nil { + if err := c.xweb.GetRegistry().Add(zac.NewZitiAdminConsoleFactory()); err != nil { logrus.WithError(err).Fatalf("failed to create single page application factory") } @@ -313,11 +313,11 @@ func (c *Controller) Run() error { go underlayDispatcher.Run() - if err := c.config.Configure(c.spaHandler); err != nil { + if err := c.config.Configure(c.xweb); err != nil { panic(err) } - go c.spaHandler.Run() + go c.xweb.Run() // event handlers if err := c.eventDispatcher.WireEventHandlers(c.getEventHandlerConfigs()); err != nil { @@ -373,7 +373,7 @@ func (c *Controller) Shutdown() { } } - go c.spaHandler.Shutdown() + go c.xweb.Shutdown() } } @@ -437,7 +437,7 @@ func (c *Controller) RegisterXmgmt(x xmgmt.Xmgmt) error { } func (c *Controller) GetXWebInstance() xweb.Instance { - return c.spaHandler + return c.xweb } func (c *Controller) GetNetwork() *network.Network {