Skip to content

Commit

Permalink
Fix set of empty roles from CLI. Fixes #785
Browse files Browse the repository at this point in the history
Also includes removal of an unused method
  • Loading branch information
plorenz committed Jul 10, 2024
1 parent c3b4313 commit 845fb23
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 43 deletions.
48 changes: 6 additions & 42 deletions controller/server/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type Controller struct {
xmgmt *submgmt
xctrl *subctrl
policyEngine runner2.Runner
isLoaded bool
initModulesOnce sync.Once
initialized bool
}
Expand All @@ -63,7 +62,7 @@ func NewController(host env.HostController) (*Controller, error) {
AppEnv: host.GetEnv(),
}

if !c.IsEnabled() {
if !c.Enabled() {
return c, nil
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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() {
Expand All @@ -212,7 +175,7 @@ func (c *Controller) initializeAuthModules() {
}

func (c *Controller) Initialize() {
if !c.config.Enabled {
if !c.Enabled() {
return
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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...")
Expand Down
1 change: 0 additions & 1 deletion controller/subcmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func configureController(configPath string, versionProvider versions.VersionProv
panic(err)
}

edgeController.SetHostController(fabricController)
edgeController.Initialize()

return edgeController
Expand Down
5 changes: 5 additions & 0 deletions ziti/cmd/edge/create_service_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 845fb23

Please sign in to comment.