From 0c5d233563599fa2af5757daac67481928c3a191 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Wed, 12 Apr 2023 16:57:38 +0200 Subject: [PATCH] Minor cleanup and dead code removal (#2166) --- .gitignore | 1 - cmd/crowdsec-cli/main.go | 1 - docker/docker_start.sh | 2 +- pkg/apiserver/controllers/v1/decisions.go | 6 ------ pkg/csconfig/config.go | 2 +- pkg/csplugin/utils.go | 2 +- pkg/exprhelpers/visitor.go | 3 +-- 7 files changed, 4 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 15a5c8708..46340b9cc 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,6 @@ plugins/notifications/dummy/notification-dummy # Release stuff crowdsec-v* -pkg/cwhub/hubdir/.index.json msi *.msi **/*.nupkg diff --git a/cmd/crowdsec-cli/main.go b/cmd/crowdsec-cli/main.go index eb4b1a7a1..20872cb1b 100644 --- a/cmd/crowdsec-cli/main.go +++ b/cmd/crowdsec-cli/main.go @@ -238,7 +238,6 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall rootCmd.AddCommand(NewDashboardCmd()) rootCmd.AddCommand(NewDecisionsCmd()) rootCmd.AddCommand(NewAlertsCmd()) - // rootCmd.AddCommand(NewInspectCmd()) rootCmd.AddCommand(NewSimulationCmds()) rootCmd.AddCommand(NewBouncersCmd()) rootCmd.AddCommand(NewMachinesCmd()) diff --git a/docker/docker_start.sh b/docker/docker_start.sh index c5aa0fe31..3f9b0030a 100755 --- a/docker/docker_start.sh +++ b/docker/docker_start.sh @@ -192,7 +192,7 @@ if isfalse "$DISABLE_LOCAL_API"; then # generate local agent credentials (even if agent is disabled, cscli needs a # connection to the API) if ( isfalse "$USE_TLS" || [ "$CLIENT_CERT_FILE" = "" ] ); then - if yq -e '.login==strenv(CUSTOM_HOSTNAME)' "$lapi_credentials_path" && ( cscli machines list -o json | yq -e 'any_c(.machineId==strenv(CUSTOM_HOSTNAME))' >/dev/null ); then + if yq -e '.login==strenv(CUSTOM_HOSTNAME)' "$lapi_credentials_path" >/dev/null && ( cscli machines list -o json | yq -e 'any_c(.machineId==strenv(CUSTOM_HOSTNAME))' >/dev/null ); then echo "Local agent already registered" else echo "Generate local agent credentials" diff --git a/pkg/apiserver/controllers/v1/decisions.go b/pkg/apiserver/controllers/v1/decisions.go index 902d5384e..8ea379873 100644 --- a/pkg/apiserver/controllers/v1/decisions.go +++ b/pkg/apiserver/controllers/v1/decisions.go @@ -91,9 +91,6 @@ func (c *Controller) DeleteDecisionById(gctx *gin.Context) { } //transform deleted decisions to be sendable to capi deletedDecisions := FormatDecisions(deletedFromDB) - if err != nil { - log.Warningf("failed to format decisions: %v", err) - } if c.DecisionDeleteChan != nil { c.DecisionDeleteChan <- deletedDecisions @@ -115,9 +112,6 @@ func (c *Controller) DeleteDecisions(gctx *gin.Context) { } //transform deleted decisions to be sendable to capi deletedDecisions := FormatDecisions(deletedFromDB) - if err != nil { - log.Warningf("failed to format decisions: %v", err) - } if c.DecisionDeleteChan != nil { c.DecisionDeleteChan <- deletedDecisions diff --git a/pkg/csconfig/config.go b/pkg/csconfig/config.go index 5f37ad6f1..32f17cbf7 100644 --- a/pkg/csconfig/config.go +++ b/pkg/csconfig/config.go @@ -108,7 +108,7 @@ func NewDefaultConfig() *Config { ListenURI: "127.0.0.1:8080", UseForwardedForHeaders: false, OnlineClient: &OnlineApiClientCfg{ - CredentialsFilePath: DefaultConfigPath("config", "online-api-secrets.yaml"), + CredentialsFilePath: DefaultConfigPath("online_api_credentials.yaml"), }, }, CTI: &CTICfg{ diff --git a/pkg/csplugin/utils.go b/pkg/csplugin/utils.go index cb8104a06..67707c829 100644 --- a/pkg/csplugin/utils.go +++ b/pkg/csplugin/utils.go @@ -30,7 +30,7 @@ func (pb *PluginBroker) CreateCmd(binaryPath string) (*exec.Cmd, error) { var err error cmd := exec.Command(binaryPath) if pb.pluginProcConfig.User != "" || pb.pluginProcConfig.Group != "" { - if !(pb.pluginProcConfig.User != "" && pb.pluginProcConfig.Group != "") { + if pb.pluginProcConfig.User == "" || pb.pluginProcConfig.Group == "" { return nil, errors.New("while getting process attributes: both plugin user and group must be set") } cmd.SysProcAttr, err = getProcessAttr(pb.pluginProcConfig.User, pb.pluginProcConfig.Group) diff --git a/pkg/exprhelpers/visitor.go b/pkg/exprhelpers/visitor.go index b5bc97e7c..0dc1840f5 100644 --- a/pkg/exprhelpers/visitor.go +++ b/pkg/exprhelpers/visitor.go @@ -7,7 +7,6 @@ import ( "github.com/antonmedv/expr/parser" "github.com/google/uuid" - "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus" "github.com/antonmedv/expr" @@ -136,7 +135,7 @@ type expression struct { Run display the content of each variable of a filter by evaluating them with expr, again the expr environment given in parameter */ -func (e *ExprDebugger) Run(logger *logrus.Entry, filterResult bool, exprEnv map[string]interface{}) { +func (e *ExprDebugger) Run(logger *log.Entry, filterResult bool, exprEnv map[string]interface{}) { if len(e.expression) == 0 { logger.Tracef("no variable to eval for filter '%s'", e.filter) return