Skip to content

Commit

Permalink
Deprecate challenge action; Log on bouncer start
Browse files Browse the repository at this point in the history
Signed-off-by: Shivam Sandbhor <[email protected]>
  • Loading branch information
sbs2001 committed Jun 17, 2022
1 parent c944e50 commit 7be5b1c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const CallsPerSecondLimit uint32 = 4
var TotalIPListCapacity int = 10000

var CloudflareActionByDecisionType = map[string]string{
"captcha": "challenge",
"captcha": "managed_challenge",
"ban": "block",
"js_challenge": "js_challenge",
}
Expand Down
14 changes: 7 additions & 7 deletions cloudflare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func Test_classifyDecisionsByAction(t *testing.T) {
"block": {
&decision1,
},
"challenge": {
"managed_challenge": {
&decision2,
},
},
Expand All @@ -397,8 +397,8 @@ func Test_classifyDecisionsByAction(t *testing.T) {
name: "with dups, all supported",
args: args{decisions: []*models.Decision{&decision2, &decision2dup}},
want: map[string][]*models.Decision{
"defaulted": {},
"challenge": {&decision2},
"defaulted": {},
"managed_challenge": {&decision2},
},
},
{
Expand All @@ -419,9 +419,9 @@ func Test_classifyDecisionsByAction(t *testing.T) {
decisions: []*models.Decision{&decisionUnsup, &decision1, &decision2},
},
want: map[string][]*models.Decision{
"defaulted": {},
"block": {&decision1},
"challenge": {&decision2},
"defaulted": {},
"block": {&decision1},
"managed_challenge": {&decision2},
},
},
}
Expand Down Expand Up @@ -836,7 +836,7 @@ func Test_allZonesHaveAction(t *testing.T) {
zones: []ZoneConfig{
{
ActionSet: map[string]struct{}{
"challenge": {},
"managed_challenge": {},
},
},
{
Expand Down
10 changes: 9 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func NewConfig(configPath string) (*bouncerConfig, error) {
if _, ok := validAction[account.DefaultAction]; !ok {
return nil, fmt.Errorf("account %s 's default action is invalid. %s ", account.ID, validChoiceMsg)
}

zoneUsingChallenge := make([]string, 0)
for j, zone := range account.ZoneConfigs {
config.CloudflareConfig.Accounts[i].ZoneConfigs[j].ActionSet = map[string]struct{}{}
if len(zone.Actions) == 0 {
Expand All @@ -106,6 +106,8 @@ func NewConfig(configPath string) (*bouncerConfig, error) {
for _, a := range zone.Actions {
if _, ok := validAction[a]; !ok {
return nil, fmt.Errorf("invalid actions '%s', %s", a, validChoiceMsg)
} else if a == "challenge" {
zoneUsingChallenge = append(zoneUsingChallenge, zone.ID)
}
if a == account.DefaultAction {
defaultActionIsSupported = true
Expand All @@ -122,6 +124,12 @@ func NewConfig(configPath string) (*bouncerConfig, error) {
}
zoneIdSet[zone.ID] = true
}
if len(zoneUsingChallenge) > 0 {
log.Warningf(
"zones %s uses 'challenge' action which is deprecated in favour of 'managed_challenge'. See migration guide at ",
strings.Join(zoneUsingChallenge, ", "),
)
}
}
/*Configure logging*/
if err = types.SetDefaultLoggerConfig(config.LogMode, config.LogDir, config.LogLevel, 0, 0, 0, nil); err != nil {
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func main() {
}

if !*onlySetup && !*delete {
log.Infof("Starting %s %s", name, version.VersionStr())
csLAPI = &csbouncer.StreamBouncer{
APIKey: conf.CrowdSecLAPIKey,
APIUrl: conf.CrowdSecLAPIUrl,
Expand Down

0 comments on commit 7be5b1c

Please sign in to comment.