From 24b5e8f100e834dab52c24308e2f0f62605c7e41 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Tue, 16 Jan 2024 09:16:21 +0100 Subject: [PATCH] Fix #2733 "cscli hang forever when i try to delete a decision" (#2745) --- pkg/apiserver/apiserver.go | 14 ++++++++------ pkg/csconfig/console.go | 7 +++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index a85cffcf5..b1724784c 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -245,12 +245,14 @@ func NewServer(config *csconfig.LocalApiServerCfg) (*APIServer, error) { if apiClient.apiClient.IsEnrolled() { log.Infof("Machine is enrolled in the console, Loading PAPI Client") - papiClient, err = NewPAPI(apiClient, dbClient, config.ConsoleConfig, *config.PapiLogLevel) - if err != nil { - return nil, err - } + if config.ConsoleConfig.IsPAPIEnabled() { + papiClient, err = NewPAPI(apiClient, dbClient, config.ConsoleConfig, *config.PapiLogLevel) + if err != nil { + return nil, err + } - controller.DecisionDeleteChan = papiClient.Channels.DeleteDecisionChannel + controller.DecisionDeleteChan = papiClient.Channels.DeleteDecisionChannel + } } else { log.Errorf("Machine is not enrolled in the console, can't synchronize with the console") } @@ -317,7 +319,7 @@ func (s *APIServer) Run(apiReady chan bool) error { //csConfig.API.Server.ConsoleConfig.ShareCustomScenarios if s.apic.apiClient.IsEnrolled() { - if s.consoleConfig.ConsoleManagement != nil && *s.consoleConfig.ConsoleManagement { + if s.consoleConfig.IsPAPIEnabled() { if s.papi.URL != "" { log.Infof("Starting PAPI decision receiver") s.papi.pullTomb.Go(func() error { diff --git a/pkg/csconfig/console.go b/pkg/csconfig/console.go index c8e83dcd8..9e3b1e5ac 100644 --- a/pkg/csconfig/console.go +++ b/pkg/csconfig/console.go @@ -30,6 +30,13 @@ type ConsoleConfig struct { ShareContext *bool `yaml:"share_context"` } +func (c *ConsoleConfig) IsPAPIEnabled() bool { + if c == nil || c.ConsoleManagement == nil { + return false + } + return *c.ConsoleManagement +} + func (c *LocalApiServerCfg) LoadConsoleConfig() error { c.ConsoleConfig = &ConsoleConfig{} if _, err := os.Stat(c.ConsoleConfigPath); err != nil && os.IsNotExist(err) {