Repository: cloudflare/cloudflare-go
Pull request #1394 (2023-09-11 00:30:08)

Add support for Cache Reserve Configuration in the Rulesets API
Cache Reserve asset eligibility is currently just a global feature toggle. The ability to control the Cache Reserve asset eligibility via Cache Rules is a highly requested feature. This will give customers better control over their Cache Reserve costs.

## Description

Adds the ability to configure some aspects of eligibility for Cache Reserve with a Cache Rule

## Has your change been tested?

Thorough testing for the API and internally.

## Types of changes

What sort of change does your code introduce/modify?

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [x] This change is using publicly documented in [cloudflare/api-schemas](https://github.com/cloudflare/api-schemas) 
      and relies on stable APIs.

[1]: https://help.github.com/articles/closing-issues-using-keywords/


github-actions[bot]: Oops! It looks like no changelog entry is attached to this PR. Please include a release note as described in https://github.com/cloudflare/cloudflare-go/blob/master/docs/changelog-process.md.

Example: 

~~~
```release-note:TYPE
Release note
```
~~~

If you do not require a release note to be included, please add the `workflow/skip-changelog-entry` label.

Patch:
diff --git a/.changelog/1394.txt b/.changelog/1394.txt
new file mode 100644
index 000000000..c2afb6cf7
--- /dev/null
+++ b/.changelog/1394.txt
@@ -0,0 +1,3 @@
+```release_note:enhancement
+rulesets: Add support for Cache Reserve configuration via the Rulesets/Cache Rules API
+```
\ No newline at end of file
diff --git a/rulesets.go b/rulesets.go
index d000ea7bb..c8a476251 100644
--- a/rulesets.go
+++ b/rulesets.go
@@ -237,6 +237,7 @@ type RulesetRuleActionParameters struct {
 	CacheKey                 *RulesetRuleActionParametersCacheKey              `json:"cache_key,omitempty"`
 	OriginCacheControl       *bool                                             `json:"origin_cache_control,omitempty"`
 	OriginErrorPagePassthru  *bool                                             `json:"origin_error_page_passthru,omitempty"`
+	CacheReserve             *RulesetRuleActionParametersCacheReserve          `json:"cache_reserve,omitempty"`
 	FromList                 *RulesetRuleActionParametersFromList              `json:"from_list,omitempty"`
 	FromValue                *RulesetRuleActionParametersFromValue             `json:"from_value,omitempty"`
 	AutomaticHTTPSRewrites   *bool                                             `json:"automatic_https_rewrites,omitempty"`
@@ -316,6 +317,11 @@ type RulesetRuleActionParametersCacheKey struct {
 	CustomKey               *RulesetRuleActionParametersCustomKey `json:"custom_key,omitempty"`
 }
 
+type RulesetRuleActionParametersCacheReserve struct {
+	Eligible        *bool `json:"eligible,omitempty"`
+	MinimumFileSize *uint `json:"minimum_file_size,omitempty"`
+}
+
 type RulesetRuleActionParametersCustomKey struct {
 	Query  *RulesetRuleActionParametersCustomKeyQuery  `json:"query_string,omitempty"`
 	Header *RulesetRuleActionParametersCustomKeyHeader `json:"header,omitempty"`


Test patch:
diff --git a/rulesets_test.go b/rulesets_test.go
index 16fafeedd..91f432529 100644
--- a/rulesets_test.go
+++ b/rulesets_test.go
@@ -244,7 +244,11 @@ func TestGetRuleset_SetCacheSettings(t *testing.T) {
 				"additional_cacheable_ports": [1,2,3,4],
 				"origin_cache_control": true,
 				"read_timeout": 1000,
-				"origin_error_page_passthru":true
+				"origin_error_page_passthru":true,
+				"cache_reserve": {
+					"eligible": true,
+					"minimum_file_size": 1000
+				}
 			},
 			"description": "Set all available cache settings in one rule",
 			"last_updated": "2020-12-18T09:28:09.655749Z",
@@ -331,6 +335,10 @@ func TestGetRuleset_SetCacheSettings(t *testing.T) {
 			OriginCacheControl:       BoolPtr(true),
 			ReadTimeout:              UintPtr(1000),
 			OriginErrorPagePassthru:  BoolPtr(true),
+			CacheReserve: &RulesetRuleActionParametersCacheReserve{
+				Eligible:        BoolPtr(true),
+				MinimumFileSize: UintPtr(1000),
+			},
 		},
 		Description: "Set all available cache settings in one rule",
 		LastUpdated: &lastUpdated,