diff --git a/.changelog/1433.txt b/.changelog/1433.txt index d837a4c9264..b8cbacb051a 100644 --- a/.changelog/1433.txt +++ b/.changelog/1433.txt @@ -1,3 +1,43 @@ +```release-note:breaking-change +devices_policy: `UpdateDeviceClientCertificatesZone` is renamed to `UpdateDeviceClientCertificates` with updated method signatures +``` + +```release-note:breaking-change +devices_policy: `GetDeviceClientCertificatesZone` is renamed to `GetDeviceClientCertificates` with updated method signatures +``` + +```release-note:breaking-change +devices_policy: `DeviceClientCertificates` is renamed to `DeviceClientCertificates` +``` + +```release-note:breaking-change +devices_policy: `GetDeviceClientCertificates` is updated with method signatures matching the library conventions +``` + +```release-note:breaking-change +devices_policy: `CreateDeviceSettingsPolicy` is updated with method signatures matching the library conventions +``` + +```release-note:breaking-change +devices_policy: `UpdateDefaultDeviceSettingsPolicy` is updated with method signatures matching the library conventions +``` + +```release-note:breaking-change +devices_policy: `UpdateDeviceSettingsPolicy` is updated with method signatures matching the library conventions +``` + +```release-note:breaking-change +devices_policy: `DeleteDeviceSettingsPolicy` is updated with method signatures matching the library conventions +``` + +```release-note:breaking-change +devices_policy: `GetDefaultDeviceSettingsPolicy` is updated with method signatures matching the library conventions +``` + +```release-note:breaking-change +devices_policy: `GetDeviceSettingsPolicy` is updated with method signatures matching the library conventions +``` + ```release-note:enhancement devices_policy: Add support for listing device settings policies ``` diff --git a/devices_policy.go b/devices_policy.go index 4fba72814ce..c662ecb42be 100644 --- a/devices_policy.go +++ b/devices_policy.go @@ -12,8 +12,8 @@ type Enabled struct { Enabled bool `json:"enabled"` } -// DeviceClientCertificatesZone identifies if the zero trust zone is configured for an account. -type DeviceClientCertificatesZone struct { +// DeviceClientCertificates identifies if the zero trust zone is configured for an account. +type DeviceClientCertificates struct { Response Result Enabled } @@ -21,12 +21,13 @@ type DeviceClientCertificatesZone struct { type ServiceMode string const ( - oneDotOne ServiceMode = "1dot1" - warp ServiceMode = "warp" - proxy ServiceMode = "proxy" - postureOnly ServiceMode = "posture_only" - warpTunnelOnly ServiceMode = "warp_tunnel_only" - listDeviceSettingsPoliciesDefaultPageSize = 20 + oneDotOne ServiceMode = "1dot1" + warp ServiceMode = "warp" + proxy ServiceMode = "proxy" + postureOnly ServiceMode = "posture_only" + warpTunnelOnly ServiceMode = "warp_tunnel_only" + + listDeviceSettingsPoliciesDefaultPageSize = 20 ) type ServiceModeV2 struct { @@ -68,7 +69,44 @@ type DeleteDeviceSettingsPolicyResponse struct { Result []DeviceSettingsPolicy } -type DeviceSettingsPolicyRequest struct { +type CreateDeviceSettingsPolicyParams struct { + DisableAutoFallback *bool `json:"disable_auto_fallback,omitempty"` + CaptivePortal *int `json:"captive_portal,omitempty"` + AllowModeSwitch *bool `json:"allow_mode_switch,omitempty"` + SwitchLocked *bool `json:"switch_locked,omitempty"` + AllowUpdates *bool `json:"allow_updates,omitempty"` + AutoConnect *int `json:"auto_connect,omitempty"` + AllowedToLeave *bool `json:"allowed_to_leave,omitempty"` + SupportURL *string `json:"support_url,omitempty"` + ServiceModeV2 *ServiceModeV2 `json:"service_mode_v2,omitempty"` + Precedence *int `json:"precedence,omitempty"` + Name *string `json:"name,omitempty"` + Match *string `json:"match,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + ExcludeOfficeIps *bool `json:"exclude_office_ips"` + Description *string `json:"description,omitempty"` +} + +type UpdateDefaultDeviceSettingsPolicyParams struct { + DisableAutoFallback *bool `json:"disable_auto_fallback,omitempty"` + CaptivePortal *int `json:"captive_portal,omitempty"` + AllowModeSwitch *bool `json:"allow_mode_switch,omitempty"` + SwitchLocked *bool `json:"switch_locked,omitempty"` + AllowUpdates *bool `json:"allow_updates,omitempty"` + AutoConnect *int `json:"auto_connect,omitempty"` + AllowedToLeave *bool `json:"allowed_to_leave,omitempty"` + SupportURL *string `json:"support_url,omitempty"` + ServiceModeV2 *ServiceModeV2 `json:"service_mode_v2,omitempty"` + Precedence *int `json:"precedence,omitempty"` + Name *string `json:"name,omitempty"` + Match *string `json:"match,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + ExcludeOfficeIps *bool `json:"exclude_office_ips"` + Description *string `json:"description,omitempty"` +} + +type UpdateDeviceSettingsPolicyParams struct { + PolicyID *string `json:"-"` DisableAutoFallback *bool `json:"disable_auto_fallback,omitempty"` CaptivePortal *int `json:"captive_portal,omitempty"` AllowModeSwitch *bool `json:"allow_mode_switch,omitempty"` @@ -92,14 +130,30 @@ type ListDeviceSettingsPoliciesResponse struct { Result []DeviceSettingsPolicy `json:"result"` } +type UpdateDeviceClientCertificatesParams struct { + Enabled *bool `json:"enabled"` +} + +type GetDeviceClientCertificatesParams struct{} + +type GetDefaultDeviceSettingsPolicyParams struct{} + +type GetDeviceSettingsPolicyParams struct { + PolicyID *string `json:"-"` +} + // UpdateDeviceClientCertificates controls the zero trust zone used to provision client certificates. // // API reference: https://api.cloudflare.com/#device-client-certificates -func (api *API) UpdateDeviceClientCertificatesZone(ctx context.Context, zoneID string, enable bool) (DeviceClientCertificatesZone, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/certificates", ZoneRouteRoot, zoneID) +func (api *API) UpdateDeviceClientCertificates(ctx context.Context, rc *ResourceContainer, params UpdateDeviceClientCertificatesParams) (DeviceClientCertificates, error) { + if rc.Level != ZoneRouteLevel { + return DeviceClientCertificates{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) + } + + uri := fmt.Sprintf("/%s/%s/devices/policy/certificates", rc.Level, rc.Identifier) - result := DeviceClientCertificatesZone{} - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, Enabled{enable}) + result := DeviceClientCertificates{Result: Enabled{false}} + res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params) if err != nil { return result, err } @@ -111,13 +165,18 @@ func (api *API) UpdateDeviceClientCertificatesZone(ctx context.Context, zoneID s return result, err } -// GetDeviceClientCertificatesZone controls the zero trust zone used to provision client certificates. +// GetDeviceClientCertificates controls the zero trust zone used to provision +// client certificates. // // API reference: https://api.cloudflare.com/#device-client-certificates -func (api *API) GetDeviceClientCertificatesZone(ctx context.Context, zoneID string) (DeviceClientCertificatesZone, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/certificates", ZoneRouteRoot, zoneID) +func (api *API) GetDeviceClientCertificates(ctx context.Context, rc *ResourceContainer, params GetDeviceClientCertificatesParams) (DeviceClientCertificates, error) { + if rc.Level != ZoneRouteLevel { + return DeviceClientCertificates{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) + } + + uri := fmt.Sprintf("/%s/%s/devices/policy/certificates", rc.Level, rc.Identifier) - result := DeviceClientCertificatesZone{} + result := DeviceClientCertificates{} res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) if err != nil { return result, err @@ -130,118 +189,143 @@ func (api *API) GetDeviceClientCertificatesZone(ctx context.Context, zoneID stri return result, err } -// CreateDeviceSettingsPolicy creates a settings policy against devices that match the policy +// CreateDeviceSettingsPolicy creates a settings policy against devices that +// match the policy. // // API reference: https://api.cloudflare.com/#devices-create-device-settings-policy -func (api *API) CreateDeviceSettingsPolicy(ctx context.Context, accountID string, req DeviceSettingsPolicyRequest) (DeviceSettingsPolicyResponse, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy", AccountRouteRoot, accountID) +func (api *API) CreateDeviceSettingsPolicy(ctx context.Context, rc *ResourceContainer, params CreateDeviceSettingsPolicyParams) (DeviceSettingsPolicy, error) { + if rc.Level != AccountRouteLevel { + return DeviceSettingsPolicy{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) + } + + uri := fmt.Sprintf("/%s/%s/devices/policy", rc.Level, rc.Identifier) result := DeviceSettingsPolicyResponse{} - res, err := api.makeRequestContext(ctx, http.MethodPost, uri, req) + res, err := api.makeRequestContext(ctx, http.MethodPost, uri, params) if err != nil { - return result, err + return DeviceSettingsPolicy{}, err } if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) + return DeviceSettingsPolicy{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } - return result, err + return result.Result, err } // UpdateDefaultDeviceSettingsPolicy updates the default settings policy for an account // // API reference: https://api.cloudflare.com/#devices-update-default-device-settings-policy -func (api *API) UpdateDefaultDeviceSettingsPolicy(ctx context.Context, accountID string, req DeviceSettingsPolicyRequest) (DeviceSettingsPolicyResponse, error) { +func (api *API) UpdateDefaultDeviceSettingsPolicy(ctx context.Context, rc *ResourceContainer, params UpdateDefaultDeviceSettingsPolicyParams) (DeviceSettingsPolicy, error) { + if rc.Level != AccountRouteLevel { + return DeviceSettingsPolicy{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) + } + result := DeviceSettingsPolicyResponse{} - uri := fmt.Sprintf("/%s/%s/devices/policy", AccountRouteRoot, accountID) - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, req) + uri := fmt.Sprintf("/%s/%s/devices/policy", rc.Level, rc.Identifier) + res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params) if err != nil { - return result, err + return DeviceSettingsPolicy{}, err } if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) + return DeviceSettingsPolicy{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } - return result, err + return result.Result, err } // UpdateDeviceSettingsPolicy updates a settings policy // // API reference: https://api.cloudflare.com/#devices-update-device-settings-policy -func (api *API) UpdateDeviceSettingsPolicy(ctx context.Context, accountID, policyID string, req DeviceSettingsPolicyRequest) (DeviceSettingsPolicyResponse, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s", AccountRouteRoot, accountID, policyID) +func (api *API) UpdateDeviceSettingsPolicy(ctx context.Context, rc *ResourceContainer, params UpdateDeviceSettingsPolicyParams) (DeviceSettingsPolicy, error) { + if rc.Level != AccountRouteLevel { + return DeviceSettingsPolicy{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) + } + + uri := fmt.Sprintf("/%s/%s/devices/policy/%s", rc.Level, rc.Identifier, *params.PolicyID) result := DeviceSettingsPolicyResponse{} - res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, req) + res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params) if err != nil { - return result, err + return DeviceSettingsPolicy{}, err } if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) + return DeviceSettingsPolicy{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } - return result, err + return result.Result, err } // DeleteDeviceSettingsPolicy deletes a settings policy and returns a list -// of all of the other policies in the account +// of all of the other policies in the account. // // API reference: https://api.cloudflare.com/#devices-delete-device-settings-policy -func (api *API) DeleteDeviceSettingsPolicy(ctx context.Context, accountID, policyID string) (DeleteDeviceSettingsPolicyResponse, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s", AccountRouteRoot, accountID, policyID) +func (api *API) DeleteDeviceSettingsPolicy(ctx context.Context, rc *ResourceContainer, policyID string) ([]DeviceSettingsPolicy, error) { + if rc.Level != AccountRouteLevel { + return []DeviceSettingsPolicy{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) + } + + uri := fmt.Sprintf("/%s/%s/devices/policy/%s", rc.Level, rc.Identifier, policyID) result := DeleteDeviceSettingsPolicyResponse{} res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil) if err != nil { - return result, err + return []DeviceSettingsPolicy{}, err } if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) + return []DeviceSettingsPolicy{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } - return result, err + return result.Result, err } -// GetDefaultDeviceSettings gets the default device settings policy +// GetDefaultDeviceSettings gets the default device settings policy. // // API reference: https://api.cloudflare.com/#devices-get-default-device-settings-policy -func (api *API) GetDefaultDeviceSettingsPolicy(ctx context.Context, accountID string) (DeviceSettingsPolicyResponse, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy", AccountRouteRoot, accountID) +func (api *API) GetDefaultDeviceSettingsPolicy(ctx context.Context, rc *ResourceContainer, params GetDefaultDeviceSettingsPolicyParams) (DeviceSettingsPolicy, error) { + if rc.Level != AccountRouteLevel { + return DeviceSettingsPolicy{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) + } + + uri := fmt.Sprintf("/%s/%s/devices/policy", rc.Level, rc.Identifier) result := DeviceSettingsPolicyResponse{} res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) if err != nil { - return result, err + return DeviceSettingsPolicy{}, err } if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) + return DeviceSettingsPolicy{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } - return result, err + return result.Result, err } -// GetDefaultDeviceSettings gets the device settings policy by its policyID +// GetDefaultDeviceSettings gets the device settings policy by its policyID. // // API reference: https://api.cloudflare.com/#devices-get-device-settings-policy-by-id -func (api *API) GetDeviceSettingsPolicy(ctx context.Context, accountID, policyID string) (DeviceSettingsPolicyResponse, error) { - uri := fmt.Sprintf("/%s/%s/devices/policy/%s", AccountRouteRoot, accountID, policyID) +func (api *API) GetDeviceSettingsPolicy(ctx context.Context, rc *ResourceContainer, params GetDeviceSettingsPolicyParams) (DeviceSettingsPolicy, error) { + if rc.Level != AccountRouteLevel { + return DeviceSettingsPolicy{}, fmt.Errorf(errInvalidResourceContainerAccess, rc.Level) + } + + uri := fmt.Sprintf("/%s/%s/devices/policy/%s", rc.Level, rc.Identifier, *params.PolicyID) result := DeviceSettingsPolicyResponse{} res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) if err != nil { - return result, err + return DeviceSettingsPolicy{}, err } if err := json.Unmarshal(res, &result); err != nil { - return result, fmt.Errorf("%s: %w", errUnmarshalError, err) + return DeviceSettingsPolicy{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } - return result, err + return result.Result, err } type ListDeviceSettingsPoliciesParams struct { @@ -251,8 +335,7 @@ type ListDeviceSettingsPoliciesParams struct { // ListDeviceSettingsPolicies returns all device settings policies for an account // // API reference: https://api.cloudflare.com/#devices-list-device-settings-policies -func (api *API) ListDeviceSettingsPolicies(ctx context.Context, accountID string, params ListDeviceSettingsPoliciesParams) ([]DeviceSettingsPolicy, *ResultInfo, error) { - +func (api *API) ListDeviceSettingsPolicies(ctx context.Context, rc *ResourceContainer, params ListDeviceSettingsPoliciesParams) ([]DeviceSettingsPolicy, *ResultInfo, error) { autoPaginate := true if params.PerPage >= 1 || params.Page >= 1 { autoPaginate = false @@ -265,7 +348,7 @@ func (api *API) ListDeviceSettingsPolicies(ctx context.Context, accountID string var policies []DeviceSettingsPolicy var lastResultInfo ResultInfo for { - uri := buildURI(fmt.Sprintf("/%s/%s/devices/policies", AccountRouteRoot, accountID), params) + uri := buildURI(fmt.Sprintf("/%s/%s/devices/policies", rc.Level, rc.Identifier), params) res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) if err != nil { return nil, nil, err diff --git a/devices_policy_test.go b/devices_policy_test.go index 8656ce6ca01..b08e4522610 100644 --- a/devices_policy_test.go +++ b/devices_policy_test.go @@ -150,7 +150,7 @@ var ( }`, deviceSettingsPolicyID, deviceSettingsPolicyMatch) ) -func TestUpdateDeviceClientCertificatesZone(t *testing.T) { +func TestUpdateDeviceClientCertificates(t *testing.T) { setup() defer teardown() @@ -165,7 +165,7 @@ func TestUpdateDeviceClientCertificatesZone(t *testing.T) { }`) } - want := DeviceClientCertificatesZone{ + want := DeviceClientCertificates{ Response: Response{ Success: true, Errors: nil, @@ -176,14 +176,14 @@ func TestUpdateDeviceClientCertificatesZone(t *testing.T) { mux.HandleFunc("/zones/"+testZoneID+"/devices/policy/certificates", handler) - actual, err := client.UpdateDeviceClientCertificatesZone(context.Background(), testZoneID, true) + actual, err := client.UpdateDeviceClientCertificates(context.Background(), ZoneIdentifier(testZoneID), UpdateDeviceClientCertificatesParams{Enabled: BoolPtr(true)}) if assert.NoError(t, err) { assert.Equal(t, want, actual) } } -func TestGetDeviceClientCertificatesZone(t *testing.T) { +func TestGetDeviceClientCertificates(t *testing.T) { setup() defer teardown() @@ -198,7 +198,7 @@ func TestGetDeviceClientCertificatesZone(t *testing.T) { }`) } - want := DeviceClientCertificatesZone{ + want := DeviceClientCertificates{ Response: Response{ Success: true, Errors: nil, @@ -209,7 +209,7 @@ func TestGetDeviceClientCertificatesZone(t *testing.T) { mux.HandleFunc("/zones/"+testZoneID+"/devices/policy/certificates", handler) - actual, err := client.GetDeviceClientCertificatesZone(context.Background(), testZoneID) + actual, err := client.GetDeviceClientCertificates(context.Background(), ZoneIdentifier(testZoneID), GetDeviceClientCertificatesParams{}) if assert.NoError(t, err) { assert.Equal(t, want, actual) @@ -231,18 +231,9 @@ func TestCreateDeviceSettingsPolicy(t *testing.T) { }`, nonDefaultDeviceSettingsPolicyJson) } - want := DeviceSettingsPolicyResponse{ - Response: Response{ - Success: true, - Errors: nil, - Messages: nil, - }, - Result: nonDefaultDeviceSettingsPolicy, - } - mux.HandleFunc("/accounts/"+testAccountID+"/devices/policy", handler) - actual, err := client.CreateDeviceSettingsPolicy(context.Background(), testAccountID, DeviceSettingsPolicyRequest{ + actual, err := client.CreateDeviceSettingsPolicy(context.Background(), AccountIdentifier(testAccountID), CreateDeviceSettingsPolicyParams{ Precedence: IntPtr(10), Match: &deviceSettingsPolicyMatch, Name: StringPtr("test"), @@ -250,7 +241,7 @@ func TestCreateDeviceSettingsPolicy(t *testing.T) { }) if assert.NoError(t, err) { - assert.Equal(t, want, actual) + assert.Equal(t, nonDefaultDeviceSettingsPolicy, actual) } } @@ -269,21 +260,12 @@ func TestUpdateDefaultDeviceSettingsPolicy(t *testing.T) { }`, defaultDeviceSettingsPolicyJson) } - want := DeviceSettingsPolicyResponse{ - Response: Response{ - Success: true, - Errors: nil, - Messages: nil, - }, - Result: defaultDeviceSettingsPolicy, - } - mux.HandleFunc("/accounts/"+testAccountID+"/devices/policy", handler) - actual, err := client.UpdateDefaultDeviceSettingsPolicy(context.Background(), testAccountID, DeviceSettingsPolicyRequest{}) + actual, err := client.UpdateDefaultDeviceSettingsPolicy(context.Background(), AccountIdentifier(testAccountID), UpdateDefaultDeviceSettingsPolicyParams{}) if assert.NoError(t, err) { - assert.Equal(t, want, actual) + assert.Equal(t, defaultDeviceSettingsPolicy, actual) } } @@ -303,23 +285,16 @@ func TestUpdateDeviceSettingsPolicy(t *testing.T) { } precedence := 10 - want := DeviceSettingsPolicyResponse{ - Response: Response{ - Success: true, - Errors: nil, - Messages: nil, - }, - Result: nonDefaultDeviceSettingsPolicy, - } mux.HandleFunc("/accounts/"+testAccountID+"/devices/policy/"+deviceSettingsPolicyID, handler) - actual, err := client.UpdateDeviceSettingsPolicy(context.Background(), testAccountID, deviceSettingsPolicyID, DeviceSettingsPolicyRequest{ + actual, err := client.UpdateDeviceSettingsPolicy(context.Background(), AccountIdentifier(testAccountID), UpdateDeviceSettingsPolicyParams{ + PolicyID: &deviceSettingsPolicyID, Precedence: &precedence, }) if assert.NoError(t, err) { - assert.Equal(t, want, actual) + assert.Equal(t, nonDefaultDeviceSettingsPolicy, actual) } } @@ -338,21 +313,12 @@ func TestDeleteDeviceSettingsPolicy(t *testing.T) { }`, defaultDeviceSettingsPolicyJson) } - want := DeleteDeviceSettingsPolicyResponse{ - Response: Response{ - Success: true, - Errors: nil, - Messages: nil, - }, - Result: []DeviceSettingsPolicy{defaultDeviceSettingsPolicy}, - } - mux.HandleFunc("/accounts/"+testAccountID+"/devices/policy/"+deviceSettingsPolicyID, handler) - actual, err := client.DeleteDeviceSettingsPolicy(context.Background(), testAccountID, deviceSettingsPolicyID) + actual, err := client.DeleteDeviceSettingsPolicy(context.Background(), AccountIdentifier(testAccountID), deviceSettingsPolicyID) if assert.NoError(t, err) { - assert.Equal(t, want, actual) + assert.Equal(t, []DeviceSettingsPolicy{defaultDeviceSettingsPolicy}, actual) } } @@ -371,21 +337,12 @@ func TestGetDefaultDeviceSettings(t *testing.T) { }`, defaultDeviceSettingsPolicyJson) } - want := DeviceSettingsPolicyResponse{ - Response: Response{ - Success: true, - Errors: nil, - Messages: nil, - }, - Result: defaultDeviceSettingsPolicy, - } - mux.HandleFunc("/accounts/"+testAccountID+"/devices/policy", handler) - actual, err := client.GetDefaultDeviceSettingsPolicy(context.Background(), testAccountID) + actual, err := client.GetDefaultDeviceSettingsPolicy(context.Background(), AccountIdentifier(testAccountID), GetDefaultDeviceSettingsPolicyParams{}) if assert.NoError(t, err) { - assert.Equal(t, want, actual) + assert.Equal(t, defaultDeviceSettingsPolicy, actual) } } @@ -404,21 +361,12 @@ func TestGetDeviceSettings(t *testing.T) { }`, nonDefaultDeviceSettingsPolicyJson) } - want := DeviceSettingsPolicyResponse{ - Response: Response{ - Success: true, - Errors: nil, - Messages: nil, - }, - Result: nonDefaultDeviceSettingsPolicy, - } - mux.HandleFunc("/accounts/"+testAccountID+"/devices/policy/"+deviceSettingsPolicyID, handler) - actual, err := client.GetDeviceSettingsPolicy(context.Background(), testAccountID, deviceSettingsPolicyID) + actual, err := client.GetDeviceSettingsPolicy(context.Background(), AccountIdentifier(testAccountID), GetDeviceSettingsPolicyParams{PolicyID: &deviceSettingsPolicyID}) if assert.NoError(t, err) { - assert.Equal(t, want, actual) + assert.Equal(t, nonDefaultDeviceSettingsPolicy, actual) } } @@ -447,7 +395,7 @@ func TestListDeviceSettingsPolicies(t *testing.T) { mux.HandleFunc("/accounts/"+testAccountID+"/devices/policies", handler) - actual, resultInfo, err := client.ListDeviceSettingsPolicies(context.Background(), testAccountID, ListDeviceSettingsPoliciesParams{ + actual, resultInfo, err := client.ListDeviceSettingsPolicies(context.Background(), AccountIdentifier(testAccountID), ListDeviceSettingsPoliciesParams{ ResultInfo: ResultInfo{ Page: 1, PerPage: 20,