From 1de2ed68ad71a12c350b3530d70d4536d3471a67 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Wed, 7 Aug 2024 09:42:28 -0400 Subject: [PATCH 1/6] feature(Ruleset): Add DeleteRulesetRule() --- rulesets.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/rulesets.go b/rulesets.go index 8b1ad430a56..b67c3889896 100644 --- a/rulesets.go +++ b/rulesets.go @@ -886,3 +886,24 @@ func (api *API) UpdateEntrypointRuleset(ctx context.Context, rc *ResourceContain 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, rulesetID, rulesetRuleID string) error { + uri := fmt.Sprintf("/%s/%s/rulesets/%s/rules/%s", rc.Level, rc.Identifier, rulesetID, 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 +} From 28cd78476f47d2ffd4351e037060036bcf48d2f0 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Wed, 7 Aug 2024 09:55:18 -0400 Subject: [PATCH 2/6] move fn to match code style --- rulesets.go | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/rulesets.go b/rulesets.go index b67c3889896..80d91996d9c 100644 --- a/rulesets.go +++ b/rulesets.go @@ -844,6 +844,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, rulesetID, rulesetRuleID string) error { + uri := fmt.Sprintf("/%s/%s/rulesets/%s/rules/%s", rc.Level, rc.Identifier, rulesetID, 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 @@ -886,24 +907,3 @@ func (api *API) UpdateEntrypointRuleset(ctx context.Context, rc *ResourceContain 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, rulesetID, rulesetRuleID string) error { - uri := fmt.Sprintf("/%s/%s/rulesets/%s/rules/%s", rc.Level, rc.Identifier, rulesetID, 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 -} From a8304bf53b4f2153b0df56f8d4fdea3347ee2c20 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Wed, 7 Aug 2024 14:14:14 -0400 Subject: [PATCH 3/6] Add changelog --- .changelog/2833.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/2833.txt diff --git a/.changelog/2833.txt b/.changelog/2833.txt new file mode 100644 index 00000000000..25c9976db3d --- /dev/null +++ b/.changelog/2833.txt @@ -0,0 +1,2 @@ +release-note:enhancement +Add DeleteRulesetRule() From 1f9a88425c06fec96d00bd3829173b95c030059f Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Wed, 7 Aug 2024 14:19:01 -0400 Subject: [PATCH 4/6] Update changelog --- .changelog/2833.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/2833.txt b/.changelog/2833.txt index 25c9976db3d..2cdf8101e80 100644 --- a/.changelog/2833.txt +++ b/.changelog/2833.txt @@ -1,2 +1,2 @@ release-note:enhancement -Add DeleteRulesetRule() +rulesets: Add DeleteRulesetRule() function From 0ad1a1e016a751ad36eca2ef42a52a587e3a33de Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Thu, 8 Aug 2024 14:15:26 +1000 Subject: [PATCH 5/6] update changelog --- .changelog/2833.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.changelog/2833.txt b/.changelog/2833.txt index 2cdf8101e80..00633a04e66 100644 --- a/.changelog/2833.txt +++ b/.changelog/2833.txt @@ -1,2 +1,3 @@ -release-note:enhancement -rulesets: Add DeleteRulesetRule() function +```release-note:enhancement +rulesets: Add `DeleteRulesetRule` +``` From 4ebdf6a694c529e0a603d3a1d98cb38759c28021 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Fri, 9 Aug 2024 12:58:37 +1000 Subject: [PATCH 6/6] refactor: shuffle params into a struct --- rulesets.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rulesets.go b/rulesets.go index 80d91996d9c..b58a4eec822 100644 --- a/rulesets.go +++ b/rulesets.go @@ -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. // @@ -848,8 +853,8 @@ func (api *API) UpdateRuleset(ctx context.Context, rc *ResourceContainer, params // ruleset rule ID. // // API reference: https://developers.cloudflare.com/api/operations/deleteZoneRulesetRule -func (api *API) DeleteRulesetRule(ctx context.Context, rc *ResourceContainer, rulesetID, rulesetRuleID string) error { - uri := fmt.Sprintf("/%s/%s/rulesets/%s/rules/%s", rc.Level, rc.Identifier, rulesetID, rulesetRuleID) +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