add support in cscli to switch branches of hub
This commit is contained in:
parent
ec81bc1f9a
commit
c9ca8ffc7b
2 changed files with 7 additions and 5 deletions
|
@ -117,7 +117,8 @@ API interaction:
|
||||||
rootCmd.PersistentFlags().BoolVar(&nfo_lvl, "info", false, "Set logging to info.")
|
rootCmd.PersistentFlags().BoolVar(&nfo_lvl, "info", false, "Set logging to info.")
|
||||||
rootCmd.PersistentFlags().BoolVar(&wrn_lvl, "warning", false, "Set logging to warning.")
|
rootCmd.PersistentFlags().BoolVar(&wrn_lvl, "warning", false, "Set logging to warning.")
|
||||||
rootCmd.PersistentFlags().BoolVar(&err_lvl, "error", false, "Set logging to error.")
|
rootCmd.PersistentFlags().BoolVar(&err_lvl, "error", false, "Set logging to error.")
|
||||||
|
rootCmd.PersistentFlags().StringVar(&cwhub.HUB_BRANCH, "branch", "master", "Override hub branch on github")
|
||||||
|
rootCmd.PersistentFlags().MarkHidden("branch")
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
/*don't sort flags so we can enforce order*/
|
/*don't sort flags so we can enforce order*/
|
||||||
rootCmd.Flags().SortFlags = false
|
rootCmd.Flags().SortFlags = false
|
||||||
|
|
|
@ -32,8 +32,9 @@ var Installdir = "/etc/crowdsec/"
|
||||||
var Hubdir = "/etc/crowdsec/cscli/hub/"
|
var Hubdir = "/etc/crowdsec/cscli/hub/"
|
||||||
var Cfgdir = "/etc/crowdsec/cscli/"
|
var Cfgdir = "/etc/crowdsec/cscli/"
|
||||||
|
|
||||||
var RawFileURLTemplate = "https://raw.githubusercontent.com/crowdsecurity/hub/master/%s"
|
var RawFileURLTemplate = "https://raw.githubusercontent.com/crowdsecurity/hub/%s/%s"
|
||||||
var HUB_INDEX_FILE = ".index.json"
|
var HUB_INDEX_FILE = ".index.json"
|
||||||
|
var HUB_BRANCH = "master"
|
||||||
|
|
||||||
type ItemVersion struct {
|
type ItemVersion struct {
|
||||||
Digest string
|
Digest string
|
||||||
|
@ -406,7 +407,7 @@ func UpdateHubIdx() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func DownloadHubIdx() ([]byte, error) {
|
func DownloadHubIdx() ([]byte, error) {
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf(RawFileURLTemplate, HUB_INDEX_FILE), nil)
|
req, err := http.NewRequest("GET", fmt.Sprintf(RawFileURLTemplate, HUB_BRANCH, HUB_INDEX_FILE), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("failed request : %s", err)
|
log.Errorf("failed request : %s", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -418,7 +419,7 @@ func DownloadHubIdx() ([]byte, error) {
|
||||||
}
|
}
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
log.Errorf("got code %d while requesting %s, abort", resp.StatusCode,
|
log.Errorf("got code %d while requesting %s, abort", resp.StatusCode,
|
||||||
fmt.Sprintf(RawFileURLTemplate, HUB_INDEX_FILE))
|
fmt.Sprintf(RawFileURLTemplate, HUB_BRANCH, HUB_INDEX_FILE))
|
||||||
return nil, fmt.Errorf("bad http code")
|
return nil, fmt.Errorf("bad http code")
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
@ -678,7 +679,7 @@ func DownloadItem(target Item, tdir string, overwrite bool, dataFolder string) (
|
||||||
}
|
}
|
||||||
|
|
||||||
//log.Infof("Downloading %s to %s", target.Name, tdir)
|
//log.Infof("Downloading %s to %s", target.Name, tdir)
|
||||||
req, err := http.NewRequest("GET", fmt.Sprintf(RawFileURLTemplate, target.RemotePath), nil)
|
req, err := http.NewRequest("GET", fmt.Sprintf(RawFileURLTemplate, HUB_BRANCH, target.RemotePath), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("%s : request creation failed : %s", target.Name, err)
|
log.Errorf("%s : request creation failed : %s", target.Name, err)
|
||||||
return target, err
|
return target, err
|
||||||
|
|
Loading…
Add table
Reference in a new issue