From 845fb23780f18e76dcebfe304c4c31545a3495f3 Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Wed, 10 Jul 2024 13:52:42 -0400 Subject: [PATCH] Fix set of empty roles from CLI. Fixes #785 Also includes removal of an unused method --- controller/server/controller.go | 48 ++++---------------------- controller/subcmd/init.go | 1 - ziti/cmd/edge/create_service_policy.go | 5 +++ 3 files changed, 11 insertions(+), 43 deletions(-) diff --git a/controller/server/controller.go b/controller/server/controller.go index 7a565113b..72e6a7095 100644 --- a/controller/server/controller.go +++ b/controller/server/controller.go @@ -43,7 +43,6 @@ type Controller struct { xmgmt *submgmt xctrl *subctrl policyEngine runner2.Runner - isLoaded bool initModulesOnce sync.Once initialized bool } @@ -63,7 +62,7 @@ func NewController(host env.HostController) (*Controller, error) { AppEnv: host.GetEnv(), } - if !c.IsEnabled() { + if !c.Enabled() { return c, nil } @@ -118,27 +117,6 @@ func NewController(host env.HostController) (*Controller, error) { return c, nil } -func (c *Controller) IsEnabled() bool { - return c.config != nil && c.config.Enabled -} - -func (c *Controller) SetHostController(h env.HostController) { - if !c.IsEnabled() { - return - } - - c.AppEnv.HostController = h - c.AppEnv.TraceManager = env.NewTraceManager(h.GetCloseNotifyChannel()) - c.AppEnv.HostController.GetNetwork().AddCapability("ziti.edge") - if err := h.RegisterXctrl(c.xctrl); err != nil { - panic(err) - } - - if err := h.RegisterXmgmt(c.xmgmt); err != nil { - panic(err) - } -} - func (c *Controller) GetCtrlHandlers(binding channel.Binding) []channel.TypedReceiveHandler { ch := binding.GetChannel() tunnelState := handler_edge_ctrl.NewTunnelState() @@ -177,23 +155,8 @@ func (c *Controller) GetMgmtHandlers() []channel.TypedReceiveHandler { } } -func (c *Controller) LoadConfig(cfgmap map[interface{}]interface{}) error { - if c.isLoaded { - return nil - } - - parsedConfig, err := edgeconfig.LoadEdgeConfigFromMap(cfgmap) - if err != nil { - return fmt.Errorf("error loading edge controller configuration: %s", err.Error()) - } - - c.config = parsedConfig - - return nil -} - func (c *Controller) Enabled() bool { - return c.config.Enabled + return c.AppEnv.HostController.GetConfig().Edge.Enabled } func (c *Controller) initializeAuthModules() { @@ -212,7 +175,7 @@ func (c *Controller) initializeAuthModules() { } func (c *Controller) Initialize() { - if !c.config.Enabled { + if !c.Enabled() { return } @@ -263,9 +226,10 @@ func (c *Controller) Initialize() { } func (c *Controller) Run() { - if !c.config.Enabled { + if !c.Enabled() { return } + log := pfxlog.Logger() if !c.initialized { @@ -339,7 +303,7 @@ func (c *Controller) checkEdgeInitialized() { } func (c *Controller) Shutdown() { - if c.config.Enabled { + if c.Enabled() { log := pfxlog.Logger() pfxlog.Logger().Info("edge controller: shutting down...") diff --git a/controller/subcmd/init.go b/controller/subcmd/init.go index 74ff7ba64..501ead626 100644 --- a/controller/subcmd/init.go +++ b/controller/subcmd/init.go @@ -161,7 +161,6 @@ func configureController(configPath string, versionProvider versions.VersionProv panic(err) } - edgeController.SetHostController(fabricController) edgeController.Initialize() return edgeController diff --git a/ziti/cmd/edge/create_service_policy.go b/ziti/cmd/edge/create_service_policy.go index 2085c750c..ccf0f516b 100644 --- a/ziti/cmd/edge/create_service_policy.go +++ b/ziti/cmd/edge/create_service_policy.go @@ -119,5 +119,10 @@ func convertNamesToIds(roles []string, entityType string, o api.Options) ([]stri result = append(result, val) } } + // The REST endpoints treat an empty slice differently from a nil, + // and in this case it's important to pass in an empty slice + if result == nil { + return []string{}, nil + } return result, nil }