Repository: cloudflare/cloudflare-go
Pull request #1261 (2023-04-05 16:23:50)

Added support for `http_response_compress` phase and `compress_response` action.

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.
codecov-commenter: ## [Codecov](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1261?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare) Report
> Merging [#1261](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1261?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare) (03020cc) into [master](https://codecov.io/gh/cloudflare/cloudflare-go/commit/0c3db86282352878154a63c9bc67764dfded0780?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare) (0c3db86) will **increase** coverage by `0.06%`.
> The diff coverage is `45.16%`.

```diff
@@            Coverage Diff             @@
##           master    #1261      +/-   ##
==========================================
+ Coverage   49.23%   49.30%   +0.06%     
==========================================
  Files         131      131              
  Lines       12665    12688      +23     
==========================================
+ Hits         6236     6256      +20     
+ Misses       4988     4983       -5     
- Partials     1441     1449       +8     
```


| [Impacted Files](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1261?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare) | Coverage Δ | |
|---|---|---|
| [access\_policy.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1261?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-YWNjZXNzX3BvbGljeS5nbw==) | `76.31% <ø> (ø)` | |
| [errors.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1261?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-ZXJyb3JzLmdv) | `40.78% <ø> (ø)` | |
| [rulesets.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1261?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-cnVsZXNldHMuZ28=) | `34.64% <0.00%> (-0.35%)` | :arrow_down: |
| [ssl.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1261?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-c3NsLmdv) | `72.72% <ø> (ø)` | |
| [zone.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1261?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-em9uZS5nbw==) | `41.70% <50.00%> (+2.59%)` | :arrow_up: |

... and [1 file with indirect coverage changes](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1261/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare)

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare)


Patch:
diff --git a/.changelog/1260.txt b/.changelog/1260.txt
deleted file mode 100644
index 806345d46..000000000
--- a/.changelog/1260.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-```release-note:enhancement
-access: Add `auto_redirect_to_identity` flag to Access organizations
-```
diff --git a/.changelog/1261.txt b/.changelog/1261.txt
new file mode 100644
index 000000000..efa0a01ba
--- /dev/null
+++ b/.changelog/1261.txt
@@ -0,0 +1,7 @@
+```release-note:enhancement
+rulesets: add support for the `http_response_compression` phase
+```
+
+```release-note:enhancement
+rulesets: add support for the `compress_response` action
+```
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 836204323..2ac6b20f4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,6 @@
 
 ENHANCEMENTS:
 
-* access: Add `auto_redirect_to_identity` flag to Access organizations ([#1260](https://github.com/cloudflare/cloudflare-go/issues/1260))
 * access: Add `isolation_required` flag to Access policies ([#1258](https://github.com/cloudflare/cloudflare-go/issues/1258))
 * rulesets: add support for add operation to HTTP header configuration ([#1253](https://github.com/cloudflare/cloudflare-go/issues/1253))
 
diff --git a/access_organization.go b/access_organization.go
index ff2fef9de..f4de4a7b6 100644
--- a/access_organization.go
+++ b/access_organization.go
@@ -18,7 +18,6 @@ type AccessOrganization struct {
 	IsUIReadOnly                   *bool                         `json:"is_ui_read_only,omitempty"`
 	UIReadOnlyToggleReason         string                        `json:"ui_read_only_toggle_reason,omitempty"`
 	UserSeatExpirationInactiveTime string                        `json:"user_seat_expiration_inactive_time,omitempty"`
-	AutoRedirectToIdentity         *bool                         `json:"auto_redirect_to_identity,omitempty"`
 }
 
 // AccessOrganizationLoginDesign represents the login design options.
diff --git a/rulesets.go b/rulesets.go
index 29aa2dfd6..8110d0206 100644
--- a/rulesets.go
+++ b/rulesets.go
@@ -35,6 +35,7 @@ const (
 	RulesetPhaseHTTPResponseFirewallManaged         RulesetPhase = "http_response_firewall_managed"
 	RulesetPhaseHTTPResponseHeadersTransform        RulesetPhase = "http_response_headers_transform"
 	RulesetPhaseHTTPResponseHeadersTransformManaged RulesetPhase = "http_response_headers_transform_managed"
+	RulesetPhaseHTTPResponseCompression             RulesetPhase = "http_response_compression"
 	RulesetPhaseMagicTransit                        RulesetPhase = "magic_transit"
 	RulesetPhaseRateLimit                           RulesetPhase = "http_ratelimit"
 	RulesetPhaseSuperBotFightMode                   RulesetPhase = "http_request_sbfm"
@@ -58,6 +59,7 @@ const (
 	RulesetRuleActionSetConfig            RulesetRuleAction = "set_config"
 	RulesetRuleActionServeError           RulesetRuleAction = "serve_error"
 	RulesetRuleActionSkip                 RulesetRuleAction = "skip"
+	RulesetRuleActionCompressResponse     RulesetRuleAction = "compress_response"
 
 	RulesetActionParameterProductBIC           RulesetActionParameterProduct = "bic"
 	RulesetActionParameterProductHOT           RulesetActionParameterProduct = "hot"
@@ -106,6 +108,7 @@ func RulesetPhaseValues() []string {
 		string(RulesetPhaseHTTPResponseFirewallManaged),
 		string(RulesetPhaseHTTPResponseHeadersTransform),
 		string(RulesetPhaseHTTPResponseHeadersTransformManaged),
+		string(RulesetPhaseHTTPResponseCompression),
 		string(RulesetPhaseMagicTransit),
 		string(RulesetPhaseRateLimit),
 		string(RulesetPhaseSuperBotFightMode),
@@ -135,6 +138,7 @@ func RulesetRuleActionValues() []string {
 		string(RulesetRuleActionSetConfig),
 		string(RulesetRuleActionServeError),
 		string(RulesetRuleActionSkip),
+		string(RulesetRuleActionCompressResponse),
 	}
 }
 
@@ -205,53 +209,54 @@ 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"`
-	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"`
-	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"`
+	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"`
+	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"`
+	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
@@ -451,6 +456,12 @@ type RulesetRuleActionParametersSni struct {
 	Value string `json:"value"`
 }
 
+// RulesetRuleActionParametersCompressionAlgorithm defines a compression
+// algorithm for the compress_response action.
+type RulesetRuleActionParametersCompressionAlgorithm struct {
+	Name string `json:"name"`
+}
+
 type Polish int
 
 const (


Test patch:
diff --git a/access_organization_test.go b/access_organization_test.go
index 3ea79970a..7d6cfa60e 100644
--- a/access_organization_test.go
+++ b/access_organization_test.go
@@ -28,7 +28,6 @@ func TestAccessOrganization(t *testing.T) {
 				"auth_domain": "test.cloudflareaccess.com",
 				"is_ui_read_only": false,
 				"user_seat_expiration_inactive_time": "720h",
-				"auto_redirect_to_identity": true,
 				"login_design": {
 					"background_color": "#c5ed1b",
 					"logo_path": "https://example.com/logo.png",
@@ -58,7 +57,6 @@ func TestAccessOrganization(t *testing.T) {
 		},
 		IsUIReadOnly:                   BoolPtr(false),
 		UserSeatExpirationInactiveTime: "720h",
-		AutoRedirectToIdentity:         BoolPtr(true),
 	}
 
 	mux.HandleFunc("/accounts/"+testAccountID+"/access/organizations", handler)
diff --git a/rulesets_test.go b/rulesets_test.go
index 32a0774c7..c126c7239 100644
--- a/rulesets_test.go
+++ b/rulesets_test.go
@@ -554,6 +554,86 @@ func TestGetRuleset_RedirectFromValue(t *testing.T) {
 	}
 }
 
+func TestGetRuleset_CompressResponse(t *testing.T) {
+	setup()
+	defer teardown()
+
+	handler := func(w http.ResponseWriter, r *http.Request) {
+		assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method)
+		w.Header().Set("content-type", "application/json")
+		fmt.Fprint(w, `{
+      "result": {
+        "id": "70339d97bdb34195bbf054b1ebe81f76",
+        "name": "Cloudflare compress response ruleset",
+        "description": "This ruleset provides response compression rules",
+        "kind": "zone",
+        "version": "1",
+        "rules": [
+          {
+            "id": "78723a9e0c7c4c6dbec5684cb766231d",
+            "version": "1",
+            "action": "compress_response",
+            "action_parameters": {
+				"algorithms": [ { "name": "brotli" }, { "name": "default" } ]
+            },
+			"description": "Compress response rule",
+			"last_updated": "2020-12-18T09:28:09.655749Z",
+			"ref": "272936dc447b41fe976255ff6b768ec0",
+			"enabled": true
+          }
+        ],
+        "last_updated": "2020-12-18T09:28:09.655749Z",
+        "phase": "http_response_compression"
+      },
+      "success": true,
+      "errors": [],
+      "messages": []
+    }`)
+	}
+
+	mux.HandleFunc("/accounts/"+testAccountID+"/rulesets/b232b534beea4e00a21dcbb7a8a545e9", handler)
+	mux.HandleFunc("/zones/"+testZoneID+"/rulesets/b232b534beea4e00a21dcbb7a8a545e9", handler)
+
+	lastUpdated, _ := time.Parse(time.RFC3339, "2020-12-18T09:28:09.655749Z")
+
+	rules := []RulesetRule{{
+		ID:      "78723a9e0c7c4c6dbec5684cb766231d",
+		Version: StringPtr("1"),
+		Action:  string(RulesetRuleActionCompressResponse),
+		ActionParameters: &RulesetRuleActionParameters{
+			Algorithms: []RulesetRuleActionParametersCompressionAlgorithm{
+				{Name: "brotli"},
+				{Name: "default"},
+			},
+		},
+		Description: "Compress response rule",
+		LastUpdated: &lastUpdated,
+		Ref:         "272936dc447b41fe976255ff6b768ec0",
+		Enabled:     BoolPtr(true),
+	}}
+
+	want := Ruleset{
+		ID:          "70339d97bdb34195bbf054b1ebe81f76",
+		Name:        "Cloudflare compress response ruleset",
+		Description: "This ruleset provides response compression rules",
+		Kind:        string(RulesetKindZone),
+		Version:     StringPtr("1"),
+		LastUpdated: &lastUpdated,
+		Phase:       string(RulesetPhaseHTTPResponseCompression),
+		Rules:       rules,
+	}
+
+	zoneActual, err := client.GetZoneRuleset(context.Background(), testZoneID, "b232b534beea4e00a21dcbb7a8a545e9")
+	if assert.NoError(t, err) {
+		assert.Equal(t, want, zoneActual)
+	}
+
+	accountActual, err := client.GetAccountRuleset(context.Background(), testAccountID, "b232b534beea4e00a21dcbb7a8a545e9")
+	if assert.NoError(t, err) {
+		assert.Equal(t, want, accountActual)
+	}
+}
+
 func TestCreateRuleset(t *testing.T) {
 	setup()
 	defer teardown()