Repository: cloudflare/cloudflare-go
Pull request #1375 (2023-08-25 16:43:03)

Add support for additional cacheable ports in the Rulesets API
<!-- 
Provide a general summary of your changes in the title above. You should
remove this overview, any sections and any section descriptions you
don't need below before submitting. There isn't a strict requirement to
use this template if you can structure your description and still cover
these points. 
-->

## Description

Adds support for the usage of the `additional_cacheable_ports` field which has been added to the rulesets API. This allows the origin to pass content back on [non-standard ports ](https://developers.cloudflare.com/fundamentals/get-started/reference/network-ports/) that are eligible for caching.

<!--
Describe your changes in detail through motivation and context. Why is
this change required? What problem does it solve? If it fixes an open
issue, link to the issue using GitHub's closing issues keywords[1].
-->
## Has your change been tested?

Thoroughly tested at the API level, unit tests modifications included for the library.

<!--
Explain how the change has been tested and what you ran to confirm your
change affects other parts of the code. Automated tests are generally
expected and changes without tests should explain why they aren't
required.
-->

## Screenshots (if appropriate):

## 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.
- [ ] 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/



Patch:
diff --git a/.changelog/1375.txt b/.changelog/1375.txt
new file mode 100644
index 000000000..a7d2ae9c7
--- /dev/null
+++ b/.changelog/1375.txt
@@ -0,0 +1,3 @@
+```release_note:enhancement
+rulesets: Add support for Additional Cacheable Ports configuration via the Rulesets/Cache Rules API
+```
\ No newline at end of file
diff --git a/rulesets.go b/rulesets.go
index cfa725aa8..d000ea7bb 100644
--- a/rulesets.go
+++ b/rulesets.go
@@ -206,56 +206,57 @@ type RulesetActionParametersLogCustomField struct {
 // RulesetRuleActionParameters specifies the action parameters for a Ruleset
 // rule.
 type RulesetRuleActionParameters struct {
-	ID                      string                                            `json:"id,omitempty"`
-	Ruleset                 string                                            `json:"ruleset,omitempty"`
-	Rulesets                []string                                          `json:"rulesets,omitempty"`
-	Rules                   map[string][]string                               `json:"rules,omitempty"`
-	Increment               int                                               `json:"increment,omitempty"`
-	URI                     *RulesetRuleActionParametersURI                   `json:"uri,omitempty"`
-	Headers                 map[string]RulesetRuleActionParametersHTTPHeader  `json:"headers,omitempty"`
-	Products                []string                                          `json:"products,omitempty"`
-	Phases                  []string                                          `json:"phases,omitempty"`
-	Overrides               *RulesetRuleActionParametersOverrides             `json:"overrides,omitempty"`
-	MatchedData             *RulesetRuleActionParametersMatchedData           `json:"matched_data,omitempty"`
-	Version                 *string                                           `json:"version,omitempty"`
-	Response                *RulesetRuleActionParametersBlockResponse         `json:"response,omitempty"`
-	HostHeader              string                                            `json:"host_header,omitempty"`
-	Origin                  *RulesetRuleActionParametersOrigin                `json:"origin,omitempty"`
-	SNI                     *RulesetRuleActionParametersSni                   `json:"sni,omitempty"`
-	RequestFields           []RulesetActionParametersLogCustomField           `json:"request_fields,omitempty"`
-	ResponseFields          []RulesetActionParametersLogCustomField           `json:"response_fields,omitempty"`
-	CookieFields            []RulesetActionParametersLogCustomField           `json:"cookie_fields,omitempty"`
-	Cache                   *bool                                             `json:"cache,omitempty"`
-	EdgeTTL                 *RulesetRuleActionParametersEdgeTTL               `json:"edge_ttl,omitempty"`
-	BrowserTTL              *RulesetRuleActionParametersBrowserTTL            `json:"browser_ttl,omitempty"`
-	ServeStale              *RulesetRuleActionParametersServeStale            `json:"serve_stale,omitempty"`
-	Content                 string                                            `json:"content,omitempty"`
-	ContentType             string                                            `json:"content_type,omitempty"`
-	StatusCode              uint16                                            `json:"status_code,omitempty"`
-	RespectStrongETags      *bool                                             `json:"respect_strong_etags,omitempty"`
-	CacheKey                *RulesetRuleActionParametersCacheKey              `json:"cache_key,omitempty"`
-	OriginCacheControl      *bool                                             `json:"origin_cache_control,omitempty"`
-	OriginErrorPagePassthru *bool                                             `json:"origin_error_page_passthru,omitempty"`
-	FromList                *RulesetRuleActionParametersFromList              `json:"from_list,omitempty"`
-	FromValue               *RulesetRuleActionParametersFromValue             `json:"from_value,omitempty"`
-	AutomaticHTTPSRewrites  *bool                                             `json:"automatic_https_rewrites,omitempty"`
-	AutoMinify              *RulesetRuleActionParametersAutoMinify            `json:"autominify,omitempty"`
-	BrowserIntegrityCheck   *bool                                             `json:"bic,omitempty"`
-	DisableApps             *bool                                             `json:"disable_apps,omitempty"`
-	DisableZaraz            *bool                                             `json:"disable_zaraz,omitempty"`
-	DisableRailgun          *bool                                             `json:"disable_railgun,omitempty"`
-	EmailObfuscation        *bool                                             `json:"email_obfuscation,omitempty"`
-	Mirage                  *bool                                             `json:"mirage,omitempty"`
-	OpportunisticEncryption *bool                                             `json:"opportunistic_encryption,omitempty"`
-	Polish                  *Polish                                           `json:"polish,omitempty"`
-	ReadTimeout             *uint                                             `json:"read_timeout,omitempty"`
-	RocketLoader            *bool                                             `json:"rocket_loader,omitempty"`
-	SecurityLevel           *SecurityLevel                                    `json:"security_level,omitempty"`
-	ServerSideExcludes      *bool                                             `json:"server_side_excludes,omitempty"`
-	SSL                     *SSL                                              `json:"ssl,omitempty"`
-	SXG                     *bool                                             `json:"sxg,omitempty"`
-	HotLinkProtection       *bool                                             `json:"hotlink_protection,omitempty"`
-	Algorithms              []RulesetRuleActionParametersCompressionAlgorithm `json:"algorithms,omitempty"`
+	ID                       string                                            `json:"id,omitempty"`
+	Ruleset                  string                                            `json:"ruleset,omitempty"`
+	Rulesets                 []string                                          `json:"rulesets,omitempty"`
+	Rules                    map[string][]string                               `json:"rules,omitempty"`
+	Increment                int                                               `json:"increment,omitempty"`
+	URI                      *RulesetRuleActionParametersURI                   `json:"uri,omitempty"`
+	Headers                  map[string]RulesetRuleActionParametersHTTPHeader  `json:"headers,omitempty"`
+	Products                 []string                                          `json:"products,omitempty"`
+	Phases                   []string                                          `json:"phases,omitempty"`
+	Overrides                *RulesetRuleActionParametersOverrides             `json:"overrides,omitempty"`
+	MatchedData              *RulesetRuleActionParametersMatchedData           `json:"matched_data,omitempty"`
+	Version                  *string                                           `json:"version,omitempty"`
+	Response                 *RulesetRuleActionParametersBlockResponse         `json:"response,omitempty"`
+	HostHeader               string                                            `json:"host_header,omitempty"`
+	Origin                   *RulesetRuleActionParametersOrigin                `json:"origin,omitempty"`
+	SNI                      *RulesetRuleActionParametersSni                   `json:"sni,omitempty"`
+	RequestFields            []RulesetActionParametersLogCustomField           `json:"request_fields,omitempty"`
+	ResponseFields           []RulesetActionParametersLogCustomField           `json:"response_fields,omitempty"`
+	CookieFields             []RulesetActionParametersLogCustomField           `json:"cookie_fields,omitempty"`
+	Cache                    *bool                                             `json:"cache,omitempty"`
+	AdditionalCacheablePorts []int                                             `json:"additional_cacheable_ports,omitempty"`
+	EdgeTTL                  *RulesetRuleActionParametersEdgeTTL               `json:"edge_ttl,omitempty"`
+	BrowserTTL               *RulesetRuleActionParametersBrowserTTL            `json:"browser_ttl,omitempty"`
+	ServeStale               *RulesetRuleActionParametersServeStale            `json:"serve_stale,omitempty"`
+	Content                  string                                            `json:"content,omitempty"`
+	ContentType              string                                            `json:"content_type,omitempty"`
+	StatusCode               uint16                                            `json:"status_code,omitempty"`
+	RespectStrongETags       *bool                                             `json:"respect_strong_etags,omitempty"`
+	CacheKey                 *RulesetRuleActionParametersCacheKey              `json:"cache_key,omitempty"`
+	OriginCacheControl       *bool                                             `json:"origin_cache_control,omitempty"`
+	OriginErrorPagePassthru  *bool                                             `json:"origin_error_page_passthru,omitempty"`
+	FromList                 *RulesetRuleActionParametersFromList              `json:"from_list,omitempty"`
+	FromValue                *RulesetRuleActionParametersFromValue             `json:"from_value,omitempty"`
+	AutomaticHTTPSRewrites   *bool                                             `json:"automatic_https_rewrites,omitempty"`
+	AutoMinify               *RulesetRuleActionParametersAutoMinify            `json:"autominify,omitempty"`
+	BrowserIntegrityCheck    *bool                                             `json:"bic,omitempty"`
+	DisableApps              *bool                                             `json:"disable_apps,omitempty"`
+	DisableZaraz             *bool                                             `json:"disable_zaraz,omitempty"`
+	DisableRailgun           *bool                                             `json:"disable_railgun,omitempty"`
+	EmailObfuscation         *bool                                             `json:"email_obfuscation,omitempty"`
+	Mirage                   *bool                                             `json:"mirage,omitempty"`
+	OpportunisticEncryption  *bool                                             `json:"opportunistic_encryption,omitempty"`
+	Polish                   *Polish                                           `json:"polish,omitempty"`
+	ReadTimeout              *uint                                             `json:"read_timeout,omitempty"`
+	RocketLoader             *bool                                             `json:"rocket_loader,omitempty"`
+	SecurityLevel            *SecurityLevel                                    `json:"security_level,omitempty"`
+	ServerSideExcludes       *bool                                             `json:"server_side_excludes,omitempty"`
+	SSL                      *SSL                                              `json:"ssl,omitempty"`
+	SXG                      *bool                                             `json:"sxg,omitempty"`
+	HotLinkProtection        *bool                                             `json:"hotlink_protection,omitempty"`
+	Algorithms               []RulesetRuleActionParametersCompressionAlgorithm `json:"algorithms,omitempty"`
 }
 
 // RulesetRuleActionParametersFromList holds the FromList struct for


Test patch:
diff --git a/rulesets_test.go b/rulesets_test.go
index 91c269f1f..16fafeedd 100644
--- a/rulesets_test.go
+++ b/rulesets_test.go
@@ -241,6 +241,7 @@ 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
@@ -326,9 +327,10 @@ func TestGetRuleset_SetCacheSettings(t *testing.T) {
 					},
 				},
 			},
-			OriginCacheControl:      BoolPtr(true),
-			ReadTimeout:             UintPtr(1000),
-			OriginErrorPagePassthru: BoolPtr(true),
+			AdditionalCacheablePorts: []int{1, 2, 3, 4},
+			OriginCacheControl:       BoolPtr(true),
+			ReadTimeout:              UintPtr(1000),
+			OriginErrorPagePassthru:  BoolPtr(true),
 		},
 		Description: "Set all available cache settings in one rule",
 		LastUpdated: &lastUpdated,