Преглед изворни кода

changes following BL tests (#2038)

Co-authored-by: Sebastien Blot <sebastien@crowdsec.net>
Thibault "bui" Koechlin пре 2 година
родитељ
комит
1d7d377f8b
3 измењених фајлова са 20 додато и 15 уклоњено
  1. 6 6
      cmd/crowdsec-cli/console.go
  2. 3 0
      pkg/apiclient/client_http.go
  3. 11 9
      pkg/apiserver/apiserver.go

+ 6 - 6
cmd/crowdsec-cli/console.go

@@ -236,12 +236,12 @@ func SetConsoleOpts(args []string, wanted bool) {
 		switch arg {
 		case csconfig.CONSOLE_MANAGEMENT:
 			if !fflag.PapiClient.IsEnabled() {
-				log.Fatalf("Feature flag %s is disabled, cannot set %s", fflag.PapiClient.Name, csconfig.CONSOLE_MANAGEMENT)
+				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 {
-					log.Infof("%s already set to %t", csconfig.CONSOLE_MANAGEMENT, 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
@@ -254,7 +254,7 @@ func SetConsoleOpts(args []string, wanted bool) {
 			/*for each flag check if it's already set before setting it*/
 			if csConfig.API.Server.ConsoleConfig.ShareCustomScenarios != nil {
 				if *csConfig.API.Server.ConsoleConfig.ShareCustomScenarios == wanted {
-					log.Infof("%s already set to %t", csconfig.SEND_CUSTOM_SCENARIOS, wanted)
+					log.Debugf("%s already set to %t", csconfig.SEND_CUSTOM_SCENARIOS, wanted)
 				} else {
 					log.Infof("%s set to %t", csconfig.SEND_CUSTOM_SCENARIOS, wanted)
 					*csConfig.API.Server.ConsoleConfig.ShareCustomScenarios = wanted
@@ -267,7 +267,7 @@ func SetConsoleOpts(args []string, wanted bool) {
 			/*for each flag check if it's already set before setting it*/
 			if csConfig.API.Server.ConsoleConfig.ShareTaintedScenarios != nil {
 				if *csConfig.API.Server.ConsoleConfig.ShareTaintedScenarios == wanted {
-					log.Infof("%s already set to %t", csconfig.SEND_TAINTED_SCENARIOS, wanted)
+					log.Debugf("%s already set to %t", csconfig.SEND_TAINTED_SCENARIOS, wanted)
 				} else {
 					log.Infof("%s set to %t", csconfig.SEND_TAINTED_SCENARIOS, wanted)
 					*csConfig.API.Server.ConsoleConfig.ShareTaintedScenarios = wanted
@@ -280,7 +280,7 @@ func SetConsoleOpts(args []string, wanted bool) {
 			/*for each flag check if it's already set before setting it*/
 			if csConfig.API.Server.ConsoleConfig.ShareManualDecisions != nil {
 				if *csConfig.API.Server.ConsoleConfig.ShareManualDecisions == wanted {
-					log.Infof("%s already set to %t", csconfig.SEND_MANUAL_SCENARIOS, wanted)
+					log.Debugf("%s already set to %t", csconfig.SEND_MANUAL_SCENARIOS, wanted)
 				} else {
 					log.Infof("%s set to %t", csconfig.SEND_MANUAL_SCENARIOS, wanted)
 					*csConfig.API.Server.ConsoleConfig.ShareManualDecisions = wanted
@@ -293,7 +293,7 @@ func SetConsoleOpts(args []string, wanted bool) {
 			/*for each flag check if it's already set before setting it*/
 			if csConfig.API.Server.ConsoleConfig.ShareContext != nil {
 				if *csConfig.API.Server.ConsoleConfig.ShareContext == wanted {
-					log.Infof("%s already set to %t", csconfig.SEND_CONTEXT, wanted)
+					log.Debugf("%s already set to %t", csconfig.SEND_CONTEXT, wanted)
 				} else {
 					log.Infof("%s set to %t", csconfig.SEND_CONTEXT, wanted)
 					*csConfig.API.Server.ConsoleConfig.ShareContext = wanted

+ 3 - 0
pkg/apiclient/client_http.go

@@ -59,6 +59,9 @@ func (c *ApiClient) Do(ctx context.Context, req *http.Request, v interface{}) (*
 		req.Header.Add("User-Agent", c.UserAgent)
 	}
 
+	if log.GetLevel() >= log.DebugLevel {
+		log.Debugf("[URL] %s %s", req.Method, req.URL)
+	}
 	resp, err := c.client.Do(req)
 	if resp != nil && resp.Body != nil {
 		defer resp.Body.Close()

+ 11 - 9
pkg/apiserver/apiserver.go

@@ -222,16 +222,18 @@ func NewServer(config *csconfig.LocalApiServerCfg) (*APIServer, error) {
 		}
 		log.Infof("CAPI manager configured successfully")
 		isMachineEnrolled = isEnrolled(apiClient.apiClient)
-		if isMachineEnrolled {
-			log.Infof("Machine is enrolled in the console, Loading PAPI Client")
-			papiClient, err = NewPAPI(apiClient, dbClient, config.ConsoleConfig, *config.PapiLogLevel)
-			if err != nil {
-				return &APIServer{}, err
+		controller.AlertsAddChan = apiClient.AlertsAddChan
+		if fflag.PapiClient.IsEnabled() {
+			if isMachineEnrolled {
+				log.Infof("Machine is enrolled in the console, Loading PAPI Client")
+				papiClient, err = NewPAPI(apiClient, dbClient, config.ConsoleConfig, *config.PapiLogLevel)
+				if err != nil {
+					return &APIServer{}, err
+				}
+				controller.DecisionDeleteChan = papiClient.Channels.DeleteDecisionChannel
+			} else {
+				log.Errorf("Machine is not enrolled in the console, can't synchronize with the console")
 			}
-			controller.DecisionDeleteChan = papiClient.Channels.DeleteDecisionChannel
-			controller.AlertsAddChan = apiClient.AlertsAddChan
-		} else {
-			log.Errorf("Machine is not enrolled in the console, can't synchronize with the console")
 		}
 	} else {
 		apiClient = nil