Skip to content

Commit

Permalink
truely don't try to send anything with empty online credentials confi…
Browse files Browse the repository at this point in the history
…guration file (#657)

* truely don't try to send anything with empty online credentials config file

Co-authored-by: AlteredCoder <AlteredCoder>
  • Loading branch information
registergoofy committed Mar 2, 2021
1 parent a627887 commit a8b16a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func NewServer(config *csconfig.LocalApiServerCfg) (*APIServer, error) {

var apiClient *apic

if config.OnlineClient != nil {
if config.OnlineClient != nil && config.OnlineClient.Credentials != nil {
log.Printf("Loading CAPI pusher")
apiClient, err = NewAPIC(config.OnlineClient, dbClient)
if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions pkg/csconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func (c *GlobalConfig) LoadConfiguration() error {
if err := c.LoadSimulation(); err != nil {
return err
}

if c.Crowdsec != nil {
if c.Crowdsec.AcquisitionFilePath != "" {
log.Debugf("non-empty acquisition file path %s", c.Crowdsec.AcquisitionFilePath)
Expand Down Expand Up @@ -157,7 +156,6 @@ func (c *GlobalConfig) LoadConfiguration() error {
apiclient.InsecureSkipVerify = *c.API.Client.InsecureSkipVerify
}
}

if c.API.Server != nil && !c.DisableAPI {
c.API.Server.DbConfig = c.DbConfig
c.API.Server.LogDir = c.Common.LogDir
Expand All @@ -175,10 +173,14 @@ func (c *GlobalConfig) LoadConfiguration() error {
if err != nil {
return errors.Wrap(err, fmt.Sprintf("failed unmarshaling api server credentials configuration file '%s'", c.API.Server.OnlineClient.CredentialsFilePath))
}
if c.API.Server.OnlineClient.Credentials == nil {
log.Debugf("online credentials not found in '%s', will not use crowdsec api", c.API.Server.OnlineClient.CredentialsFilePath)
if c.API.Server.OnlineClient.Credentials.Login == "" || c.API.Server.OnlineClient.Credentials.Password == "" || c.API.Server.OnlineClient.Credentials.URL == "" {
log.Debugf("can't load CAPI credentials from '%s' (missing field)", c.API.Server.OnlineClient.CredentialsFilePath)
c.API.Server.OnlineClient.Credentials = nil
}
}
if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil {
log.Printf("push and pull to crowdsec API disabled")
}
}

return nil
Expand Down

0 comments on commit a8b16a6

Please sign in to comment.