diff --git a/.changelog/2165.txt b/.changelog/2165.txt new file mode 100644 index 00000000000..d053fdc624d --- /dev/null +++ b/.changelog/2165.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +teams_account: Add Zero Trust connectivity settings +``` \ No newline at end of file diff --git a/teams_accounts.go b/teams_accounts.go index b13ad1bf066..3472fa4874f 100644 --- a/teams_accounts.go +++ b/teams_accounts.go @@ -147,6 +147,16 @@ type TeamsLoggingSettingsResponse struct { Result TeamsLoggingSettings `json:"result"` } +type TeamsConnectivitySettings struct { + ICMPProxyEnabled *bool `json:"icmp_proxy_enabled"` + OfframpWARPEnabled *bool `json:"offramp_warp_enabled"` +} + +type TeamsAccountConnectivitySettingsResponse struct { + Response + Result TeamsConnectivitySettings `json:"result"` +} + // TeamsAccount returns teams account information with internal and external ID. // // API reference: TBA. @@ -227,6 +237,26 @@ func (api *API) TeamsAccountLoggingConfiguration(ctx context.Context, accountID return teamsConfigResponse.Result, nil } +// TeamsAccountConnectivityConfiguration returns zero trust account connectivity settings. +// +// API reference: https://developers.cloudflare.com/api/operations/zero-trust-accounts-get-connectivity-settings +func (api *API) TeamsAccountConnectivityConfiguration(ctx context.Context, accountID string) (TeamsConnectivitySettings, error) { + uri := fmt.Sprintf("/accounts/%s/zerotrust/connectivity_settings", accountID) + + res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil) + if err != nil { + return TeamsConnectivitySettings{}, err + } + + var teamsConnectivityResponse TeamsAccountConnectivitySettingsResponse + err = json.Unmarshal(res, &teamsConnectivityResponse) + if err != nil { + return TeamsConnectivitySettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) + } + + return teamsConnectivityResponse.Result, nil +} + // TeamsAccountUpdateConfiguration updates a teams account configuration. // // API reference: TBA. @@ -286,3 +316,23 @@ func (api *API) TeamsAccountDeviceUpdateConfiguration(ctx context.Context, accou return teamsDeviceResponse.Result, nil } + +// TeamsAccountConnectivityUpdateConfiguration updates zero trust account connectivity settings. +// +// API reference: https://developers.cloudflare.com/api/operations/zero-trust-accounts-patch-connectivity-settings +func (api *API) TeamsAccountConnectivityUpdateConfiguration(ctx context.Context, accountID string, settings TeamsConnectivitySettings) (TeamsConnectivitySettings, error) { + uri := fmt.Sprintf("/accounts/%s/zerotrust/connectivity_settings", accountID) + + res, err := api.makeRequestContext(ctx, http.MethodPut, uri, settings) + if err != nil { + return TeamsConnectivitySettings{}, err + } + + var teamsConnectivityResponse TeamsAccountConnectivitySettingsResponse + err = json.Unmarshal(res, &teamsConnectivityResponse) + if err != nil { + return TeamsConnectivitySettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) + } + + return teamsConnectivityResponse.Result, nil +} diff --git a/teams_accounts_test.go b/teams_accounts_test.go index cf044f6abb9..5fd3686ac61 100644 --- a/teams_accounts_test.go +++ b/teams_accounts_test.go @@ -340,3 +340,60 @@ func TestTeamsAccountUpdateDeviceConfiguration(t *testing.T) { }) } } + +func TestTeamsAccountGetConnectivityConfiguration(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.Fprintf(w, `{ + "success": true, + "errors": [], + "messages": [], + "result": {"icmp_proxy_enabled": false,"offramp_warp_enabled":false} + }`) + } + + mux.HandleFunc("/accounts/"+testAccountID+"/zerotrust/connectivity_settings", handler) + + actual, err := client.TeamsAccountConnectivityConfiguration(context.Background(), testAccountID) + + if assert.NoError(t, err) { + assert.Equal(t, actual, TeamsConnectivitySettings{ + ICMPProxyEnabled: BoolPtr(false), + OfframpWARPEnabled: BoolPtr(false), + }) + } +} + +func TestTeamsAccountUpdateConnectivityConfiguration(t *testing.T) { + setup() + defer teardown() + + handler := func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method) + w.Header().Set("content-type", "application/json") + fmt.Fprintf(w, `{ + "success": true, + "errors": [], + "messages": [], + "result": {"icmp_proxy_enabled": true,"offramp_warp_enabled":true} + }`) + } + + mux.HandleFunc("/accounts/"+testAccountID+"/zerotrust/connectivity_settings", handler) + + actual, err := client.TeamsAccountConnectivityUpdateConfiguration(context.Background(), testAccountID, TeamsConnectivitySettings{ + ICMPProxyEnabled: BoolPtr(true), + OfframpWARPEnabled: BoolPtr(true), + }) + + if assert.NoError(t, err) { + assert.Equal(t, actual, TeamsConnectivitySettings{ + ICMPProxyEnabled: BoolPtr(true), + OfframpWARPEnabled: BoolPtr(true), + }) + } +}