diff --git a/cmd/crowdsec-cli/cliconfig/show.go b/cmd/crowdsec-cli/cliconfig/show.go index cff214e49..a9cf96cbb 100644 --- a/cmd/crowdsec-cli/cliconfig/show.go +++ b/cmd/crowdsec-cli/cliconfig/show.go @@ -67,6 +67,7 @@ func (cli *cliConfig) template() string { - Configuration Folder : {{.ConfigPaths.ConfigDir}} - Data Folder : {{.ConfigPaths.DataDir}} - Hub Folder : {{.ConfigPaths.HubDir}} + - Notification Folder : {{.ConfigPaths.NotificationDir}} - Simulation File : {{.ConfigPaths.SimulationFilePath}} {{- end }} diff --git a/cmd/crowdsec-cli/clinotifications/notifications.go b/cmd/crowdsec-cli/clinotifications/notifications.go index 7856c89ff..7be2f3a66 100644 --- a/cmd/crowdsec-cli/clinotifications/notifications.go +++ b/cmd/crowdsec-cli/clinotifications/notifications.go @@ -70,7 +70,7 @@ func (cli *cliNotifications) NewCommand() *cobra.Command { return fmt.Errorf("loading api client: %w", err) } - return require.Notifications(cfg) + return nil }, } diff --git a/cmd/crowdsec-cli/require/require.go b/cmd/crowdsec-cli/require/require.go index beffa29f3..098218263 100644 --- a/cmd/crowdsec-cli/require/require.go +++ b/cmd/crowdsec-cli/require/require.go @@ -74,14 +74,6 @@ func DB(c *csconfig.Config) error { return nil } -func Notifications(c *csconfig.Config) error { - if c.ConfigPaths.NotificationDir == "" { - return errors.New("config_paths.notification_dir is not set in crowdsec config") - } - - return nil -} - func HubDownloader(ctx context.Context, c *csconfig.Config) *cwhub.Downloader { // set branch in config, and log if necessary branch := HubBranch(ctx, c) diff --git a/cmd/crowdsec/api.go b/cmd/crowdsec/api.go index ccb0acf02..1b14d2f69 100644 --- a/cmd/crowdsec/api.go +++ b/cmd/crowdsec/api.go @@ -32,10 +32,6 @@ func initAPIServer(ctx context.Context, cConfig *csconfig.Config) (*apiserver.AP return nil, errors.New("plugins are enabled, but the plugin_config section is missing in the configuration") } - if cConfig.ConfigPaths.NotificationDir == "" { - return nil, errors.New("plugins are enabled, but config_paths.notification_dir is not defined") - } - if cConfig.ConfigPaths.PluginDir == "" { return nil, errors.New("plugins are enabled, but config_paths.plugin_dir is not defined") } diff --git a/pkg/csconfig/config_paths.go b/pkg/csconfig/config_paths.go index a8d39a664..cc372db2a 100644 --- a/pkg/csconfig/config_paths.go +++ b/pkg/csconfig/config_paths.go @@ -23,6 +23,10 @@ func (c *Config) loadConfigurationPaths() error { return errors.New("no configuration paths provided") } + if c.ConfigPaths.ConfigDir == "" { + c.ConfigPaths.ConfigDir = filepath.Dir(c.FilePath) + } + if c.ConfigPaths.DataDir == "" { return errors.New("please provide a data directory with the 'data_dir' directive in the 'config_paths' section") } @@ -35,6 +39,10 @@ func (c *Config) loadConfigurationPaths() error { c.ConfigPaths.HubIndexFile = filepath.Join(c.ConfigPaths.HubDir, ".index.json") } + if c.ConfigPaths.NotificationDir == "" { + c.ConfigPaths.NotificationDir = filepath.Join(c.ConfigPaths.ConfigDir, "notifications") + } + if c.ConfigPaths.PatternDir == "" { c.ConfigPaths.PatternDir = filepath.Join(c.ConfigPaths.ConfigDir, "patterns") } diff --git a/test/bats/01_cscli.bats b/test/bats/01_cscli.bats index 77c128568..df4ece8d7 100644 --- a/test/bats/01_cscli.bats +++ b/test/bats/01_cscli.bats @@ -147,6 +147,11 @@ teardown() { # defaults + config_set 'del(.config_paths.config_dir)' + rune -0 cscli config show --key Config.ConfigPaths.ConfigDir + assert_output "$configdir" + echo "$config" > "$CONFIG_YAML" + config_set 'del(.config_paths.hub_dir)' rune -0 cscli hub list rune -0 cscli config show --key Config.ConfigPaths.HubDir diff --git a/test/bats/72_plugin_badconfig.bats b/test/bats/72_plugin_badconfig.bats index 216b29f4d..4f0294b23 100644 --- a/test/bats/72_plugin_badconfig.bats +++ b/test/bats/72_plugin_badconfig.bats @@ -12,6 +12,9 @@ setup_file() { PROFILES_PATH=$(config_get '.api.server.profiles_path') export PROFILES_PATH + + CONFIG_DIR=$(dirname "$CONFIG_YAML") + export CONFIG_DIR } teardown_file() { @@ -110,10 +113,8 @@ teardown() { @test "config.yaml: missing config_paths.notification_dir" { config_set 'del(.config_paths.notification_dir)' - config_set "$PROFILES_PATH" '.notifications=["http_default"]' - rune -0 wait-for \ - --err "api server init: plugins are enabled, but config_paths.notification_dir is not defined" \ - "$CROWDSEC" + rune -0 cscli config show --key Config.ConfigPaths.NotificationDir + assert_output "$CONFIG_DIR/notifications" } @test "config.yaml: missing config_paths.plugin_dir" {