|
@@ -10,6 +10,54 @@ import (
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
|
|
)
|
|
|
|
|
|
+func NewPostOverflowsCmd() *cobra.Command {
|
|
|
+ cmdPostOverflows := &cobra.Command{
|
|
|
+ Use: "postoverflows [action] [config]",
|
|
|
+ Short: "Install/Remove/Upgrade/Inspect postoverflow(s) from hub",
|
|
|
+ Example: `cscli postoverflows install crowdsecurity/cdn-whitelist
|
|
|
+ cscli postoverflows inspect crowdsecurity/cdn-whitelist
|
|
|
+ cscli postoverflows upgrade crowdsecurity/cdn-whitelist
|
|
|
+ cscli postoverflows list
|
|
|
+ cscli postoverflows remove crowdsecurity/cdn-whitelist`,
|
|
|
+ Args: cobra.MinimumNArgs(1),
|
|
|
+ Aliases: []string{"postoverflow"},
|
|
|
+ DisableAutoGenTag: true,
|
|
|
+ PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
|
+ if err := csConfig.LoadHub(); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if csConfig.Hub == nil {
|
|
|
+ return fmt.Errorf("you must configure cli before interacting with hub")
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := cwhub.SetHubBranch(); err != nil {
|
|
|
+ return fmt.Errorf("while setting hub branch: %w", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := cwhub.GetHubIdx(csConfig.Hub); err != nil {
|
|
|
+ log.Info("Run 'sudo cscli hub update' to get the hub index")
|
|
|
+ return fmt.Errorf("failed to get hub index: %w", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+ },
|
|
|
+ PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
|
|
+ if cmd.Name() == "inspect" || cmd.Name() == "list" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ log.Infof(ReloadMessage())
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ cmdPostOverflows.AddCommand(NewPostOverflowsInstallCmd())
|
|
|
+ cmdPostOverflows.AddCommand(NewPostOverflowsRemoveCmd())
|
|
|
+ cmdPostOverflows.AddCommand(NewPostOverflowsUpgradeCmd())
|
|
|
+ cmdPostOverflows.AddCommand(NewPostOverflowsInspectCmd())
|
|
|
+ cmdPostOverflows.AddCommand(NewPostOverflowsListCmd())
|
|
|
+
|
|
|
+ return cmdPostOverflows
|
|
|
+}
|
|
|
+
|
|
|
func NewPostOverflowsInstallCmd() *cobra.Command {
|
|
|
var ignoreError bool
|
|
|
|
|
@@ -23,7 +71,7 @@ func NewPostOverflowsInstallCmd() *cobra.Command {
|
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
return compAllItems(cwhub.PARSERS_OVFLW, args, toComplete)
|
|
|
},
|
|
|
- Run: func(cmd *cobra.Command, args []string) {
|
|
|
+ RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
for _, name := range args {
|
|
|
t := cwhub.GetItem(cwhub.PARSERS_OVFLW, name)
|
|
|
if t == nil {
|
|
@@ -32,13 +80,13 @@ func NewPostOverflowsInstallCmd() *cobra.Command {
|
|
|
continue
|
|
|
}
|
|
|
if err := cwhub.InstallItem(csConfig, name, cwhub.PARSERS_OVFLW, forceAction, downloadOnly); err != nil {
|
|
|
- if ignoreError {
|
|
|
- log.Errorf("Error while installing '%s': %s", name, err)
|
|
|
- } else {
|
|
|
- log.Fatalf("Error while installing '%s': %s", name, err)
|
|
|
+ if !ignoreError {
|
|
|
+ return fmt.Errorf("error while installing '%s': %w", name, err)
|
|
|
}
|
|
|
+ log.Errorf("Error while installing '%s': %s", name, err)
|
|
|
}
|
|
|
}
|
|
|
+ return nil
|
|
|
},
|
|
|
}
|
|
|
|
|
@@ -55,24 +103,26 @@ func NewPostOverflowsRemoveCmd() *cobra.Command {
|
|
|
Short: "Remove given postoverflow(s)",
|
|
|
Long: `remove given postoverflow(s)`,
|
|
|
Example: `cscli postoverflows remove crowdsec/xxx crowdsec/xyz`,
|
|
|
- DisableAutoGenTag: true,
|
|
|
Aliases: []string{"delete"},
|
|
|
+ DisableAutoGenTag: true,
|
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
return compInstalledItems(cwhub.PARSERS_OVFLW, args, toComplete)
|
|
|
},
|
|
|
- Run: func(cmd *cobra.Command, args []string) {
|
|
|
+ RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
if all {
|
|
|
cwhub.RemoveMany(csConfig, cwhub.PARSERS_OVFLW, "", all, purge, forceAction)
|
|
|
- return
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
if len(args) == 0 {
|
|
|
- log.Fatalf("Specify at least one postoverflow to remove or '--all' flag.")
|
|
|
+ return fmt.Errorf("specify at least one postoverflow to remove or '--all'")
|
|
|
}
|
|
|
|
|
|
for _, name := range args {
|
|
|
cwhub.RemoveMany(csConfig, cwhub.PARSERS_OVFLW, name, all, purge, forceAction)
|
|
|
}
|
|
|
+
|
|
|
+ return nil
|
|
|
},
|
|
|
}
|
|
|
|
|
@@ -93,17 +143,18 @@ func NewPostOverflowsUpgradeCmd() *cobra.Command {
|
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
return compInstalledItems(cwhub.PARSERS_OVFLW, args, toComplete)
|
|
|
},
|
|
|
- Run: func(cmd *cobra.Command, args []string) {
|
|
|
+ RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
if all {
|
|
|
cwhub.UpgradeConfig(csConfig, cwhub.PARSERS_OVFLW, "", forceAction)
|
|
|
} else {
|
|
|
if len(args) == 0 {
|
|
|
- log.Fatalf("no target postoverflow to upgrade")
|
|
|
+ return fmt.Errorf("specify at least one postoverflow to upgrade or '--all'")
|
|
|
}
|
|
|
for _, name := range args {
|
|
|
cwhub.UpgradeConfig(csConfig, cwhub.PARSERS_OVFLW, name, forceAction)
|
|
|
}
|
|
|
}
|
|
|
+ return nil
|
|
|
},
|
|
|
}
|
|
|
|
|
@@ -120,10 +171,10 @@ func NewPostOverflowsInspectCmd() *cobra.Command {
|
|
|
Long: `Inspect given postoverflow`,
|
|
|
Example: `cscli postoverflows inspect crowdsec/xxx crowdsec/xyz`,
|
|
|
DisableAutoGenTag: true,
|
|
|
+ Args: cobra.MinimumNArgs(1),
|
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
return compInstalledItems(cwhub.PARSERS_OVFLW, args, toComplete)
|
|
|
},
|
|
|
- Args: cobra.MinimumNArgs(1),
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
InspectItem(args[0], cwhub.PARSERS_OVFLW)
|
|
|
},
|
|
@@ -149,52 +200,3 @@ cscli postoverflows list crowdsecurity/xxx`,
|
|
|
|
|
|
return cmdPostOverflowsList
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-func NewPostOverflowsCmd() *cobra.Command {
|
|
|
- cmdPostOverflows := &cobra.Command{
|
|
|
- Use: "postoverflows [action] [config]",
|
|
|
- Short: "Install/Remove/Upgrade/Inspect postoverflow(s) from hub",
|
|
|
- Example: `cscli postoverflows install crowdsecurity/cdn-whitelist
|
|
|
- cscli postoverflows inspect crowdsecurity/cdn-whitelist
|
|
|
- cscli postoverflows upgrade crowdsecurity/cdn-whitelist
|
|
|
- cscli postoverflows list
|
|
|
- cscli postoverflows remove crowdsecurity/cdn-whitelist`,
|
|
|
- Args: cobra.MinimumNArgs(1),
|
|
|
- Aliases: []string{"postoverflow"},
|
|
|
- DisableAutoGenTag: true,
|
|
|
- PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
|
- if err := csConfig.LoadHub(); err != nil {
|
|
|
- log.Fatal(err)
|
|
|
- }
|
|
|
- if csConfig.Hub == nil {
|
|
|
- return fmt.Errorf("you must configure cli before interacting with hub")
|
|
|
- }
|
|
|
-
|
|
|
- if err := cwhub.SetHubBranch(); err != nil {
|
|
|
- return fmt.Errorf("error while setting hub branch: %s", err)
|
|
|
- }
|
|
|
-
|
|
|
- if err := cwhub.GetHubIdx(csConfig.Hub); err != nil {
|
|
|
- log.Info("Run 'sudo cscli hub update' to get the hub index")
|
|
|
- log.Fatalf("Failed to get Hub index : %v", err)
|
|
|
- }
|
|
|
- return nil
|
|
|
- },
|
|
|
- PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
|
|
- if cmd.Name() == "inspect" || cmd.Name() == "list" {
|
|
|
- return
|
|
|
- }
|
|
|
- log.Infof(ReloadMessage())
|
|
|
- },
|
|
|
- }
|
|
|
-
|
|
|
- cmdPostOverflows.AddCommand(NewPostOverflowsInstallCmd())
|
|
|
- cmdPostOverflows.AddCommand(NewPostOverflowsRemoveCmd())
|
|
|
- cmdPostOverflows.AddCommand(NewPostOverflowsUpgradeCmd())
|
|
|
- cmdPostOverflows.AddCommand(NewPostOverflowsInspectCmd())
|
|
|
- cmdPostOverflows.AddCommand(NewPostOverflowsListCmd())
|
|
|
-
|
|
|
- return cmdPostOverflows
|
|
|
-}
|