Kaynağa Gözat

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>
Manuel Sabban 3 yıl önce
ebeveyn
işleme
d7d591ff84

+ 1 - 1
pkg/cwhub/cwhub.go

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

+ 6 - 6
pkg/cwhub/cwhub_test.go

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

+ 1 - 1
pkg/cwhub/download_test.go

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

+ 1 - 1
pkg/cwversion/version.go

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