Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support in cscli to switch branches of hub #43

Merged
merged 3 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/crowdsec-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ API interaction:
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(&err_lvl, "error", false, "Set logging to error.")

rootCmd.PersistentFlags().StringVar(&cwhub.HubBranch, "branch", "master", "Override hub branch on github")
if err := rootCmd.PersistentFlags().MarkHidden("branch"); err != nil {
log.Fatalf("failed to make branch hidden : %s", err)
}
cobra.OnInitialize(initConfig)
/*don't sort flags so we can enforce order*/
rootCmd.Flags().SortFlags = false
Expand Down
11 changes: 6 additions & 5 deletions pkg/cwhub/hubMgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ var Installdir = "/etc/crowdsec/"
var Hubdir = "/etc/crowdsec/cscli/hub/"
var Cfgdir = "/etc/crowdsec/cscli/"

var RawFileURLTemplate = "https://raw.githubusercontent.com/crowdsecurity/hub/master/%s"
var HUB_INDEX_FILE = ".index.json"
var RawFileURLTemplate = "https://raw.githubusercontent.com/crowdsecurity/hub/%s/%s"
var HubIndexFile = ".index.json"
var HubBranch = "master"

type ItemVersion struct {
Digest string
Expand Down Expand Up @@ -406,7 +407,7 @@ func UpdateHubIdx() 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, HubBranch, HubIndexFile), nil)
if err != nil {
log.Errorf("failed request : %s", err)
return nil, err
Expand All @@ -418,7 +419,7 @@ func DownloadHubIdx() ([]byte, error) {
}
if resp.StatusCode != 200 {
log.Errorf("got code %d while requesting %s, abort", resp.StatusCode,
fmt.Sprintf(RawFileURLTemplate, HUB_INDEX_FILE))
fmt.Sprintf(RawFileURLTemplate, HubBranch, HubIndexFile))
return nil, fmt.Errorf("bad http code")
}
defer resp.Body.Close()
Expand Down Expand Up @@ -678,7 +679,7 @@ func DownloadItem(target Item, tdir string, overwrite bool, dataFolder string) (
}

//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, HubBranch, target.RemotePath), nil)
if err != nil {
log.Errorf("%s : request creation failed : %s", target.Name, err)
return target, err
Expand Down