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:
parent
bed90a832e
commit
d7d591ff84
|
@ -26,7 +26,7 @@ var ItemTypes = []string{PARSERS, PARSERS_OVFLW, SCENARIOS, COLLECTIONS}
|
||||||
|
|
||||||
var hubIdx map[string]map[string]Item
|
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 HubBranch = "master"
|
||||||
var HubIndexFile = ".index.json"
|
var HubIndexFile = ".index.json"
|
||||||
|
|
||||||
|
|
|
@ -386,7 +386,7 @@ func (t *mockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
log.Printf("---> %s", req.URL.Path)
|
log.Printf("---> %s", req.URL.Path)
|
||||||
|
|
||||||
/*FAKE PARSER*/
|
/*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
|
responseBody = `onsuccess: next_stage
|
||||||
filter: evt.Parsed.program == 'foobar_parser'
|
filter: evt.Parsed.program == 'foobar_parser'
|
||||||
name: crowdsecurity/foobar_parser
|
name: crowdsecurity/foobar_parser
|
||||||
|
@ -397,7 +397,7 @@ grok:
|
||||||
apply_on: message
|
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
|
responseBody = `onsuccess: next_stage
|
||||||
filter: evt.Parsed.program == 'foobar_parser'
|
filter: evt.Parsed.program == 'foobar_parser'
|
||||||
name: crowdsecurity/foobar_parser
|
name: crowdsecurity/foobar_parser
|
||||||
|
@ -409,19 +409,19 @@ grok:
|
||||||
`
|
`
|
||||||
/*FAKE SCENARIO*/
|
/*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
|
responseBody = `filter: true
|
||||||
name: crowdsecurity/foobar_scenario`
|
name: crowdsecurity/foobar_scenario`
|
||||||
/*FAKE COLLECTIONS*/
|
/*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 = `
|
responseBody = `
|
||||||
blah: blalala
|
blah: blalala
|
||||||
qwe: jejwejejw`
|
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 = `
|
responseBody = `
|
||||||
blah: blalala
|
blah: blalala
|
||||||
qwe: jejwejejw`
|
qwe: jejwejejw`
|
||||||
} else if req.URL.Path == "/crowdsecurity/hub/master/.index.json" {
|
} else if req.URL.Path == "/master/.index.json" {
|
||||||
responseBody =
|
responseBody =
|
||||||
`{
|
`{
|
||||||
"collections": {
|
"collections": {
|
||||||
|
|
|
@ -22,7 +22,7 @@ func TestDownloadHubIdx(t *testing.T) {
|
||||||
|
|
||||||
//bad domain
|
//bad domain
|
||||||
fmt.Println("Test 'bad domain'")
|
fmt.Println("Test 'bad domain'")
|
||||||
RawFileURLTemplate = "https://baddomain/crowdsecurity/hub/%s/%s"
|
RawFileURLTemplate = "https://baddomain/%s/%s"
|
||||||
ret, err = DownloadHubIdx(&csconfig.Hub{})
|
ret, err = DownloadHubIdx(&csconfig.Hub{})
|
||||||
if err == nil || !strings.HasPrefix(fmt.Sprintf("%s", err), "failed http request for hub index: Get") {
|
if err == nil || !strings.HasPrefix(fmt.Sprintf("%s", err), "failed http request for hub index: Get") {
|
||||||
log.Errorf("unexpected error %s", err)
|
log.Errorf("unexpected error %s", err)
|
||||||
|
|
|
@ -84,7 +84,7 @@ func Statisfies(strvers string, constraint string) (bool, error) {
|
||||||
func Latest() (string, error) {
|
func Latest() (string, error) {
|
||||||
latest := make(map[string]interface{})
|
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 {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue