From a16fb1475d5aa7fed82fafbeaab32c7077a21193 Mon Sep 17 00:00:00 2001 From: erenJag <64777133+erenJag@users.noreply.github.com> Date: Tue, 1 Dec 2020 12:33:14 +0100 Subject: [PATCH] add info message when there is no hub index (#492) --- cmd/crowdsec-cli/capi.go | 1 + cmd/crowdsec-cli/collections.go | 11 ++++++++--- cmd/crowdsec-cli/config.go | 6 ++++-- cmd/crowdsec-cli/hub.go | 1 + cmd/crowdsec-cli/lapi.go | 1 + cmd/crowdsec-cli/parsers.go | 11 ++++++++--- cmd/crowdsec-cli/postoverflows.go | 11 ++++++++--- cmd/crowdsec-cli/scenarios.go | 11 ++++++++--- cmd/crowdsec-cli/simulation.go | 3 ++- pkg/cwhub/loader.go | 1 - 10 files changed, 41 insertions(+), 16 deletions(-) diff --git a/cmd/crowdsec-cli/capi.go b/cmd/crowdsec-cli/capi.go index 7e7bc85ed..25aa212d3 100644 --- a/cmd/crowdsec-cli/capi.go +++ b/cmd/crowdsec-cli/capi.go @@ -126,6 +126,7 @@ func NewCapiCmd() *cobra.Command { } if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { log.Fatalf("Failed to load hub index : %s", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } scenarios, err := cwhub.GetUpstreamInstalledScenariosAsString() if err != nil { diff --git a/cmd/crowdsec-cli/collections.go b/cmd/crowdsec-cli/collections.go index 409b831d3..52a1b3ec3 100644 --- a/cmd/crowdsec-cli/collections.go +++ b/cmd/crowdsec-cli/collections.go @@ -43,7 +43,8 @@ func NewCollectionsCmd() *cobra.Command { Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } for _, name := range args { InstallItem(name, cwhub.COLLECTIONS, forceInstall) @@ -63,6 +64,7 @@ func NewCollectionsCmd() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } if removeAll { @@ -87,6 +89,7 @@ func NewCollectionsCmd() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } if upgradeAll { UpgradeConfig(cwhub.COLLECTIONS, "", forceUpgrade) @@ -109,7 +112,8 @@ func NewCollectionsCmd() *cobra.Command { Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } for _, name := range args { InspectItem(name, cwhub.COLLECTIONS) @@ -127,7 +131,8 @@ func NewCollectionsCmd() *cobra.Command { Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } ListItem(cwhub.COLLECTIONS, args) }, diff --git a/cmd/crowdsec-cli/config.go b/cmd/crowdsec-cli/config.go index f383ba9c0..46490f6ef 100644 --- a/cmd/crowdsec-cli/config.go +++ b/cmd/crowdsec-cli/config.go @@ -297,7 +297,8 @@ func NewConfigCmd() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { var err error if err = cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } if err = backupConfigToDirectory(args[0]); err != nil { log.Fatalf("Failed to backup configurations: %s", err) @@ -321,7 +322,8 @@ func NewConfigCmd() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { var err error if err = cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } if err := restoreConfigFromDirectory(args[0]); err != nil { log.Fatalf("failed restoring configurations from %s : %s", args[0], err) diff --git a/cmd/crowdsec-cli/hub.go b/cmd/crowdsec-cli/hub.go index e680dfe48..e3a0d14fc 100644 --- a/cmd/crowdsec-cli/hub.go +++ b/cmd/crowdsec-cli/hub.go @@ -42,6 +42,7 @@ cscli hub update # Download list of available configurations from the hub Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } cwhub.DisplaySummary() diff --git a/cmd/crowdsec-cli/lapi.go b/cmd/crowdsec-cli/lapi.go index 81f158e8c..cb8bbffa0 100644 --- a/cmd/crowdsec-cli/lapi.go +++ b/cmd/crowdsec-cli/lapi.go @@ -129,6 +129,7 @@ Keep in mind the machine needs to be validated by an administrator on LAPI side } if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { log.Fatalf("Failed to load hub index : %s", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } scenarios, err := cwhub.GetUpstreamInstalledScenariosAsString() if err != nil { diff --git a/cmd/crowdsec-cli/parsers.go b/cmd/crowdsec-cli/parsers.go index 4ca87adf9..1c9a523c6 100644 --- a/cmd/crowdsec-cli/parsers.go +++ b/cmd/crowdsec-cli/parsers.go @@ -47,7 +47,8 @@ cscli parsers remove crowdsecurity/sshd-logs Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } for _, name := range args { InstallItem(name, cwhub.PARSERS, forceInstall) @@ -67,6 +68,7 @@ cscli parsers remove crowdsecurity/sshd-logs Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } if removeAll { @@ -91,6 +93,7 @@ cscli parsers remove crowdsecurity/sshd-logs Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } if upgradeAll { UpgradeConfig(cwhub.PARSERS, "", forceUpgrade) @@ -113,7 +116,8 @@ cscli parsers remove crowdsecurity/sshd-logs Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } InspectItem(args[0], cwhub.PARSERS) }, @@ -129,7 +133,8 @@ cscli parsers remove crowdsecurity/sshd-logs cscli parser list crowdsecurity/xxx`, Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } ListItem(cwhub.PARSERS, args) }, diff --git a/cmd/crowdsec-cli/postoverflows.go b/cmd/crowdsec-cli/postoverflows.go index 016012861..0a2fbe595 100644 --- a/cmd/crowdsec-cli/postoverflows.go +++ b/cmd/crowdsec-cli/postoverflows.go @@ -46,7 +46,8 @@ func NewPostOverflowsCmd() *cobra.Command { Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } for _, name := range args { InstallItem(name, cwhub.PARSERS_OVFLW, forceInstall) @@ -66,6 +67,7 @@ func NewPostOverflowsCmd() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } if removeAll { @@ -90,6 +92,7 @@ func NewPostOverflowsCmd() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } if upgradeAll { UpgradeConfig(cwhub.PARSERS_OVFLW, "", forceUpgrade) @@ -112,7 +115,8 @@ func NewPostOverflowsCmd() *cobra.Command { Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } InspectItem(args[0], cwhub.PARSERS_OVFLW) }, @@ -127,7 +131,8 @@ func NewPostOverflowsCmd() *cobra.Command { cscli postoverflows list crowdsecurity/xxx`, Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } ListItem(cwhub.PARSERS_OVFLW, args) }, diff --git a/cmd/crowdsec-cli/scenarios.go b/cmd/crowdsec-cli/scenarios.go index 33f92f382..85685e634 100644 --- a/cmd/crowdsec-cli/scenarios.go +++ b/cmd/crowdsec-cli/scenarios.go @@ -47,7 +47,8 @@ cscli scenarios remove crowdsecurity/ssh-bf Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } for _, name := range args { InstallItem(name, cwhub.SCENARIOS, forceInstall) @@ -67,6 +68,7 @@ cscli scenarios remove crowdsecurity/ssh-bf Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } if removeAll { @@ -91,6 +93,7 @@ cscli scenarios remove crowdsecurity/ssh-bf Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } if upgradeAll { UpgradeConfig(cwhub.SCENARIOS, "", forceUpgrade) @@ -113,7 +116,8 @@ cscli scenarios remove crowdsecurity/ssh-bf Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } InspectItem(args[0], cwhub.SCENARIOS) }, @@ -129,7 +133,8 @@ cscli scenarios remove crowdsecurity/ssh-bf cscli scenarios list crowdsecurity/xxx`, Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } ListItem(cwhub.SCENARIOS, args) }, diff --git a/cmd/crowdsec-cli/simulation.go b/cmd/crowdsec-cli/simulation.go index a6339212c..158af38bb 100644 --- a/cmd/crowdsec-cli/simulation.go +++ b/cmd/crowdsec-cli/simulation.go @@ -126,7 +126,8 @@ cscli simulation disable crowdsecurity/ssh-bf`, Example: `cscli simulation enable`, Run: func(cmd *cobra.Command, args []string) { if err := cwhub.GetHubIdx(csConfig.Cscli); err != nil { - log.Fatalf("failed to get Hub index : %v", err) + log.Fatalf("Failed to get Hub index : %v", err) + log.Infoln("Run 'sudo cscli hub update' to get the hub index") } if len(args) > 0 { diff --git a/pkg/cwhub/loader.go b/pkg/cwhub/loader.go index ff605bc63..93108d1d0 100644 --- a/pkg/cwhub/loader.go +++ b/pkg/cwhub/loader.go @@ -342,7 +342,6 @@ func GetHubIdx(cscli *csconfig.CscliCfg) error { bidx, err := ioutil.ReadFile(cscli.HubIndexFile) if err != nil { return errors.Wrap(err, "unable to read index file") - log.Fatalf("Unable to read downloaded index : %v. Please run update", err) } ret, err := LoadPkgIndex(bidx) if err != nil {