add load configuration file
This commit is contained in:
parent
52edfba2b3
commit
2c6a279b9b
|
@ -3,6 +3,7 @@ package csconfig
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
"github.com/crowdsecurity/crowdsec/pkg/apiclient"
|
||||||
|
@ -85,9 +86,11 @@ type LocalApiServerCfg struct {
|
||||||
LogMedia string `yaml:"-"`
|
LogMedia string `yaml:"-"`
|
||||||
OnlineClient *OnlineApiClientCfg `yaml:"online_client"`
|
OnlineClient *OnlineApiClientCfg `yaml:"online_client"`
|
||||||
ProfilesPath string `yaml:"profiles_path,omitempty"`
|
ProfilesPath string `yaml:"profiles_path,omitempty"`
|
||||||
|
ConsoleConfigPath string `yaml:"console_path,omitempty"`
|
||||||
Profiles []*ProfileCfg `yaml:"-"`
|
Profiles []*ProfileCfg `yaml:"-"`
|
||||||
LogLevel *log.Level `yaml:"log_level"`
|
LogLevel *log.Level `yaml:"log_level"`
|
||||||
UseForwardedForHeaders bool `yaml:"use_forwarded_for_headers,omitempty"`
|
UseForwardedForHeaders bool `yaml:"use_forwarded_for_headers,omitempty"`
|
||||||
|
ConsoleConfig map[string]interface{} `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TLSCfg struct {
|
type TLSCfg struct {
|
||||||
|
@ -105,6 +108,7 @@ func (c *Config) LoadAPIServer() error {
|
||||||
if err := c.API.Server.LoadProfiles(); err != nil {
|
if err := c.API.Server.LoadProfiles(); err != nil {
|
||||||
return errors.Wrap(err, "while loading profiles for LAPI")
|
return errors.Wrap(err, "while loading profiles for LAPI")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.API.Server.OnlineClient != nil && c.API.Server.OnlineClient.CredentialsFilePath != "" {
|
if c.API.Server.OnlineClient != nil && c.API.Server.OnlineClient.CredentialsFilePath != "" {
|
||||||
if err := c.API.Server.OnlineClient.Load(); err != nil {
|
if err := c.API.Server.OnlineClient.Load(); err != nil {
|
||||||
return errors.Wrap(err, "loading online client credentials")
|
return errors.Wrap(err, "loading online client credentials")
|
||||||
|
@ -124,6 +128,24 @@ func (c *Config) LoadAPIServer() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *LocalApiServerCfg) LoadConsoleConfig() error {
|
||||||
|
c.ConsoleConfig = make(map[string]interface{})
|
||||||
|
if _, err := os.Stat(c.ConsoleConfigPath); err != nil && os.IsNotExist(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
yamlFile, err := ioutil.ReadFile(c.ConsoleConfigPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("reading console config file '%s': %s", c.ConsoleConfigPath, err)
|
||||||
|
}
|
||||||
|
err = yaml.Unmarshal(yamlFile, c.ConsoleConfig)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unmarshaling console config file '%s': %s", c.ConsoleConfigPath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Config) LoadAPIClient() error {
|
func (c *Config) LoadAPIClient() error {
|
||||||
if c.API != nil && c.API.Client != nil && c.API.Client.CredentialsFilePath != "" && !c.DisableAgent {
|
if c.API != nil && c.API.Client != nil && c.API.Client.CredentialsFilePath != "" && !c.DisableAgent {
|
||||||
if err := c.API.Client.Load(); err != nil {
|
if err := c.API.Client.Load(); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue