Skip to content

Commit

Permalink
fix(waiting_room_rules): define body_param_name for bulk rules endp…
Browse files Browse the repository at this point in the history
…oint (#3592)
  • Loading branch information
stainless-app[bot] authored Nov 12, 2024
1 parent 8792f7e commit 9e7bfd9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
38 changes: 23 additions & 15 deletions waiting_rooms/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,16 @@ func (r WaitingRoomRuleAction) IsKnown() bool {
type RuleNewParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
Rules RuleNewParamsRules `json:"rules,required"`
}

func (r RuleNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Rules)
}

type RuleNewParamsRules struct {
// The action to take when the expression matches.
Action param.Field[RuleNewParamsAction] `json:"action,required"`
Action param.Field[RuleNewParamsRulesAction] `json:"action,required"`
// Criteria defining when there is a match for the current rule.
Expression param.Field[string] `json:"expression,required"`
// The description of the rule.
Expand All @@ -216,20 +224,20 @@ type RuleNewParams struct {
Enabled param.Field[bool] `json:"enabled"`
}

func (r RuleNewParams) MarshalJSON() (data []byte, err error) {
func (r RuleNewParamsRules) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// The action to take when the expression matches.
type RuleNewParamsAction string
type RuleNewParamsRulesAction string

const (
RuleNewParamsActionBypassWaitingRoom RuleNewParamsAction = "bypass_waiting_room"
RuleNewParamsRulesActionBypassWaitingRoom RuleNewParamsRulesAction = "bypass_waiting_room"
)

func (r RuleNewParamsAction) IsKnown() bool {
func (r RuleNewParamsRulesAction) IsKnown() bool {
switch r {
case RuleNewParamsActionBypassWaitingRoom:
case RuleNewParamsRulesActionBypassWaitingRoom:
return true
}
return false
Expand Down Expand Up @@ -314,16 +322,16 @@ func (r ruleNewResponseEnvelopeResultInfoJSON) RawJSON() string {
type RuleUpdateParams struct {
// Identifier
ZoneID param.Field[string] `path:"zone_id,required"`
Body []RuleUpdateParamsBody `json:"body,required"`
Rules []RuleUpdateParamsRule `json:"rules,required"`
}

func (r RuleUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Body)
return apijson.MarshalRoot(r.Rules)
}

type RuleUpdateParamsBody struct {
type RuleUpdateParamsRule struct {
// The action to take when the expression matches.
Action param.Field[RuleUpdateParamsBodyAction] `json:"action,required"`
Action param.Field[RuleUpdateParamsRulesAction] `json:"action,required"`
// Criteria defining when there is a match for the current rule.
Expression param.Field[string] `json:"expression,required"`
// The description of the rule.
Expand All @@ -332,20 +340,20 @@ type RuleUpdateParamsBody struct {
Enabled param.Field[bool] `json:"enabled"`
}

func (r RuleUpdateParamsBody) MarshalJSON() (data []byte, err error) {
func (r RuleUpdateParamsRule) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}

// The action to take when the expression matches.
type RuleUpdateParamsBodyAction string
type RuleUpdateParamsRulesAction string

const (
RuleUpdateParamsBodyActionBypassWaitingRoom RuleUpdateParamsBodyAction = "bypass_waiting_room"
RuleUpdateParamsRulesActionBypassWaitingRoom RuleUpdateParamsRulesAction = "bypass_waiting_room"
)

func (r RuleUpdateParamsBodyAction) IsKnown() bool {
func (r RuleUpdateParamsRulesAction) IsKnown() bool {
switch r {
case RuleUpdateParamsBodyActionBypassWaitingRoom:
case RuleUpdateParamsRulesActionBypassWaitingRoom:
return true
}
return false
Expand Down
20 changes: 11 additions & 9 deletions waiting_rooms/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ func TestRuleNewWithOptionalParams(t *testing.T) {
context.TODO(),
"699d98642c564d2e855e9661899b7252",
waiting_rooms.RuleNewParams{
ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
Action: cloudflare.F(waiting_rooms.RuleNewParamsActionBypassWaitingRoom),
Expression: cloudflare.F("ip.src in {10.20.30.40}"),
Description: cloudflare.F("allow all traffic from 10.20.30.40"),
Enabled: cloudflare.F(true),
ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
Rules: waiting_rooms.RuleNewParamsRules{
Action: cloudflare.F(waiting_rooms.RuleNewParamsRulesActionBypassWaitingRoom),
Expression: cloudflare.F("ip.src in {10.20.30.40}"),
Description: cloudflare.F("allow all traffic from 10.20.30.40"),
Enabled: cloudflare.F(true),
},
},
)
if err != nil {
Expand Down Expand Up @@ -65,18 +67,18 @@ func TestRuleUpdate(t *testing.T) {
"699d98642c564d2e855e9661899b7252",
waiting_rooms.RuleUpdateParams{
ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
Body: []waiting_rooms.RuleUpdateParamsBody{{
Action: cloudflare.F(waiting_rooms.RuleUpdateParamsBodyActionBypassWaitingRoom),
Rules: []waiting_rooms.RuleUpdateParamsRule{{
Action: cloudflare.F(waiting_rooms.RuleUpdateParamsRulesActionBypassWaitingRoom),
Expression: cloudflare.F("ip.src in {10.20.30.40}"),
Description: cloudflare.F("allow all traffic from 10.20.30.40"),
Enabled: cloudflare.F(true),
}, {
Action: cloudflare.F(waiting_rooms.RuleUpdateParamsBodyActionBypassWaitingRoom),
Action: cloudflare.F(waiting_rooms.RuleUpdateParamsRulesActionBypassWaitingRoom),
Expression: cloudflare.F("ip.src in {10.20.30.40}"),
Description: cloudflare.F("allow all traffic from 10.20.30.40"),
Enabled: cloudflare.F(true),
}, {
Action: cloudflare.F(waiting_rooms.RuleUpdateParamsBodyActionBypassWaitingRoom),
Action: cloudflare.F(waiting_rooms.RuleUpdateParamsRulesActionBypassWaitingRoom),
Expression: cloudflare.F("ip.src in {10.20.30.40}"),
Description: cloudflare.F("allow all traffic from 10.20.30.40"),
Enabled: cloudflare.F(true),
Expand Down

0 comments on commit 9e7bfd9

Please sign in to comment.