Repository: cloudflare/cloudflare-go
Pull request #1205 (2023-02-10 17:02:12)

Add ExcludeOfficeIPs flag for policy
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

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?

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.
- [x] 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 (api.cloudflare.com or developers.cloudflare.com) and 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/1205.txt b/.changelog/1205.txt
new file mode 100644
index 000000000..257352280
--- /dev/null
+++ b/.changelog/1205.txt
@@ -0,0 +1,3 @@
+```release-note:enhancement
+devices_policy: Add new exclude_office_ips field to policy
+```
diff --git a/devices_policy.go b/devices_policy.go
index 96d542125..2e537757e 100644
--- a/devices_policy.go
+++ b/devices_policy.go
@@ -42,6 +42,7 @@ type DeviceSettingsPolicy struct {
 	Match               *string           `json:"match"`
 	Precedence          *int              `json:"precedence"`
 	Default             bool              `json:"default"`
+	ExcludeOfficeIps    *bool             `json:"exclude_office_ips"`
 }
 
 type DeviceSettingsPolicyResponse struct {
@@ -68,6 +69,7 @@ type DeviceSettingsPolicyRequest struct {
 	Name                *string        `json:"name,omitempty"`
 	Match               *string        `json:"match,omitempty"`
 	Enabled             *bool          `json:"enabled,omitempty"`
+	ExcludeOfficeIps    *bool          `json:"exclude_office_ips"`
 }
 
 // UpdateDeviceClientCertificates controls the zero trust zone used to provision client certificates.


Test patch:
diff --git a/devices_policy_test.go b/devices_policy_test.go
index 12bd07354..ac03a752c 100644
--- a/devices_policy_test.go
+++ b/devices_policy_test.go
@@ -27,20 +27,21 @@ var (
 			{Address: "10.0.0.0/8"},
 			{Address: "100.64.0.0/10"},
 		},
-		GatewayUniqueID: StringPtr("t1235"),
-		SupportURL:      StringPtr(""),
-		CaptivePortal:   IntPtr(180),
-		AllowModeSwitch: BoolPtr(false),
-		SwitchLocked:    BoolPtr(false),
-		AllowUpdates:    BoolPtr(false),
-		AutoConnect:     IntPtr(0),
-		AllowedToLeave:  BoolPtr(true),
-		Enabled:         BoolPtr(true),
-		PolicyID:        nil,
-		Name:            nil,
-		Match:           nil,
-		Precedence:      nil,
-		Default:         true,
+		GatewayUniqueID:  StringPtr("t1235"),
+		SupportURL:       StringPtr(""),
+		CaptivePortal:    IntPtr(180),
+		AllowModeSwitch:  BoolPtr(false),
+		SwitchLocked:     BoolPtr(false),
+		AllowUpdates:     BoolPtr(false),
+		AutoConnect:      IntPtr(0),
+		AllowedToLeave:   BoolPtr(true),
+		Enabled:          BoolPtr(true),
+		PolicyID:         nil,
+		Name:             nil,
+		Match:            nil,
+		Precedence:       nil,
+		Default:          true,
+		ExcludeOfficeIps: BoolPtr(false),
 	}
 
 	nonDefaultDeviceSettingsPolicy = DeviceSettingsPolicy{
@@ -56,20 +57,21 @@ var (
 			{Address: "10.0.0.0/8"},
 			{Address: "100.64.0.0/10"},
 		},
-		GatewayUniqueID: StringPtr("t1235"),
-		SupportURL:      StringPtr(""),
-		CaptivePortal:   IntPtr(180),
-		AllowModeSwitch: BoolPtr(false),
-		SwitchLocked:    BoolPtr(false),
-		AllowUpdates:    BoolPtr(false),
-		AutoConnect:     IntPtr(0),
-		AllowedToLeave:  BoolPtr(true),
-		PolicyID:        &deviceSettingsPolicyID,
-		Enabled:         BoolPtr(true),
-		Name:            StringPtr("test"),
-		Match:           &deviceSettingsPolicyMatch,
-		Precedence:      &deviceSettingsPolicyPrecedence,
-		Default:         false,
+		GatewayUniqueID:  StringPtr("t1235"),
+		SupportURL:       StringPtr(""),
+		CaptivePortal:    IntPtr(180),
+		AllowModeSwitch:  BoolPtr(false),
+		SwitchLocked:     BoolPtr(false),
+		AllowUpdates:     BoolPtr(false),
+		AutoConnect:      IntPtr(0),
+		AllowedToLeave:   BoolPtr(true),
+		PolicyID:         &deviceSettingsPolicyID,
+		Enabled:          BoolPtr(true),
+		Name:             StringPtr("test"),
+		Match:            &deviceSettingsPolicyMatch,
+		Precedence:       &deviceSettingsPolicyPrecedence,
+		Default:          false,
+		ExcludeOfficeIps: BoolPtr(true),
 	}
 
 	defaultDeviceSettingsPolicyJson = `{
@@ -102,7 +104,8 @@ var (
 		"auto_connect": 0,
 		"allowed_to_leave": true,
 		"enabled": true,
-		"default": true
+		"default": true,
+		"exclude_office_ips":false
 	}`
 
 	nonDefaultDeviceSettingsPolicyJson = fmt.Sprintf(`{
@@ -139,7 +142,8 @@ var (
 		"name": "test",
 		"match": %#v,
 		"precedence": 10,
-		"default": false
+		"default": false,
+		"exclude_office_ips":true
 	}`, deviceSettingsPolicyID, deviceSettingsPolicyMatch)
 )