update to use cdn for hub (#920)

* update to use cdn for hub
* add cdn for version
* fix unit tests accodingly with new cdn

Co-authored-by: sabban <15465465+sabban@users.noreply.github.com>
This commit is contained in:
Manuel Sabban 2021-09-02 15:17:37 +02:00 committed by GitHub
parent bed90a832e
commit d7d591ff84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 9 deletions

View file

@ -26,7 +26,7 @@ var ItemTypes = []string{PARSERS, PARSERS_OVFLW, SCENARIOS, COLLECTIONS}
var hubIdx map[string]map[string]Item
var RawFileURLTemplate = "https://raw.githubusercontent.com/crowdsecurity/hub/%s/%s"
var RawFileURLTemplate = "https://hub-cdn.crowdsec.net/%s/%s"
var HubBranch = "master"
var HubIndexFile = ".index.json"

View file

@ -386,7 +386,7 @@ func (t *mockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
log.Printf("---> %s", req.URL.Path)
/*FAKE PARSER*/
if req.URL.Path == "/crowdsecurity/hub/master/parsers/s01-parse/crowdsecurity/foobar_parser.yaml" {
if req.URL.Path == "/master/parsers/s01-parse/crowdsecurity/foobar_parser.yaml" {
responseBody = `onsuccess: next_stage
filter: evt.Parsed.program == 'foobar_parser'
name: crowdsecurity/foobar_parser
@ -397,7 +397,7 @@ grok:
apply_on: message
`
} else if req.URL.Path == "/crowdsecurity/hub/master/parsers/s01-parse/crowdsecurity/foobar_subparser.yaml" {
} else if req.URL.Path == "/master/parsers/s01-parse/crowdsecurity/foobar_subparser.yaml" {
responseBody = `onsuccess: next_stage
filter: evt.Parsed.program == 'foobar_parser'
name: crowdsecurity/foobar_parser
@ -409,19 +409,19 @@ grok:
`
/*FAKE SCENARIO*/
} else if req.URL.Path == "/crowdsecurity/hub/master/scenarios/crowdsecurity/foobar_scenario.yaml" {
} else if req.URL.Path == "/master/scenarios/crowdsecurity/foobar_scenario.yaml" {
responseBody = `filter: true
name: crowdsecurity/foobar_scenario`
/*FAKE COLLECTIONS*/
} else if req.URL.Path == "/crowdsecurity/hub/master/collections/crowdsecurity/foobar.yaml" {
} else if req.URL.Path == "/master/collections/crowdsecurity/foobar.yaml" {
responseBody = `
blah: blalala
qwe: jejwejejw`
} else if req.URL.Path == "/crowdsecurity/hub/master/collections/crowdsecurity/foobar_subcollection.yaml" {
} else if req.URL.Path == "/master/collections/crowdsecurity/foobar_subcollection.yaml" {
responseBody = `
blah: blalala
qwe: jejwejejw`
} else if req.URL.Path == "/crowdsecurity/hub/master/.index.json" {
} else if req.URL.Path == "/master/.index.json" {
responseBody =
`{
"collections": {

View file

@ -22,7 +22,7 @@ func TestDownloadHubIdx(t *testing.T) {
//bad domain
fmt.Println("Test 'bad domain'")
RawFileURLTemplate = "https://baddomain/crowdsecurity/hub/%s/%s"
RawFileURLTemplate = "https://baddomain/%s/%s"
ret, err = DownloadHubIdx(&csconfig.Hub{})
if err == nil || !strings.HasPrefix(fmt.Sprintf("%s", err), "failed http request for hub index: Get") {
log.Errorf("unexpected error %s", err)

View file

@ -84,7 +84,7 @@ func Statisfies(strvers string, constraint string) (bool, error) {
func Latest() (string, error) {
latest := make(map[string]interface{})
resp, err := http.Get("https://api.github.com/repos/crowdsecurity/crowdsec/releases/latest")
resp, err := http.Get("https://version.crowdsec.net/latest")
if err != nil {
return "", err
}