Fix cscli notifications list crash (#1697)

This commit is contained in:
blotus 2022-08-02 20:44:19 +02:00 committed by GitHub
parent c742242094
commit dacf6ebc64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,6 +37,9 @@ func NewNotificationsCmd() *cobra.Command {
if err = csConfig.API.Server.LoadProfiles(); err != nil {
log.Fatalf(err.Error())
}
if csConfig.ConfigPaths.NotificationDir == "" {
log.Fatalf("config_paths.notification_dir is not set in crowdsec config")
}
},
}
@ -141,6 +144,9 @@ func NewNotificationsCmd() *cobra.Command {
func getNotificationsConfiguration() map[string]NotificationsCfg {
pcfgs := map[string]csplugin.PluginConfig{}
wf := func(path string, info fs.FileInfo, err error) error {
if info == nil {
return errors.Wrapf(err, "error while traversing directory %s", path)
}
name := filepath.Join(csConfig.ConfigPaths.NotificationDir, info.Name()) //Avoid calling info.Name() twice
if (strings.HasSuffix(name, "yaml") || strings.HasSuffix(name, "yml")) && !(info.IsDir()) {
ts, err := csplugin.ParsePluginConfigFile(name)
@ -153,6 +159,7 @@ func getNotificationsConfiguration() map[string]NotificationsCfg {
}
return nil
}
if err := filepath.Walk(csConfig.ConfigPaths.NotificationDir, wf); err != nil {
log.Fatalf("Loading notifification plugin configuration: %s", err)
}