2020-11-30 09:37:17 +00:00
|
|
|
package csconfig
|
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
/*cscli specific config, such as hub directory*/
|
|
|
|
type CscliCfg struct {
|
|
|
|
Output string `yaml:"output,omitempty"`
|
2022-10-07 09:05:35 +00:00
|
|
|
Color string `yaml:"color,omitempty"`
|
2020-11-30 09:37:17 +00:00
|
|
|
HubBranch string `yaml:"hub_branch"`
|
2024-01-25 11:53:20 +00:00
|
|
|
HubURLTemplate string `yaml:"__hub_url_template__,omitempty"`
|
2020-11-30 09:37:17 +00:00
|
|
|
SimulationConfig *SimulationConfig `yaml:"-"`
|
|
|
|
DbConfig *DatabaseCfg `yaml:"-"`
|
2023-11-24 14:57:32 +00:00
|
|
|
|
2020-11-30 09:37:17 +00:00
|
|
|
SimulationFilePath string `yaml:"-"`
|
2021-02-17 12:53:57 +00:00
|
|
|
PrometheusUrl string `yaml:"prometheus_uri"`
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
2021-03-24 17:16:17 +00:00
|
|
|
|
2024-01-25 11:53:20 +00:00
|
|
|
const defaultHubURLTemplate = "https://hub-cdn.crowdsec.net/%s/%s"
|
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
func (c *Config) loadCSCLI() error {
|
2021-03-24 17:16:17 +00:00
|
|
|
if c.Cscli == nil {
|
|
|
|
c.Cscli = &CscliCfg{}
|
|
|
|
}
|
2023-11-24 14:57:32 +00:00
|
|
|
|
|
|
|
if c.Prometheus.ListenAddr != "" && c.Prometheus.ListenPort != 0 {
|
|
|
|
c.Cscli.PrometheusUrl = fmt.Sprintf("http://%s:%d/metrics", c.Prometheus.ListenAddr, c.Prometheus.ListenPort)
|
2021-03-24 17:16:17 +00:00
|
|
|
}
|
|
|
|
|
2024-01-25 11:53:20 +00:00
|
|
|
if c.Cscli.HubURLTemplate == "" {
|
|
|
|
c.Cscli.HubURLTemplate = defaultHubURLTemplate
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:16:17 +00:00
|
|
|
return nil
|
|
|
|
}
|