Skip to content

Commit

Permalink
Merge pull request #105 from sbs2001/release_ready
Browse files Browse the repository at this point in the history
Make bouncer release ready
  • Loading branch information
AlteredCoder authored Jun 21, 2022
2 parents 4813a91 + d1f5967 commit 2386a2e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 40 deletions.
74 changes: 38 additions & 36 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,44 @@ func NewConfig(configPath string) (*bouncerConfig, error) {
if err != nil {
return nil, fmt.Errorf("failed to unmarshal %s : %v", configPath, err)
}

/*Configure logging*/
if err = types.SetDefaultLoggerConfig(config.LogMode, config.LogDir, config.LogLevel, 0, 0, 0, nil); err != nil {
log.Fatal(err.Error())
}
if config.LogMode == "file" {
if config.LogDir == "" {
config.LogDir = "/var/log/"
}
_maxsize := 40
if config.LogMaxSize != 0 {
_maxsize = config.LogMaxSize
}
_maxfiles := 3
if config.LogMaxFiles != 0 {
_maxfiles = config.LogMaxFiles
}
_maxage := 30
if config.LogMaxAge != 0 {
_maxage = config.LogMaxAge
}
_compress := true
if config.CompressLogs != nil {
_compress = *config.CompressLogs
}
logOutput := &lumberjack.Logger{
Filename: config.LogDir + "/crowdsec-cloudflare-bouncer.log",
MaxSize: _maxsize,
MaxBackups: _maxfiles,
MaxAge: _maxage,
Compress: _compress,
}
log.SetOutput(logOutput)
log.SetFormatter(&log.TextFormatter{TimestampFormat: "02-01-2006 15:04:05", FullTimestamp: true})
} else if config.LogMode != "stdout" {
return &bouncerConfig{}, fmt.Errorf("log mode '%s' unknown, expecting 'file' or 'stdout'", config.LogMode)
}

accountIDSet := make(map[string]bool) // for verifying that each account ID is unique
zoneIdSet := make(map[string]bool) // for verifying that each zoneID is unique
validAction := map[string]bool{"challenge": true, "block": true, "js_challenge": true, "managed_challenge": true}
Expand Down Expand Up @@ -131,42 +169,6 @@ func NewConfig(configPath string) (*bouncerConfig, error) {
)
}
}
/*Configure logging*/
if err = types.SetDefaultLoggerConfig(config.LogMode, config.LogDir, config.LogLevel, 0, 0, 0, nil); err != nil {
log.Fatal(err.Error())
}
if config.LogMode == "file" {
if config.LogDir == "" {
config.LogDir = "/var/log/"
}
_maxsize := 40
if config.LogMaxSize != 0 {
_maxsize = config.LogMaxSize
}
_maxfiles := 3
if config.LogMaxFiles != 0 {
_maxfiles = config.LogMaxFiles
}
_maxage := 30
if config.LogMaxAge != 0 {
_maxage = config.LogMaxAge
}
_compress := true
if config.CompressLogs != nil {
_compress = *config.CompressLogs
}
logOutput := &lumberjack.Logger{
Filename: config.LogDir + "/crowdsec-cloudflare-bouncer.log",
MaxSize: _maxsize,
MaxBackups: _maxfiles,
MaxAge: _maxage,
Compress: _compress,
}
log.SetOutput(logOutput)
log.SetFormatter(&log.TextFormatter{TimestampFormat: "02-01-2006 15:04:05", FullTimestamp: true})
} else if config.LogMode != "stdout" {
return &bouncerConfig{}, fmt.Errorf("log mode '%s' unknown, expecting 'file' or 'stdout'", config.LogMode)
}
return config, nil
}

Expand Down
4 changes: 2 additions & 2 deletions config/crowdsec-cloudflare-bouncer-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ cloudflare_config:
- id:
token:
ip_list_prefix: crowdsec
default_action: challenge
default_action: managed_challenge
zones:
- actions:
- challenge # valid choices are either of challenge, js_challenge, block
- managed_challenge # valid choices are either of managed_challenge, js_challenge, block
zone_id:


Expand Down
4 changes: 2 additions & 2 deletions config/crowdsec-cloudflare-bouncer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ cloudflare_config:
- id: <CLOUDFLARE_ACCOUNT_ID>
token: <CLOUDFLARE_TOKEN>
ip_list_prefix: crowdsec
default_action: challenge
default_action: managed_challenge
zones:
- actions:
- challenge # valid choices are either of challenge, js_challenge, block
- managed_challenge # valid choices are either of managed_challenge, js_challenge, block
zone_id:


Expand Down

0 comments on commit 2386a2e

Please sign in to comment.