Skip to content

Commit

Permalink
Merge branch 'cloudflare:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dhens authored and da-cf committed Feb 16, 2023
2 parents 9b2e289 + 1385fe5 commit 648bcfd
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 73 deletions.
3 changes: 3 additions & 0 deletions .changelog/1200.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
dlp_profile: Use int rather than uint for allowed_match_count field
```
3 changes: 3 additions & 0 deletions .changelog/1205.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
devices_policy: Add new exclude_office_ips field to policy
```
3 changes: 3 additions & 0 deletions .changelog/1207.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudflare: make it clearer when we hit a server error and to retry later
```
File renamed without changes.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## 0.61.0 (Unreleased)

ENHANCEMENTS:

* cloudflare: make it clearer when we hit a server error and to retry later ([#1207](https://github.com/cloudflare/cloudflare-go/issues/1207))
* devices_policy: Add new exclude_office_ips field to policy ([#1205](https://github.com/cloudflare/cloudflare-go/issues/1205))
* dlp_profile: Use int rather than uint for allowed_match_count field ([#1200](https://github.com/cloudflare/cloudflare-go/issues/1200))

BUG FIXES:

* dns: always send `tags` to allow clearing ([#1196](https://github.com/cloudflare/cloudflare-go/issues/1196))
Expand Down
13 changes: 2 additions & 11 deletions cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,8 @@ func (api *API) makeRequestWithAuthTypeAndHeadersComplete(ctx context.Context, m
respErr = errors.New("exceeded available rate limit retries")
}

// if we got a valid http response, try to read body so we can reuse the connection
// see https://golang.org/pkg/net/http/#Client.Do
if respErr == nil {
respBody, err = io.ReadAll(resp.Body)
resp.Body.Close()

respErr = fmt.Errorf("could not read response body: %w", err)

api.logger.Printf("Request: %s %s got an error response %d: %s\n", method, uri, resp.StatusCode,
strings.Replace(strings.Replace(string(respBody), "\n", "", -1), "\t", "", -1))
} else {
api.logger.Printf("Error performing request: %s %s : %s \n", method, uri, respErr.Error())
respErr = fmt.Errorf("received %s response (HTTP %d), please try again later", strings.ToLower(http.StatusText(resp.StatusCode)), resp.StatusCode)
}
continue
} else {
Expand All @@ -286,6 +276,7 @@ func (api *API) makeRequestWithAuthTypeAndHeadersComplete(ctx context.Context, m
if err != nil {
return nil, fmt.Errorf("could not read response body: %w", err)
}

break
}
}
Expand Down
53 changes: 26 additions & 27 deletions devices_dex.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (
"time"
)

type Data map[string]interface{}
type DeviceDexTestData map[string]interface{}

type DeviceDexTest struct {
TestID string `json:"test_id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Interval string `json:"interval"`
Enabled bool `json:"enabled"`
Updated time.Time `json:"updated"`
Created time.Time `json:"created"`
Data *Data `json:"data"`
TestID string `json:"test_id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Interval string `json:"interval"`
Enabled bool `json:"enabled"`
Updated time.Time `json:"updated"`
Created time.Time `json:"created"`
Data *DeviceDexTestData `json:"data"`
}

type DeviceDexTests struct {
Expand All @@ -38,25 +38,24 @@ type DeviceDexTestListResponse struct {
type ListDeviceDexTestParams struct{}

type CreateDeviceDexTestParams struct {
TestID string `json:"network_id,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Interval string `json:"interval"`
Enabled bool `json:"enabled"`
Data *Data `json:"data"`
TestID string `json:"network_id,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Interval string `json:"interval"`
Enabled bool `json:"enabled"`
Data *DeviceDexTestData `json:"data"`
}

type UpdateDeviceDexTestParams struct {
TestID string `json:"network_id,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Interval string `json:"interval"`
Enabled bool `json:"enabled"`
Data *Data `json:"data"`
TestID string `json:"network_id,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Interval string `json:"interval"`
Enabled bool `json:"enabled"`
Data *DeviceDexTestData `json:"data"`
}

// ListDexTests returns all Device Managed Networks for a given
// account.
// ListDexTests returns all Device Dex Tests for a given account.
//
// API reference : https://developers.cloudflare.com/api/operations/device-dex-test-details
func (api *API) ListDexTests(ctx context.Context, rc *ResourceContainer, params ListDeviceDexTestParams) (DeviceDexTests, error) {
Expand All @@ -80,7 +79,7 @@ func (api *API) ListDexTests(ctx context.Context, rc *ResourceContainer, params
return response.Result, nil
}

// CreateDeviceDexTest creates a new Device Managed Network.
// CreateDeviceDexTest created a new Device Dex Test
//
// API reference: https://developers.cloudflare.com/api/operations/device-dex-test-create-device-dex-test
func (api *API) CreateDeviceDexTest(ctx context.Context, rc *ResourceContainer, params CreateDeviceDexTestParams) (DeviceDexTest, error) {
Expand All @@ -103,7 +102,7 @@ func (api *API) CreateDeviceDexTest(ctx context.Context, rc *ResourceContainer,
return deviceDexTestResponse.Result, err
}

// UpdateDeviceDexTest Update a Device Managed Network.
// UpdateDeviceDexTest Updates a Device Dex Test.
//
// API reference: https://developers.cloudflare.com/api/operations/device-dex-test-update-device-dex-test
func (api *API) UpdateDeviceDexTest(ctx context.Context, rc *ResourceContainer, params UpdateDeviceDexTestParams) (DeviceManagedNetwork, error) {
Expand All @@ -127,7 +126,7 @@ func (api *API) UpdateDeviceDexTest(ctx context.Context, rc *ResourceContainer,
return deviceManagedNetworksResponse.Result, err
}

// GetDeviceDexTest gets a single Device Managed Network.
// GetDeviceDexTest gets a single Device Dex Test.
//
// API reference: https://developers.cloudflare.com/api/operations/device-dex-test-get-device-dex-test
func (api *API) GetDeviceDexTest(ctx context.Context, rc *ResourceContainer, testID string) (DeviceDexTest, error) {
Expand All @@ -150,7 +149,7 @@ func (api *API) GetDeviceDexTest(ctx context.Context, rc *ResourceContainer, tes
return deviceDexTestResponse.Result, err
}

// DeleteDexTest deletes a Device Managed Network.
// DeleteDexTest deletes a Device Dex Test.
//
// API reference: https://developers.cloudflare.com/api/operations/device-dex-test-delete-device-dex-test
func (api *API) DeleteDexTest(ctx context.Context, rc *ResourceContainer, testID string) (DeviceDexTests, error) {
Expand Down
8 changes: 4 additions & 4 deletions devices_dex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestGetDeviceDexTests(t *testing.T) {
Description: "dex test description",
Interval: "0h30m0s",
Enabled: true,
Data: &Data{
Data: &DeviceDexTestData{
"kind": "http",
"method": "GET",
"host": "https://dash.cloudflare.com",
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestDeviceDexTest(t *testing.T) {
Description: "dex test description",
Interval: "0h30m0s",
Enabled: true,
Data: &Data{
Data: &DeviceDexTestData{
"kind": "http",
"method": "GET",
"host": "https://dash.cloudflare.com",
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestCreateDeviceDexTest(t *testing.T) {
Description: "dex test description",
Interval: "0h30m0s",
Enabled: true,
Data: &Data{
Data: &DeviceDexTestData{
"kind": "http",
"method": "GET",
"host": "https://dash.cloudflare.com",
Expand All @@ -177,7 +177,7 @@ func TestCreateDeviceDexTest(t *testing.T) {
Description: "dex test description",
Interval: "0h30m0s",
Enabled: true,
Data: &Data{
Data: &DeviceDexTestData{
"kind": "http",
"method": "GET",
"host": "https://dash.cloudflare.com",
Expand Down
2 changes: 2 additions & 0 deletions devices_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand Down
64 changes: 34 additions & 30 deletions devices_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 = `{
Expand Down Expand Up @@ -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(`{
Expand Down Expand Up @@ -139,7 +142,8 @@ var (
"name": "test",
"match": %#v,
"precedence": 10,
"default": false
"default": false,
"exclude_office_ips":true
}`, deviceSettingsPolicyID, deviceSettingsPolicyMatch)
)

Expand Down
2 changes: 1 addition & 1 deletion dlp_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type DLPProfile struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
AllowedMatchCount uint `json:"allowed_match_count"`
AllowedMatchCount int `json:"allowed_match_count"`

// The following fields are omitted for predefined DLP
// profiles
Expand Down

0 comments on commit 648bcfd

Please sign in to comment.