From 6507e8f4cd2066aebc2d1556ab7a29ad7c16deb2 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Tue, 30 Jan 2024 11:07:53 +0100 Subject: [PATCH] cscli: don't print use_wal warning (#2794) --- cmd/crowdsec-cli/require/require.go | 4 ++-- cmd/crowdsec-cli/support.go | 2 +- cmd/crowdsec-cli/utils.go | 2 +- cmd/crowdsec/main.go | 2 +- pkg/csconfig/api.go | 4 ++-- pkg/csconfig/api_test.go | 2 +- pkg/csconfig/database.go | 8 +++----- pkg/csconfig/database_test.go | 2 +- 8 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cmd/crowdsec-cli/require/require.go b/cmd/crowdsec-cli/require/require.go index 0ab5b58971e..0f5ce182d9a 100644 --- a/cmd/crowdsec-cli/require/require.go +++ b/cmd/crowdsec-cli/require/require.go @@ -11,7 +11,7 @@ import ( ) func LAPI(c *csconfig.Config) error { - if err := c.LoadAPIServer(); err != nil { + if err := c.LoadAPIServer(true); err != nil { return fmt.Errorf("failed to load Local API: %w", err) } @@ -47,7 +47,7 @@ func CAPIRegistered(c *csconfig.Config) error { } func DB(c *csconfig.Config) error { - if err := c.LoadDBConfig(); err != nil { + if err := c.LoadDBConfig(true); err != nil { return fmt.Errorf("this command requires direct database access (must be run on the local API machine): %w", err) } diff --git a/cmd/crowdsec-cli/support.go b/cmd/crowdsec-cli/support.go index 40b73e04769..99194e550c7 100644 --- a/cmd/crowdsec-cli/support.go +++ b/cmd/crowdsec-cli/support.go @@ -305,7 +305,7 @@ cscli support dump -f /tmp/crowdsec-support.zip infos[SUPPORT_AGENTS_PATH] = []byte(err.Error()) } - if err := csConfig.LoadAPIServer(); err != nil { + if err := csConfig.LoadAPIServer(true); err != nil { log.Warnf("could not load LAPI, skipping CAPI check") skipLAPI = true infos[SUPPORT_CAPI_STATUS_PATH] = []byte(err.Error()) diff --git a/cmd/crowdsec-cli/utils.go b/cmd/crowdsec-cli/utils.go index 362a8942f71..d9a3a393289 100644 --- a/cmd/crowdsec-cli/utils.go +++ b/cmd/crowdsec-cli/utils.go @@ -48,7 +48,7 @@ func manageCliDecisionAlerts(ip *string, ipRange *string, scope *string, value * } func getDBClient() (*database.Client, error) { - if err := csConfig.LoadAPIServer(); err != nil || csConfig.DisableAPI { + if err := csConfig.LoadAPIServer(true); err != nil || csConfig.DisableAPI { return nil, err } ret, err := database.NewClient(csConfig.DbConfig) diff --git a/cmd/crowdsec/main.go b/cmd/crowdsec/main.go index bdb04023e0b..2040141bb3e 100644 --- a/cmd/crowdsec/main.go +++ b/cmd/crowdsec/main.go @@ -262,7 +262,7 @@ func LoadConfig(configFile string, disableAgent bool, disableAPI bool, quiet boo } if !cConfig.DisableAPI { - if err := cConfig.LoadAPIServer(); err != nil { + if err := cConfig.LoadAPIServer(false); err != nil { return nil, err } } diff --git a/pkg/csconfig/api.go b/pkg/csconfig/api.go index 06b3d382826..d8e7c77a56c 100644 --- a/pkg/csconfig/api.go +++ b/pkg/csconfig/api.go @@ -236,7 +236,7 @@ type LocalApiServerCfg struct { CapiWhitelists *CapiWhitelist `yaml:"-"` } -func (c *Config) LoadAPIServer() error { +func (c *Config) LoadAPIServer(inCli bool) error { if c.DisableAPI { log.Warning("crowdsec local API is disabled from flag") } @@ -289,7 +289,7 @@ func (c *Config) LoadAPIServer() error { log.Printf("push and pull to Central API disabled") } - if err := c.LoadDBConfig(); err != nil { + if err := c.LoadDBConfig(inCli); err != nil { return err } diff --git a/pkg/csconfig/api_test.go b/pkg/csconfig/api_test.go index e1e24e2be34..e22c78204e7 100644 --- a/pkg/csconfig/api_test.go +++ b/pkg/csconfig/api_test.go @@ -240,7 +240,7 @@ func TestLoadAPIServer(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - err := tc.input.LoadAPIServer() + err := tc.input.LoadAPIServer(false) cstest.RequireErrorContains(t, err, tc.expectedErr) if tc.expectedErr != "" { return diff --git a/pkg/csconfig/database.go b/pkg/csconfig/database.go index 4d041c312b1..5149b4ae39e 100644 --- a/pkg/csconfig/database.go +++ b/pkg/csconfig/database.go @@ -50,7 +50,7 @@ type FlushDBCfg struct { AgentsGC *AuthGCCfg `yaml:"agents_autodelete,omitempty"` } -func (c *Config) LoadDBConfig() error { +func (c *Config) LoadDBConfig(inCli bool) error { if c.DbConfig == nil { return fmt.Errorf("no database configuration provided") } @@ -77,10 +77,8 @@ func (c *Config) LoadDBConfig() error { c.DbConfig.DecisionBulkSize = maxDecisionBulkSize } - if c.DbConfig.Type == "sqlite" { - if c.DbConfig.UseWal == nil { - log.Warning("You are using sqlite without WAL, this can have a performance impact. If you do not store the database in a network share, set db_config.use_wal to true. Set explicitly to false to disable this warning.") - } + if !inCli && c.DbConfig.Type == "sqlite" && c.DbConfig.UseWal == nil { + log.Warning("You are using sqlite without WAL, this can have a performance impact. If you do not store the database in a network share, set db_config.use_wal to true. Set explicitly to false to disable this warning.") } return nil diff --git a/pkg/csconfig/database_test.go b/pkg/csconfig/database_test.go index 631e63ae2eb..a946025799d 100644 --- a/pkg/csconfig/database_test.go +++ b/pkg/csconfig/database_test.go @@ -47,7 +47,7 @@ func TestLoadDBConfig(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - err := tc.input.LoadDBConfig() + err := tc.input.LoadDBConfig(false) cstest.RequireErrorContains(t, err, tc.expectedErr) if tc.expectedErr != "" { return