Fix cscli notifications list
crash (#1697)
This commit is contained in:
parent
c742242094
commit
dacf6ebc64
1 changed files with 7 additions and 0 deletions
|
@ -37,6 +37,9 @@ func NewNotificationsCmd() *cobra.Command {
|
||||||
if err = csConfig.API.Server.LoadProfiles(); err != nil {
|
if err = csConfig.API.Server.LoadProfiles(); err != nil {
|
||||||
log.Fatalf(err.Error())
|
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 {
|
func getNotificationsConfiguration() map[string]NotificationsCfg {
|
||||||
pcfgs := map[string]csplugin.PluginConfig{}
|
pcfgs := map[string]csplugin.PluginConfig{}
|
||||||
wf := func(path string, info fs.FileInfo, err error) error {
|
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
|
name := filepath.Join(csConfig.ConfigPaths.NotificationDir, info.Name()) //Avoid calling info.Name() twice
|
||||||
if (strings.HasSuffix(name, "yaml") || strings.HasSuffix(name, "yml")) && !(info.IsDir()) {
|
if (strings.HasSuffix(name, "yaml") || strings.HasSuffix(name, "yml")) && !(info.IsDir()) {
|
||||||
ts, err := csplugin.ParsePluginConfigFile(name)
|
ts, err := csplugin.ParsePluginConfigFile(name)
|
||||||
|
@ -153,6 +159,7 @@ func getNotificationsConfiguration() map[string]NotificationsCfg {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := filepath.Walk(csConfig.ConfigPaths.NotificationDir, wf); err != nil {
|
if err := filepath.Walk(csConfig.ConfigPaths.NotificationDir, wf); err != nil {
|
||||||
log.Fatalf("Loading notifification plugin configuration: %s", err)
|
log.Fatalf("Loading notifification plugin configuration: %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue