From 91b0fce955aaab043ced444e0a8bde176fb39ce6 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:53:20 +0100 Subject: [PATCH] option to override hub url template. for testers only. (#2785) --- cmd/crowdsec-cli/require/branch.go | 4 ++++ cmd/crowdsec-cli/require/require.go | 4 ++-- pkg/csconfig/cscli.go | 7 +++++++ pkg/csconfig/cscli_test.go | 3 ++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/crowdsec-cli/require/branch.go b/cmd/crowdsec-cli/require/branch.go index b82f34a27..6fcaaacea 100644 --- a/cmd/crowdsec-cli/require/branch.go +++ b/cmd/crowdsec-cli/require/branch.go @@ -56,3 +56,7 @@ func HubBranch(cfg *csconfig.Config) string { return branch } + +func HubURLTemplate(cfg *csconfig.Config) string { + return cfg.Cscli.HubURLTemplate +} diff --git a/cmd/crowdsec-cli/require/require.go b/cmd/crowdsec-cli/require/require.go index e4589b7ce..0ab5b5897 100644 --- a/cmd/crowdsec-cli/require/require.go +++ b/cmd/crowdsec-cli/require/require.go @@ -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", } diff --git a/pkg/csconfig/cscli.go b/pkg/csconfig/cscli.go index 2a3fa7df3..7fff03864 100644 --- a/pkg/csconfig/cscli.go +++ b/pkg/csconfig/cscli.go @@ -9,6 +9,7 @@ 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:"-"` @@ -16,6 +17,8 @@ type CscliCfg struct { 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{} @@ -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 } diff --git a/pkg/csconfig/cscli_test.go b/pkg/csconfig/cscli_test.go index b814fda88..807f02d21 100644 --- a/pkg/csconfig/cscli_test.go +++ b/pkg/csconfig/cscli_test.go @@ -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, }, }, }