Repository: cloudflare/cloudflare-go
Pull request #2778 (2024-07-23 23:43:15)

add tunnel_protocol field to policy
## Description

Adds a new tunnel_protocol field to the policy, which ultimately allows admins to switch tunnel protocols through their policy settings.

## Has your change been tested?

Because it is just adding a new field to the various device settings policy structs, this should not affect existing uses of it. An existing test for the device policy fields has been updated to include the tunnel_protocol field to verify it's use.

## 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.
- [x] 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 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.
jacobbednarz: lgtm once we have this in the API schemas 👍 

Patch:
diff --git a/.changelog/2778.txt b/.changelog/2778.txt
new file mode 100644
index 000000000..b3e90fdc7
--- /dev/null
+++ b/.changelog/2778.txt
@@ -0,0 +1,3 @@
+```release-note:enhancement
+devices_policy: Add new tunnel_protocol field to policy
+```
diff --git a/devices_policy.go b/devices_policy.go
index 1a8b03b9d..0da365d58 100644
--- a/devices_policy.go
+++ b/devices_policy.go
@@ -59,6 +59,7 @@ type DeviceSettingsPolicy struct {
 	Description         *string           `json:"description"`
 	LANAllowMinutes     *uint             `json:"lan_allow_minutes"`
 	LANAllowSubnetSize  *uint             `json:"lan_allow_subnet_size"`
+	TunnelProtocol      *string           `json:"tunnel_protocol"`
 }
 
 type DeviceSettingsPolicyResponse struct {
@@ -89,6 +90,7 @@ type CreateDeviceSettingsPolicyParams struct {
 	Description         *string        `json:"description,omitempty"`
 	LANAllowMinutes     *uint          `json:"lan_allow_minutes,omitempty"`
 	LANAllowSubnetSize  *uint          `json:"lan_allow_subnet_size,omitempty"`
+	TunnelProtocol      *string        `json:"tunnel_protocol,omitempty"`
 }
 
 type UpdateDefaultDeviceSettingsPolicyParams struct {
@@ -109,6 +111,7 @@ type UpdateDefaultDeviceSettingsPolicyParams struct {
 	Description         *string        `json:"description,omitempty"`
 	LANAllowMinutes     *uint          `json:"lan_allow_minutes,omitempty"`
 	LANAllowSubnetSize  *uint          `json:"lan_allow_subnet_size,omitempty"`
+	TunnelProtocol      *string        `json:"tunnel_protocol,omitempty"`
 }
 
 type UpdateDeviceSettingsPolicyParams struct {
@@ -130,6 +133,7 @@ type UpdateDeviceSettingsPolicyParams struct {
 	Description         *string        `json:"description,omitempty"`
 	LANAllowMinutes     *uint          `json:"lan_allow_minutes,omitempty"`
 	LANAllowSubnetSize  *uint          `json:"lan_allow_subnet_size,omitempty"`
+	TunnelProtocol      *string        `json:"tunnel_protocol,omitempty"`
 }
 
 type ListDeviceSettingsPoliciesResponse struct {


Test patch:
diff --git a/devices_policy_test.go b/devices_policy_test.go
index c78a13838..d2db00023 100644
--- a/devices_policy_test.go
+++ b/devices_policy_test.go
@@ -45,6 +45,7 @@ var (
 		Description:        nil,
 		LANAllowMinutes:    nil,
 		LANAllowSubnetSize: nil,
+		TunnelProtocol:     StringPtr("wireguard"),
 	}
 
 	nonDefaultDeviceSettingsPolicy = DeviceSettingsPolicy{
@@ -78,6 +79,7 @@ var (
 		Description:        StringPtr("Test Description"),
 		LANAllowMinutes:    UintPtr(120),
 		LANAllowSubnetSize: UintPtr(31),
+		TunnelProtocol:     StringPtr("masque"),
 	}
 
 	defaultDeviceSettingsPolicyJson = `{
@@ -111,7 +113,8 @@ var (
 		"allowed_to_leave": true,
 		"enabled": true,
 		"default": true,
-		"exclude_office_ips":false
+		"exclude_office_ips":false,
+		"tunnel_protocol":"wireguard"
 	}`
 
 	nonDefaultDeviceSettingsPolicyJson = fmt.Sprintf(`{
@@ -152,7 +155,8 @@ var (
 		"exclude_office_ips":true,
 		"description":"Test Description",
 		"lan_allow_minutes": 120,
-		"lan_allow_subnet_size": 31
+		"lan_allow_subnet_size": 31,
+		"tunnel_protocol":"masque"
 	}`, deviceSettingsPolicyID, deviceSettingsPolicyMatch)
 )