Skip to content

Commit

Permalink
Merge pull request #2165 from josip-stanic/feature/zt-warp-to-warp-co…
Browse files Browse the repository at this point in the history
…nnectivity-settings

Add ZT connectivity settings
  • Loading branch information
jacobbednarz authored May 28, 2024
2 parents 4426ca8 + c9ff24a commit 44fc8de
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/2165.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
teams_account: Add Zero Trust connectivity settings
```
50 changes: 50 additions & 0 deletions teams_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
57 changes: 57 additions & 0 deletions teams_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}
}

0 comments on commit 44fc8de

Please # to comment.