Skip to content

Commit

Permalink
cscli: don't print use_wal warning (crowdsecurity#2794)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc authored Jan 30, 2024
1 parent 66544ba commit 6507e8f
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/require/require.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/csconfig/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/csconfig/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions pkg/csconfig/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/csconfig/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6507e8f

Please sign in to comment.