do not try to load PAPI is url is not set (#2099)
This commit is contained in:
parent
e27a0a0e14
commit
16a3be49e2
6 changed files with 33 additions and 29 deletions
|
@ -215,7 +215,7 @@ Disable given information push to the central API.`,
|
|||
{csconfig.SEND_CUSTOM_SCENARIOS, fmt.Sprintf("%t", *csConfig.API.Server.ConsoleConfig.ShareCustomScenarios)},
|
||||
{csconfig.SEND_TAINTED_SCENARIOS, fmt.Sprintf("%t", *csConfig.API.Server.ConsoleConfig.ShareTaintedScenarios)},
|
||||
{csconfig.SEND_CONTEXT, fmt.Sprintf("%t", *csConfig.API.Server.ConsoleConfig.ShareContext)},
|
||||
{csconfig.CONSOLE_MANAGEMENT, fmt.Sprintf("%t", *csConfig.API.Server.ConsoleConfig.ReceiveDecisions)},
|
||||
{csconfig.CONSOLE_MANAGEMENT, fmt.Sprintf("%t", *csConfig.API.Server.ConsoleConfig.ConsoleManagement)},
|
||||
}
|
||||
for _, row := range rows {
|
||||
err = csvwriter.Write(row)
|
||||
|
@ -240,16 +240,16 @@ func SetConsoleOpts(args []string, wanted bool) {
|
|||
continue
|
||||
}
|
||||
/*for each flag check if it's already set before setting it*/
|
||||
if csConfig.API.Server.ConsoleConfig.ReceiveDecisions != nil {
|
||||
if *csConfig.API.Server.ConsoleConfig.ReceiveDecisions == wanted {
|
||||
if csConfig.API.Server.ConsoleConfig.ConsoleManagement != nil {
|
||||
if *csConfig.API.Server.ConsoleConfig.ConsoleManagement == wanted {
|
||||
log.Debugf("%s already set to %t", csconfig.CONSOLE_MANAGEMENT, wanted)
|
||||
} else {
|
||||
log.Infof("%s set to %t", csconfig.CONSOLE_MANAGEMENT, wanted)
|
||||
*csConfig.API.Server.ConsoleConfig.ReceiveDecisions = wanted
|
||||
*csConfig.API.Server.ConsoleConfig.ConsoleManagement = wanted
|
||||
}
|
||||
} else {
|
||||
log.Infof("%s set to %t", csconfig.CONSOLE_MANAGEMENT, wanted)
|
||||
csConfig.API.Server.ConsoleConfig.ReceiveDecisions = types.BoolPtr(wanted)
|
||||
csConfig.API.Server.ConsoleConfig.ConsoleManagement = types.BoolPtr(wanted)
|
||||
}
|
||||
if csConfig.API.Server.OnlineClient.Credentials != nil {
|
||||
changed := false
|
||||
|
|
|
@ -49,7 +49,7 @@ func cmdConsoleStatusTable(out io.Writer, csConfig csconfig.Config) {
|
|||
t.AddRow(option, activated, "Send context with alerts to the console")
|
||||
case csconfig.CONSOLE_MANAGEMENT:
|
||||
activated := string(emoji.CrossMark)
|
||||
if *csConfig.API.Server.ConsoleConfig.ReceiveDecisions {
|
||||
if *csConfig.API.Server.ConsoleConfig.ConsoleManagement {
|
||||
activated = string(emoji.CheckMarkButton)
|
||||
}
|
||||
t.AddRow(option, activated, "Receive decisions from console")
|
||||
|
|
|
@ -356,23 +356,27 @@ func (s *APIServer) Run(apiReady chan bool) error {
|
|||
//csConfig.API.Server.ConsoleConfig.ShareCustomScenarios
|
||||
if s.isEnrolled {
|
||||
if fflag.PapiClient.IsEnabled() {
|
||||
if s.consoleConfig.ReceiveDecisions != nil && *s.consoleConfig.ReceiveDecisions {
|
||||
log.Infof("Starting PAPI decision receiver")
|
||||
s.papi.pullTomb.Go(func() error {
|
||||
if err := s.papi.Pull(); err != nil {
|
||||
log.Errorf("papi pull: %s", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if s.consoleConfig.ConsoleManagement != nil && *s.consoleConfig.ConsoleManagement {
|
||||
if s.papi.URL != "" {
|
||||
log.Infof("Starting PAPI decision receiver")
|
||||
s.papi.pullTomb.Go(func() error {
|
||||
if err := s.papi.Pull(); err != nil {
|
||||
log.Errorf("papi pull: %s", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
s.papi.syncTomb.Go(func() error {
|
||||
if err := s.papi.SyncDecisions(); err != nil {
|
||||
log.Errorf("capi decisions sync: %s", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
s.papi.syncTomb.Go(func() error {
|
||||
if err := s.papi.SyncDecisions(); err != nil {
|
||||
log.Errorf("capi decisions sync: %s", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
} else {
|
||||
log.Warnf("papi_url is not set in online_api_credentials.yaml, can't synchronize with the console. Run cscli console enable console_management to add it.")
|
||||
}
|
||||
} else {
|
||||
log.Warningf("Machine is not allowed to synchronize decisions, you can enable it with `cscli console enable console_management`")
|
||||
}
|
||||
|
|
|
@ -293,7 +293,7 @@ func (p *Papi) SyncDecisions() error {
|
|||
go p.SendDeletedDecisions(&cacheCopy)
|
||||
}
|
||||
case deletedDecisions := <-p.Channels.DeleteDecisionChannel:
|
||||
if (p.consoleConfig.ShareManualDecisions != nil && *p.consoleConfig.ShareManualDecisions) || (p.consoleConfig.ReceiveDecisions != nil && *p.consoleConfig.ReceiveDecisions) {
|
||||
if (p.consoleConfig.ShareManualDecisions != nil && *p.consoleConfig.ShareManualDecisions) || (p.consoleConfig.ConsoleManagement != nil && *p.consoleConfig.ConsoleManagement) {
|
||||
var tmpDecisions []models.DecisionsDeleteRequestItem
|
||||
p.Logger.Debugf("%d decisions deletion to add in cache", len(deletedDecisions))
|
||||
for _, decision := range deletedDecisions {
|
||||
|
|
|
@ -202,7 +202,7 @@ func TestLoadAPIServer(t *testing.T) {
|
|||
ShareTaintedScenarios: types.BoolPtr(true),
|
||||
ShareCustomScenarios: types.BoolPtr(true),
|
||||
ShareContext: types.BoolPtr(false),
|
||||
ReceiveDecisions: types.BoolPtr(false),
|
||||
ConsoleManagement: types.BoolPtr(false),
|
||||
},
|
||||
LogDir: LogDirFullPath,
|
||||
LogMedia: "stdout",
|
||||
|
|
|
@ -27,7 +27,7 @@ type ConsoleConfig struct {
|
|||
ShareManualDecisions *bool `yaml:"share_manual_decisions"`
|
||||
ShareTaintedScenarios *bool `yaml:"share_tainted"`
|
||||
ShareCustomScenarios *bool `yaml:"share_custom"`
|
||||
ReceiveDecisions *bool `yaml:"console_management"`
|
||||
ConsoleManagement *bool `yaml:"console_management"`
|
||||
ShareContext *bool `yaml:"share_context"`
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ func (c *LocalApiServerCfg) LoadConsoleConfig() error {
|
|||
c.ConsoleConfig.ShareCustomScenarios = types.BoolPtr(true)
|
||||
c.ConsoleConfig.ShareTaintedScenarios = types.BoolPtr(true)
|
||||
c.ConsoleConfig.ShareManualDecisions = types.BoolPtr(false)
|
||||
c.ConsoleConfig.ReceiveDecisions = types.BoolPtr(false)
|
||||
c.ConsoleConfig.ConsoleManagement = types.BoolPtr(false)
|
||||
c.ConsoleConfig.ShareContext = types.BoolPtr(false)
|
||||
return nil
|
||||
}
|
||||
|
@ -66,10 +66,10 @@ func (c *LocalApiServerCfg) LoadConsoleConfig() error {
|
|||
}
|
||||
|
||||
if !fflag.PapiClient.IsEnabled() {
|
||||
c.ConsoleConfig.ReceiveDecisions = types.BoolPtr(false)
|
||||
} else if c.ConsoleConfig.ReceiveDecisions == nil {
|
||||
c.ConsoleConfig.ConsoleManagement = types.BoolPtr(false)
|
||||
} else if c.ConsoleConfig.ConsoleManagement == nil {
|
||||
log.Debugf("no console_management found, setting to false")
|
||||
c.ConsoleConfig.ReceiveDecisions = types.BoolPtr(false)
|
||||
c.ConsoleConfig.ConsoleManagement = types.BoolPtr(false)
|
||||
}
|
||||
|
||||
if c.ConsoleConfig.ShareContext == nil {
|
||||
|
|
Loading…
Add table
Reference in a new issue