Skip to content

Commit 36d15fe

Browse files
sabbanmmetc
andauthored
Use the new hub api url (#3132)
* new hapi url * mock url in tests has to be updated --------- Co-authored-by: marco <marco@crowdsec.net>
1 parent a7ec842 commit 36d15fe

File tree

5 files changed

+45
-47
lines changed

5 files changed

+45
-47
lines changed

pkg/csconfig/cscli.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import (
66

77
/*cscli specific config, such as hub directory*/
88
type CscliCfg struct {
9-
Output string `yaml:"output,omitempty"`
10-
Color string `yaml:"color,omitempty"`
11-
HubBranch string `yaml:"hub_branch"`
12-
HubURLTemplate string `yaml:"__hub_url_template__,omitempty"`
13-
SimulationConfig *SimulationConfig `yaml:"-"`
14-
DbConfig *DatabaseCfg `yaml:"-"`
15-
16-
SimulationFilePath string `yaml:"-"`
17-
PrometheusUrl string `yaml:"prometheus_uri"`
9+
Output string `yaml:"output,omitempty"`
10+
Color string `yaml:"color,omitempty"`
11+
HubBranch string `yaml:"hub_branch"`
12+
HubURLTemplate string `yaml:"__hub_url_template__,omitempty"`
13+
SimulationConfig *SimulationConfig `yaml:"-"`
14+
DbConfig *DatabaseCfg `yaml:"-"`
15+
16+
SimulationFilePath string `yaml:"-"`
17+
PrometheusUrl string `yaml:"prometheus_uri"`
1818
}
1919

20-
const defaultHubURLTemplate = "https://hub-cdn.crowdsec.net/%s/%s"
20+
const defaultHubURLTemplate = "https://cdn-hub.crowdsec.net/crowdsecurity/%s/%s"
2121

2222
func (c *Config) loadCSCLI() error {
2323
if c.Cscli == nil {

pkg/cwhub/cwhub_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
1717
)
1818

19-
const mockURLTemplate = "https://hub-cdn.crowdsec.net/%s/%s"
19+
const mockURLTemplate = "https://cdn-hub.crowdsec.net/crowdsecurity/%s/%s"
2020

2121
/*
2222
To test :
@@ -143,18 +143,18 @@ func fileToStringX(path string) string {
143143

144144
func setResponseByPath() {
145145
responseByPath = map[string]string{
146-
"/master/parsers/s01-parse/crowdsecurity/foobar_parser.yaml": fileToStringX("./testdata/foobar_parser.yaml"),
147-
"/master/parsers/s01-parse/crowdsecurity/foobar_subparser.yaml": fileToStringX("./testdata/foobar_parser.yaml"),
148-
"/master/collections/crowdsecurity/test_collection.yaml": fileToStringX("./testdata/collection_v1.yaml"),
149-
"/master/.index.json": fileToStringX("./testdata/index1.json"),
150-
"/master/scenarios/crowdsecurity/foobar_scenario.yaml": `filter: true
146+
"/crowdsecurity/master/parsers/s01-parse/crowdsecurity/foobar_parser.yaml": fileToStringX("./testdata/foobar_parser.yaml"),
147+
"/crowdsecurity/master/parsers/s01-parse/crowdsecurity/foobar_subparser.yaml": fileToStringX("./testdata/foobar_parser.yaml"),
148+
"/crowdsecurity/master/collections/crowdsecurity/test_collection.yaml": fileToStringX("./testdata/collection_v1.yaml"),
149+
"/crowdsecurity/master/.index.json": fileToStringX("./testdata/index1.json"),
150+
"/crowdsecurity/master/scenarios/crowdsecurity/foobar_scenario.yaml": `filter: true
151151
name: crowdsecurity/foobar_scenario`,
152-
"/master/scenarios/crowdsecurity/barfoo_scenario.yaml": `filter: true
152+
"/crowdsecurity/master/scenarios/crowdsecurity/barfoo_scenario.yaml": `filter: true
153153
name: crowdsecurity/foobar_scenario`,
154-
"/master/collections/crowdsecurity/foobar_subcollection.yaml": `
154+
"/crowdsecurity/master/collections/crowdsecurity/foobar_subcollection.yaml": `
155155
blah: blalala
156156
qwe: jejwejejw`,
157-
"/master/collections/crowdsecurity/foobar.yaml": `
157+
"/crowdsecurity/master/collections/crowdsecurity/foobar.yaml": `
158158
blah: blalala
159159
qwe: jejwejejw`,
160160
}

pkg/cwhub/doc.go

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
//
33
// # Definitions
44
//
5-
// - A hub ITEM is a file that defines a parser, a scenario, a collection... in the case of a collection, it has dependencies on other hub items.
6-
// - The hub INDEX is a JSON file that contains a tree of available hub items.
7-
// - A REMOTE HUB is an HTTP server that hosts the hub index and the hub items. It can serve from several branches, usually linked to the CrowdSec version.
8-
// - A LOCAL HUB is a directory that contains a copy of the hub index and the downloaded hub items.
5+
// - A hub ITEM is a file that defines a parser, a scenario, a collection... in the case of a collection, it has dependencies on other hub items.
6+
// - The hub INDEX is a JSON file that contains a tree of available hub items.
7+
// - A REMOTE HUB is an HTTP server that hosts the hub index and the hub items. It can serve from several branches, usually linked to the CrowdSec version.
8+
// - A LOCAL HUB is a directory that contains a copy of the hub index and the downloaded hub items.
99
//
1010
// Once downloaded, hub items can be installed by linking to them from the configuration directory.
1111
// If an item is present in the configuration directory but it's not a link to the local hub, it is
@@ -17,15 +17,15 @@
1717
//
1818
// For the local hub (HubDir = /etc/crowdsec/hub):
1919
//
20-
// - /etc/crowdsec/hub/.index.json
21-
// - /etc/crowdsec/hub/parsers/{stage}/{author}/{parser-name}.yaml
22-
// - /etc/crowdsec/hub/scenarios/{author}/{scenario-name}.yaml
20+
// - /etc/crowdsec/hub/.index.json
21+
// - /etc/crowdsec/hub/parsers/{stage}/{author}/{parser-name}.yaml
22+
// - /etc/crowdsec/hub/scenarios/{author}/{scenario-name}.yaml
2323
//
2424
// For the configuration directory (InstallDir = /etc/crowdsec):
2525
//
26-
// - /etc/crowdsec/parsers/{stage}/{parser-name.yaml} -> /etc/crowdsec/hub/parsers/{stage}/{author}/{parser-name}.yaml
27-
// - /etc/crowdsec/scenarios/{scenario-name.yaml} -> /etc/crowdsec/hub/scenarios/{author}/{scenario-name}.yaml
28-
// - /etc/crowdsec/scenarios/local-scenario.yaml
26+
// - /etc/crowdsec/parsers/{stage}/{parser-name.yaml} -> /etc/crowdsec/hub/parsers/{stage}/{author}/{parser-name}.yaml
27+
// - /etc/crowdsec/scenarios/{scenario-name.yaml} -> /etc/crowdsec/hub/scenarios/{author}/{scenario-name}.yaml
28+
// - /etc/crowdsec/scenarios/local-scenario.yaml
2929
//
3030
// Note that installed items are not grouped by author, this may change in the future if we want to
3131
// support items with the same name from different authors.
@@ -35,11 +35,10 @@
3535
// Additionally, an item can reference a DATA SET that is installed in a different location than
3636
// the item itself. These files are stored in the data directory (InstallDataDir = /var/lib/crowdsec/data).
3737
//
38-
// - /var/lib/crowdsec/data/http_path_traversal.txt
39-
// - /var/lib/crowdsec/data/jira_cve_2021-26086.txt
40-
// - /var/lib/crowdsec/data/log4j2_cve_2021_44228.txt
41-
// - /var/lib/crowdsec/data/sensitive_data.txt
42-
//
38+
// - /var/lib/crowdsec/data/http_path_traversal.txt
39+
// - /var/lib/crowdsec/data/jira_cve_2021-26086.txt
40+
// - /var/lib/crowdsec/data/log4j2_cve_2021_44228.txt
41+
// - /var/lib/crowdsec/data/sensitive_data.txt
4342
//
4443
// # Using the package
4544
//
@@ -87,22 +86,22 @@
8786
//
8887
// You can also install items if they have already been downloaded:
8988
//
90-
// // install a parser
91-
// force := false
92-
// downloadOnly := false
93-
// err := parser.Install(force, downloadOnly)
94-
// if err != nil {
95-
// return fmt.Errorf("unable to install parser: %w", err)
96-
// }
89+
// // install a parser
90+
// force := false
91+
// downloadOnly := false
92+
// err := parser.Install(force, downloadOnly)
93+
// if err != nil {
94+
// return fmt.Errorf("unable to install parser: %w", err)
95+
// }
9796
//
9897
// As soon as you try to install an item that is not downloaded or is not up-to-date (meaning its computed hash
9998
// does not correspond to the latest version available in the index), a download will be attempted and you'll
10099
// get the error "remote hub configuration is not provided".
101100
//
102101
// To provide the remote hub configuration, use the second parameter of NewHub():
103102
//
104-
// remoteHub := cwhub.RemoteHubCfg{
105-
// URLTemplate: "https://hub-cdn.crowdsec.net/%s/%s",
103+
// remoteHub := cwhub.RemoteHubCfg{
104+
// URLTemplate: "https://cdn-hub.crowdsec.net/crowdsecurity/%s/%s",
106105
// Branch: "master",
107106
// IndexPath: ".index.json",
108107
// }
@@ -124,5 +123,4 @@
124123
//
125124
// Note that the command will fail if the hub has already been synced. If you want to do it (ex. after a configuration
126125
// change the application is notified with SIGHUP) you have to instantiate a new hub object and dispose of the old one.
127-
//
128126
package cwhub

pkg/cwhub/hub_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestUpdateIndex(t *testing.T) {
6565
fmt.Println("Test 'bad domain'")
6666

6767
hub.remote = &RemoteHubCfg{
68-
URLTemplate: "https://baddomain/%s/%s",
68+
URLTemplate: "https://baddomain/crowdsecurity/%s/%s",
6969
Branch: "master",
7070
IndexPath: ".index.json",
7171
}

pkg/cwhub/itemupgrade_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,6 @@ func assertCollectionDepsInstalled(t *testing.T, hub *Hub, collection string) {
218218
}
219219

220220
func pushUpdateToCollectionInHub() {
221-
responseByPath["/master/.index.json"] = fileToStringX("./testdata/index2.json")
222-
responseByPath["/master/collections/crowdsecurity/test_collection.yaml"] = fileToStringX("./testdata/collection_v2.yaml")
221+
responseByPath["/crowdsecurity/master/.index.json"] = fileToStringX("./testdata/index2.json")
222+
responseByPath["/crowdsecurity/master/collections/crowdsecurity/test_collection.yaml"] = fileToStringX("./testdata/collection_v2.yaml")
223223
}

0 commit comments

Comments
 (0)