|
@@ -229,42 +229,44 @@ func (c *Config) LoadAPIServer() error {
|
|
|
log.Warning("crowdsec local API is disabled from flag")
|
|
|
}
|
|
|
|
|
|
- if c.API.Server != nil {
|
|
|
-
|
|
|
- //inherit log level from common, then api->server
|
|
|
- var logLevel log.Level
|
|
|
- if c.API.Server.LogLevel != nil {
|
|
|
- logLevel = *c.API.Server.LogLevel
|
|
|
- } else if c.Common.LogLevel != nil {
|
|
|
- logLevel = *c.Common.LogLevel
|
|
|
- } else {
|
|
|
- logLevel = log.InfoLevel
|
|
|
- }
|
|
|
+ if c.API.Server == nil {
|
|
|
+ log.Warning("crowdsec local API is disabled")
|
|
|
+ c.DisableAPI = true
|
|
|
+ return nil
|
|
|
+ }
|
|
|
|
|
|
- if c.API.Server.PapiLogLevel == nil {
|
|
|
- c.API.Server.PapiLogLevel = &logLevel
|
|
|
- }
|
|
|
+ //inherit log level from common, then api->server
|
|
|
+ var logLevel log.Level
|
|
|
+ if c.API.Server.LogLevel != nil {
|
|
|
+ logLevel = *c.API.Server.LogLevel
|
|
|
+ } else if c.Common.LogLevel != nil {
|
|
|
+ logLevel = *c.Common.LogLevel
|
|
|
+ } else {
|
|
|
+ logLevel = log.InfoLevel
|
|
|
+ }
|
|
|
|
|
|
- if c.API.Server.OnlineClient != nil && c.API.Server.OnlineClient.CredentialsFilePath != "" {
|
|
|
- if err := c.API.Server.OnlineClient.Load(); err != nil {
|
|
|
- return errors.Wrap(err, "loading online client credentials")
|
|
|
- }
|
|
|
- }
|
|
|
- if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil {
|
|
|
- log.Printf("push and pull to Central API disabled")
|
|
|
- }
|
|
|
- if err := c.LoadDBConfig(); err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
+ if c.API.Server.PapiLogLevel == nil {
|
|
|
+ c.API.Server.PapiLogLevel = &logLevel
|
|
|
+ }
|
|
|
|
|
|
- if err := c.API.Server.LoadCapiWhitelists(); err != nil {
|
|
|
- return err
|
|
|
+ if c.API.Server.OnlineClient != nil && c.API.Server.OnlineClient.CredentialsFilePath != "" {
|
|
|
+ if err := c.API.Server.OnlineClient.Load(); err != nil {
|
|
|
+ return errors.Wrap(err, "loading online client credentials")
|
|
|
}
|
|
|
+ }
|
|
|
+ if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil {
|
|
|
+ log.Printf("push and pull to Central API disabled")
|
|
|
+ }
|
|
|
+ if err := c.LoadDBConfig(); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
|
|
|
- } else {
|
|
|
- log.Warning("crowdsec local API is disabled")
|
|
|
- c.DisableAPI = true
|
|
|
- return nil
|
|
|
+ if err := c.API.Server.LoadCapiWhitelists(); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ if c.API.Server.CapiWhitelistsPath != "" {
|
|
|
+ log.Infof("loaded capi whitelist from %s: %d IPs, %d CIDRs", c.API.Server.CapiWhitelistsPath, len(c.API.Server.CapiWhitelists.Ips), len(c.API.Server.CapiWhitelists.Cidrs))
|
|
|
}
|
|
|
|
|
|
if c.API.Server.Enable == nil {
|
|
@@ -361,7 +363,7 @@ func (s *LocalApiServerCfg) LoadCapiWhitelists() error {
|
|
|
for _, v := range fromCfg.Cidrs {
|
|
|
_, tnet, err := net.ParseCIDR(v)
|
|
|
if err != nil {
|
|
|
- return fmt.Errorf("unable to parse cidr whitelist '%s' : %v.", v, err)
|
|
|
+ return fmt.Errorf("unable to parse cidr whitelist '%s' : %v", v, err)
|
|
|
}
|
|
|
s.CapiWhitelists.Cidrs = append(s.CapiWhitelists.Cidrs, tnet)
|
|
|
}
|