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

option to override hub url template. for testers only. #2785

Merged
merged 3 commits into from
Jan 25, 2024
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
4 changes: 4 additions & 0 deletions cmd/crowdsec-cli/require/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ func HubBranch(cfg *csconfig.Config) string {

return branch
}

func HubURLTemplate(cfg *csconfig.Config) string {
return cfg.Cscli.HubURLTemplate
}
4 changes: 2 additions & 2 deletions cmd/crowdsec-cli/require/require.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ func Notifications(c *csconfig.Config) error {
func RemoteHub(c *csconfig.Config) *cwhub.RemoteHubCfg {
// set branch in config, and log if necessary
branch := HubBranch(c)
urlTemplate := HubURLTemplate(c)
remote := &cwhub.RemoteHubCfg{
Branch: branch,
URLTemplate: "https://hub-cdn.crowdsec.net/%s/%s",
// URLTemplate: "http://localhost:8000/crowdsecurity/%s/hub/%s",
URLTemplate: urlTemplate,
IndexPath: ".index.json",
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/csconfig/cscli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ type CscliCfg struct {
Output string `yaml:"output,omitempty"`
Color string `yaml:"color,omitempty"`
HubBranch string `yaml:"hub_branch"`
HubURLTemplate string `yaml:"__hub_url_template__,omitempty"`
SimulationConfig *SimulationConfig `yaml:"-"`
DbConfig *DatabaseCfg `yaml:"-"`

SimulationFilePath string `yaml:"-"`
PrometheusUrl string `yaml:"prometheus_uri"`
}

const defaultHubURLTemplate = "https://hub-cdn.crowdsec.net/%s/%s"

func (c *Config) loadCSCLI() error {
if c.Cscli == nil {
c.Cscli = &CscliCfg{}
Expand All @@ -25,5 +28,9 @@ func (c *Config) loadCSCLI() error {
c.Cscli.PrometheusUrl = fmt.Sprintf("http://%s:%d/metrics", c.Prometheus.ListenAddr, c.Prometheus.ListenPort)
}

if c.Cscli.HubURLTemplate == "" {
c.Cscli.HubURLTemplate = defaultHubURLTemplate
}

return nil
}
3 changes: 2 additions & 1 deletion pkg/csconfig/cscli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func TestLoadCSCLI(t *testing.T) {
},
},
expected: &CscliCfg{
PrometheusUrl: "http://127.0.0.1:6060/metrics",
PrometheusUrl: "http://127.0.0.1:6060/metrics",
HubURLTemplate: defaultHubURLTemplate,
},
},
}
Expand Down