Skip to content

Commit

Permalink
MINOR: site_rule: add support for browserChallenge
Browse files Browse the repository at this point in the history
This commit adds support for the `browserChallenge` action type within a
Site Rule. Specifically, it documents that `browserChallenge` is
available with action types. It also adds support for the
`allowInteractive` boolean, which allows for toggling between
non-interactive and interactive challenges.

This commit depends on signalsciences/go-sigsci#60
  • Loading branch information
daniel-corbett committed Mar 15, 2024
1 parent beaaffc commit 102bc9d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion docs/resources/site_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ Optional:

Required:

- `type` (String) (block, allow, excludeSignal, addSignal) (rateLimit rule valid values: logRequest, blockSignal)
- `type` (String) (addSignal, allow, block, browserChallenge, excludeSignal) (rateLimit rule valid values: logRequest, blockSignal)

Optional:

- `allow_interactive` (Boolean) Allows toggling between a non-interactive and interactive browser challenge. Only valid with the 'browserChallenge' action type.
- `redirect_url` (String) URL to redirect to when blocking response code is set to 301 or 302
- `response_code` (Number) HTTP code agent for agent to respond with. range: 301, 302, or 400-599, defaults to '406' if not provided. Only valid with the 'block' action type.
- `signal` (String) signal id to tag
Expand Down
18 changes: 14 additions & 4 deletions provider/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,17 @@ func expandRuleActions(actionsResource *schema.Set) []sigsci.Action {
redirectURL = castElement["redirect_url"].(string)
}

var allowInteractive bool
if castElement["allow_interactive"] != nil {
allowInteractive = castElement["allow_interactive"].(bool)
}

a := sigsci.Action{
Type: castElement["type"].(string),
Signal: signal,
ResponseCode: responseCode,
RedirectURL: redirectURL,
Type: castElement["type"].(string),
Signal: signal,
ResponseCode: responseCode,
RedirectURL: redirectURL,
AllowInteractive: allowInteractive,

Check failure on line 440 in provider/lib.go

View workflow job for this annotation

GitHub Actions / build

unknown field AllowInteractive in struct literal of type sigsci.Action
}
actions = append(actions, a)
}
Expand Down Expand Up @@ -526,6 +532,10 @@ func flattenRuleActions(actions []sigsci.Action, customResponseCode bool) []inte
if action.ResponseCode == 301 || action.ResponseCode == 302 {
actionMap["redirect_url"] = action.RedirectURL
}

if action.AllowInteractive {

Check failure on line 536 in provider/lib.go

View workflow job for this annotation

GitHub Actions / build

action.AllowInteractive undefined (type sigsci.Action has no field or method AllowInteractive)
actionMap["allow_interactive"] = action.AllowInteractive

Check failure on line 537 in provider/lib.go

View workflow job for this annotation

GitHub Actions / build

action.AllowInteractive undefined (type sigsci.Action has no field or method AllowInteractive)
}
}
actionsMap[i] = actionMap
}
Expand Down
7 changes: 6 additions & 1 deletion provider/resource_site_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func resourceSiteRule() *schema.Resource {
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Description: "(block, allow, excludeSignal, addSignal) (rateLimit rule valid values: logRequest, blockSignal)",
Description: "(addSignal, allow, block, browserChallenge, excludeSignal) (rateLimit rule valid values: logRequest, blockSignal)",
Required: true,
},
"signal": {
Expand All @@ -83,6 +83,11 @@ func resourceSiteRule() *schema.Resource {
Optional: true,
ValidateFunc: validateActionRedirectURL,
},
"allow_interactive": {
Type: schema.TypeBool,
Description: "Allows toggling between a non-interactive and interactive browser challenge. Only valid with the 'browserChallenge' action type.",
Optional: true,
},
},
},
},
Expand Down

0 comments on commit 102bc9d

Please sign in to comment.