Skip to content

Commit

Permalink
Merge pull request #2833 from tlimoncelli/tlim_ruleset
Browse files Browse the repository at this point in the history
feature(Ruleset): Add DeleteRulesetRule()
  • Loading branch information
jacobbednarz authored Aug 9, 2024
2 parents 05d4578 + 4ebdf6a commit 5dc300a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/2833.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
rulesets: Add `DeleteRulesetRule`
```
26 changes: 26 additions & 0 deletions rulesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,11 @@ type UpdateEntrypointRulesetParams struct {
Rules []RulesetRule `json:"rules"`
}

type DeleteRulesetRuleParams struct {
rulesetID string `json:"-"`
rulesetRuleID string `json:"-"`
}

// ListRulesets lists all Rulesets in a given zone or account depending on the
// ResourceContainer type provided.
//
Expand Down Expand Up @@ -844,6 +849,27 @@ func (api *API) UpdateRuleset(ctx context.Context, rc *ResourceContainer, params
return result.Result, nil
}

// DeleteRulesetRule removes a ruleset rule based on the ruleset ID +
// ruleset rule ID.
//
// API reference: https://developers.cloudflare.com/api/operations/deleteZoneRulesetRule
func (api *API) DeleteRulesetRule(ctx context.Context, rc *ResourceContainer, params DeleteRulesetRuleParams) error {
uri := fmt.Sprintf("/%s/%s/rulesets/%s/rules/%s", rc.Level, rc.Identifier, params.rulesetID, params.rulesetRuleID)
res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil)
if err != nil {
return err
}

// The API is not implementing the standard response blob but returns an
// empty response (204) in case of a success. So we are checking for the
// response body size here.
if len(res) > 0 {
return fmt.Errorf(errMakeRequestError+": %w", errors.New(string(res)))
}

return nil
}

// GetEntrypointRuleset returns an entry point ruleset base on the phase.
//
// API reference: https://developers.cloudflare.com/api/operations/getAccountEntrypointRuleset
Expand Down

0 comments on commit 5dc300a

Please sign in to comment.