add info message when there is no hub index (#492)

This commit is contained in:
erenJag 2020-12-01 12:33:14 +01:00 committed by GitHub
parent 0be78d4cbf
commit a16fb1475d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 41 additions and 16 deletions

View file

@ -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 {

View file

@ -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)
},

View file

@ -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)

View file

@ -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()

View file

@ -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 {

View file

@ -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)
},

View file

@ -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)
},

View file

@ -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)
},

View file

@ -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 {

View file

@ -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 {