fix "crowdsec-cli/require" log verbosity (#2390)

This commit is contained in:
mmetc 2023-07-28 09:56:20 +02:00 committed by GitHub
parent 718721b341
commit ae53c0f1cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 29 deletions

View file

@ -26,14 +26,6 @@ func CAPI(c *csconfig.Config) error {
} }
func PAPI(c *csconfig.Config) error { func PAPI(c *csconfig.Config) error {
if err := LAPI(c); err != nil {
return err
}
if err := CAPI(c); err != nil {
return err
}
if c.API.Server.OnlineClient.Credentials.PapiURL == "" { if c.API.Server.OnlineClient.Credentials.PapiURL == "" {
return fmt.Errorf("no PAPI URL in configuration") return fmt.Errorf("no PAPI URL in configuration")
} }
@ -41,10 +33,6 @@ func PAPI(c *csconfig.Config) error {
} }
func Enrolled(c *csconfig.Config) error { func Enrolled(c *csconfig.Config) error {
if err := CAPI(c); err != nil {
return err
}
if c.API.Server.OnlineClient.Credentials == nil { if c.API.Server.OnlineClient.Credentials == nil {
return fmt.Errorf("the Central API (CAPI) must be configured with 'cscli capi register'") return fmt.Errorf("the Central API (CAPI) must be configured with 'cscli capi register'")
} }
@ -60,10 +48,6 @@ func DB(c *csconfig.Config) error {
} }
func Profiles(c *csconfig.Config) error { func Profiles(c *csconfig.Config) error {
if err := LAPI(c); err != nil {
return err
}
if err := c.API.Server.LoadProfiles(); err != nil { if err := c.API.Server.LoadProfiles(); err != nil {
return fmt.Errorf("while loading profiles: %w", err) return fmt.Errorf("while loading profiles: %w", err)
} }
@ -72,10 +56,6 @@ func Profiles(c *csconfig.Config) error {
} }
func Notifications(c *csconfig.Config) error { func Notifications(c *csconfig.Config) error {
if err := LAPI(c); err != nil {
return err
}
if c.ConfigPaths.NotificationDir == "" { if c.ConfigPaths.NotificationDir == "" {
return fmt.Errorf("config_paths.notification_dir is not set in crowdsec config") return fmt.Errorf("config_paths.notification_dir is not set in crowdsec config")
} }

View file

@ -268,9 +268,11 @@ func (c *Config) LoadAPIServer() error {
return fmt.Errorf("loading online client credentials: %w", err) return fmt.Errorf("loading online client credentials: %w", err)
} }
} }
if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil { if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil {
log.Printf("push and pull to Central API disabled") log.Printf("push and pull to Central API disabled")
} }
if err := c.LoadDBConfig(); err != nil { if err := c.LoadDBConfig(); err != nil {
return err return err
} }
@ -286,37 +288,34 @@ func (c *Config) LoadAPIServer() error {
if err := c.LoadCommon(); err != nil { if err := c.LoadCommon(); err != nil {
return fmt.Errorf("loading common configuration: %s", err) return fmt.Errorf("loading common configuration: %s", err)
} }
c.API.Server.LogDir = c.Common.LogDir c.API.Server.LogDir = c.Common.LogDir
c.API.Server.LogMedia = c.Common.LogMedia c.API.Server.LogMedia = c.Common.LogMedia
c.API.Server.CompressLogs = c.Common.CompressLogs c.API.Server.CompressLogs = c.Common.CompressLogs
c.API.Server.LogMaxSize = c.Common.LogMaxSize c.API.Server.LogMaxSize = c.Common.LogMaxSize
c.API.Server.LogMaxAge = c.Common.LogMaxAge c.API.Server.LogMaxAge = c.Common.LogMaxAge
c.API.Server.LogMaxFiles = c.Common.LogMaxFiles c.API.Server.LogMaxFiles = c.Common.LogMaxFiles
if c.API.Server.UseForwardedForHeaders && c.API.Server.TrustedProxies == nil { if c.API.Server.UseForwardedForHeaders && c.API.Server.TrustedProxies == nil {
c.API.Server.TrustedProxies = &[]string{"0.0.0.0/0"} c.API.Server.TrustedProxies = &[]string{"0.0.0.0/0"}
} }
if c.API.Server.TrustedProxies != nil { if c.API.Server.TrustedProxies != nil {
c.API.Server.UseForwardedForHeaders = true c.API.Server.UseForwardedForHeaders = true
} }
if err := c.API.Server.LoadProfiles(); err != nil { if err := c.API.Server.LoadProfiles(); err != nil {
return fmt.Errorf("while loading profiles for LAPI: %w", err) return fmt.Errorf("while loading profiles for LAPI: %w", err)
} }
if c.API.Server.ConsoleConfigPath == "" { if c.API.Server.ConsoleConfigPath == "" {
c.API.Server.ConsoleConfigPath = DefaultConsoleConfigFilePath c.API.Server.ConsoleConfigPath = DefaultConsoleConfigFilePath
} }
if err := c.API.Server.LoadConsoleConfig(); err != nil { if err := c.API.Server.LoadConsoleConfig(); err != nil {
return fmt.Errorf("while loading console options: %w", err) return fmt.Errorf("while loading console options: %w", err)
} }
if c.API.Server.OnlineClient != nil && c.API.Server.OnlineClient.CredentialsFilePath != "" {
if err := c.API.Server.OnlineClient.Load(); err != nil {
return fmt.Errorf("loading online client credentials: %w", err)
}
}
if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil {
log.Printf("push and pull to Central API disabled")
}
if c.API.CTI != nil { if c.API.CTI != nil {
if err := c.API.CTI.Load(); err != nil { if err := c.API.CTI.Load(); err != nil {
return fmt.Errorf("loading CTI configuration: %w", err) return fmt.Errorf("loading CTI configuration: %w", err)