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