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
imdawon authored Feb 22, 2023
2 parents e511508 + 44062f1 commit 4704cba
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .changelog/1202.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
stream: renamed `RequiredSignedURLs` to `RequireSignedURLs`
```
3 changes: 3 additions & 0 deletions .changelog/1206.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
tunnels: automatically paginate `ListTunnels`
```
3 changes: 3 additions & 0 deletions .changelog/1208.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
teams_accounts: Add new root_certificate_installation_enabled field
```
3 changes: 3 additions & 0 deletions .changelog/1210.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:dependency
deps: bumps github.com/urfave/cli/v2 from 2.24.3 to 2.24.4
```
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
## 0.61.0 (Unreleased)
## 0.62.0 (Unreleased)

ENHANCEMENTS:

* dex_test: add CRUD functionality for DEX test configurations ([#1209](https://github.com/cloudflare/cloudflare-go/issues/1209))
* teams_accounts: Add new root_certificate_installation_enabled field ([#1208](https://github.com/cloudflare/cloudflare-go/issues/1208))
* tunnels: automatically paginate `ListTunnels` ([#1206](https://github.com/cloudflare/cloudflare-go/issues/1206))

DEPENDENCIES:

* deps: bumps github.com/urfave/cli/v2 from 2.24.3 to 2.24.4 ([#1210](https://github.com/cloudflare/cloudflare-go/issues/1210))

## 0.61.0 (15th February, 2023)

ENHANCEMENTS:

Expand All @@ -9,6 +21,7 @@ ENHANCEMENTS:
BUG FIXES:

* dns: always send `tags` to allow clearing ([#1196](https://github.com/cloudflare/cloudflare-go/issues/1196))
* stream: renamed `RequiredSignedURLs` to `RequireSignedURLs` ([#1202](https://github.com/cloudflare/cloudflare-go/issues/1202))

DEPENDENCIES:

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.2
github.com/olekukonko/tablewriter v0.0.5
github.com/stretchr/testify v1.8.1
github.com/urfave/cli/v2 v2.24.3
github.com/urfave/cli/v2 v2.24.4
golang.org/x/net v0.0.0-20220722155237-a158d28d115b
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/urfave/cli/v2 v2.24.3 h1:7Q1w8VN8yE0MJEHP06bv89PjYsN4IHWED2s1v/Zlfm0=
github.com/urfave/cli/v2 v2.24.3/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/urfave/cli/v2 v2.24.4 h1:0gyJJEBYtCV87zI/x2nZCPyDxD51K6xM8SkwjHFCNEU=
github.com/urfave/cli/v2 v2.24.4/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
Expand Down
4 changes: 2 additions & 2 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type StreamUploadFromURLParameters struct {
Creator string `json:"creator,omitempty"`
ThumbnailTimestampPct float64 `json:"thumbnailTimestampPct,omitempty"`
AllowedOrigins []string `json:"allowedOrigins,omitempty"`
RequiredSignedURLs bool `json:"requiredSignedURLs,omitempty"`
RequireSignedURLs bool `json:"requireSignedURLs,omitempty"`
Watermark UploadVideoURLWatermark `json:"watermark,omitempty"`
}

Expand All @@ -113,7 +113,7 @@ type StreamCreateVideoParameters struct {
Creator string `json:"creator,omitempty"`
ThumbnailTimestampPct float64 `json:"thumbnailTimestampPct,omitempty"`
AllowedOrigins []string `json:"allowedOrigins,omitempty"`
RequiredSignedURLs bool `json:"requiredSignedURLs,omitempty"`
RequireSignedURLs bool `json:"requireSignedURLs,omitempty"`
Watermark UploadVideoURLWatermark `json:"watermark,omitempty"`
}

Expand Down
5 changes: 3 additions & 2 deletions teams_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ type TeamsLoggingSettings struct {
}

type TeamsDeviceSettings struct {
GatewayProxyEnabled bool `json:"gateway_proxy_enabled"`
GatewayProxyUDPEnabled bool `json:"gateway_udp_proxy_enabled"`
GatewayProxyEnabled bool `json:"gateway_proxy_enabled"`
GatewayProxyUDPEnabled bool `json:"gateway_udp_proxy_enabled"`
RootCertificateInstallationEnabled bool `json:"root_certificate_installation_enabled"`
}

type TeamsDeviceSettingsResponse struct {
Expand Down
19 changes: 11 additions & 8 deletions teams_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func TestTeamsAccountGetDeviceConfiguration(t *testing.T) {
"success": true,
"errors": [],
"messages": [],
"result": {"gateway_proxy_enabled": true,"gateway_udp_proxy_enabled":false}
"result": {"gateway_proxy_enabled": true,"gateway_udp_proxy_enabled":false, "root_certificate_installation_enabled":true}
}`)
}

Expand All @@ -249,8 +249,9 @@ func TestTeamsAccountGetDeviceConfiguration(t *testing.T) {

if assert.NoError(t, err) {
assert.Equal(t, actual, TeamsDeviceSettings{
GatewayProxyEnabled: true,
GatewayProxyUDPEnabled: false,
GatewayProxyEnabled: true,
GatewayProxyUDPEnabled: false,
RootCertificateInstallationEnabled: true,
})
}
}
Expand All @@ -266,21 +267,23 @@ func TestTeamsAccountUpdateDeviceConfiguration(t *testing.T) {
"success": true,
"errors": [],
"messages": [],
"result": {"gateway_proxy_enabled": true,"gateway_udp_proxy_enabled":true}
"result": {"gateway_proxy_enabled": true,"gateway_udp_proxy_enabled":true, "root_certificate_installation_enabled":true}
}`)
}

mux.HandleFunc("/accounts/"+testAccountID+"/devices/settings", handler)

actual, err := client.TeamsAccountDeviceUpdateConfiguration(context.Background(), testAccountID, TeamsDeviceSettings{
GatewayProxyUDPEnabled: true,
GatewayProxyEnabled: true,
GatewayProxyUDPEnabled: true,
GatewayProxyEnabled: true,
RootCertificateInstallationEnabled: true,
})

if assert.NoError(t, err) {
assert.Equal(t, actual, TeamsDeviceSettings{
GatewayProxyEnabled: true,
GatewayProxyUDPEnabled: true,
GatewayProxyEnabled: true,
GatewayProxyUDPEnabled: true,
RootCertificateInstallationEnabled: true,
})
}
}
8 changes: 7 additions & 1 deletion testdata/fixtures/tunnel/multiple_full.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@
}
]
}
]
],
"result_info": {
"count": 1,
"page": 1,
"per_page": 20,
"total_count": 1
}
}
51 changes: 40 additions & 11 deletions tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ type TunnelConnection struct {
type TunnelsDetailResponse struct {
Result []Tunnel `json:"result"`
Response
ResultInfo `json:"result_info"`
}

// listTunnelsDefaultPageSize represents the default per_page size of the API.
var listTunnelsDefaultPageSize int = 100

// TunnelDetailResponse is used for representing the API response payload for
// a single tunnel.
type TunnelDetailResponse struct {
Expand Down Expand Up @@ -171,29 +175,54 @@ type TunnelListParams struct {
UUID string `url:"uuid,omitempty"` // the tunnel ID
IsDeleted *bool `url:"is_deleted,omitempty"`
ExistedAt *time.Time `url:"existed_at,omitempty"`

ResultInfo
}

// Tunnels lists all tunnels.
//
// API reference: https://api.cloudflare.com/#cloudflare-tunnel-list-cloudflare-tunnels
func (api *API) Tunnels(ctx context.Context, rc *ResourceContainer, params TunnelListParams) ([]Tunnel, error) {
func (api *API) Tunnels(ctx context.Context, rc *ResourceContainer, params TunnelListParams) ([]Tunnel, *ResultInfo, error) {
if rc.Identifier == "" {
return []Tunnel{}, ErrMissingAccountID
return []Tunnel{}, &ResultInfo{}, ErrMissingAccountID
}

uri := buildURI(fmt.Sprintf("/accounts/%s/cfd_tunnel", rc.Identifier), params)
autoPaginate := true
if params.PerPage >= 1 || params.Page >= 1 {
autoPaginate = false
}

res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return []Tunnel{}, err
if params.PerPage < 1 {
params.PerPage = listTunnelsDefaultPageSize
}

var argoDetailsResponse TunnelsDetailResponse
err = json.Unmarshal(res, &argoDetailsResponse)
if err != nil {
return []Tunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
if params.Page < 1 {
params.Page = 1
}
return argoDetailsResponse.Result, nil

var records []Tunnel
var listResponse TunnelsDetailResponse

for {
uri := buildURI(fmt.Sprintf("/accounts/%s/cfd_tunnel", rc.Identifier), params)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return []Tunnel{}, &ResultInfo{}, err
}

err = json.Unmarshal(res, &listResponse)
if err != nil {
return []Tunnel{}, &ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}

records = append(records, listResponse.Result...)
params.ResultInfo = listResponse.ResultInfo.Next()
if params.ResultInfo.Done() || !autoPaginate {
break
}
}

return records, &listResponse.ResultInfo, nil
}

// Tunnel returns a single Argo tunnel.
Expand Down
53 changes: 52 additions & 1 deletion tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -40,7 +41,57 @@ func TestTunnels(t *testing.T) {
}},
}}

actual, err := client.Tunnels(context.Background(), AccountIdentifier(testAccountID), TunnelListParams{UUID: "f174e90a-fafe-4643-bbbc-4a0ed4fc8415"})
actual, _, err := client.Tunnels(context.Background(), AccountIdentifier(testAccountID), TunnelListParams{UUID: "f174e90a-fafe-4643-bbbc-4a0ed4fc8415"})

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}
}

func TestTunnelsPagination(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")
qry, _ := url.Parse(r.RequestURI)
assert.Equal(t, "blog", qry.Query().Get("name"))
assert.Equal(t, "2", qry.Query().Get("page"))
assert.Equal(t, "1", qry.Query().Get("per_page"))
fmt.Fprint(w, loadFixture("tunnel", "multiple_full"))
}

mux.HandleFunc("/accounts/"+testAccountID+"/cfd_tunnel", handler)

createdAt, _ := time.Parse(time.RFC3339, "2009-11-10T23:00:00Z")
deletedAt, _ := time.Parse(time.RFC3339, "2009-11-10T23:00:00Z")
want := []Tunnel{
{
ID: "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
Name: "blog",
CreatedAt: &createdAt,
DeletedAt: &deletedAt,
Connections: []TunnelConnection{{
ColoName: "DFW",
ID: "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
IsPendingReconnect: false,
ClientID: "dc6472cc-f1ae-44a0-b795-6b8a0ce29f90",
ClientVersion: "2022.2.0",
OpenedAt: "2021-01-25T18:22:34.317854Z",
OriginIP: "198.51.100.1",
}},
},
}

actual, _, err := client.Tunnels(context.Background(), AccountIdentifier(testAccountID),
TunnelListParams{
Name: "blog",
ResultInfo: ResultInfo{
Page: 2,
PerPage: 1,
},
})

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
Expand Down

0 comments on commit 4704cba

Please sign in to comment.