Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tunnels #1227

Merged
merged 3 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/1227.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:breaking-change
tunnel: changed to use List and Get
```
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved
```release-note:enhancement
tunnel: updated parameters to latest API docs
```
47 changes: 25 additions & 22 deletions testdata/fixtures/tunnel/single_full.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
"name": "blog",
"created_at": "2009-11-10T23:00:00Z",
"deleted_at": "2009-11-10T23:00:00Z",
"connections": [
{
"colo_name": "DFW",
"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
"is_pending_reconnect": false,
"client_id": "dc6472cc-f1ae-44a0-b795-6b8a0ce29f90",
"client_version": "2022.2.0",
"opened_at": "2021-01-25T18:22:34.317854Z",
"origin_ip": "198.51.100.1"
}
]
}
}
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
"name": "blog",
"created_at": "2009-11-10T23:00:00Z",
"deleted_at": "2009-11-10T23:00:00Z",
"connections": [
{
"colo_name": "DFW",
"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
"is_pending_reconnect": false,
"client_id": "dc6472cc-f1ae-44a0-b795-6b8a0ce29f90",
"client_version": "2022.2.0",
"opened_at": "2021-01-25T18:22:34.317854Z",
"origin_ip": "198.51.100.1"
}
],
"status": "healthy",
"tun_type": "cfd_tunnel",
"remote_config": true
}
}
37 changes: 21 additions & 16 deletions tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ type Tunnel struct {
Connections []TunnelConnection `json:"connections,omitempty"`
ConnsActiveAt *time.Time `json:"conns_active_at,omitempty"`
ConnInactiveAt *time.Time `json:"conns_inactive_at,omitempty"`
TunnelType string `json:"tun_type,omitempty"`
Status string `json:"status,omitempty"`
RemoteConfig bool `json:"remote_config,omitempty"`
}

// Connection is the struct definition of a connection.
type Connection struct {
ID string `json:"id,omitempty"`
Features []string `json:"features,omitempty"`
Version string `json:"version,omitempty"`
Arch string `json:"arch,omitempty"`
Connections []TunnelConnection `json:"conns,omitempty"`
RunAt *time.Time `json:"run_at,omitempty"`
ID string `json:"id,omitempty"`
Features []string `json:"features,omitempty"`
Version string `json:"version,omitempty"`
Arch string `json:"arch,omitempty"`
Connections []TunnelConnection `json:"conns,omitempty"`
RunAt *time.Time `json:"run_at,omitempty"`
ConfigVersion int `json:"config_version,omitempty"`
}

// TunnelConnection represents the connections associated with a tunnel.
Expand Down Expand Up @@ -91,8 +95,9 @@ type TunnelTokenResponse struct {
}

type TunnelCreateParams struct {
Name string `json:"name,omitempty"`
Secret string `json:"tunnel_secret,omitempty"`
Name string `json:"name,omitempty"`
Secret string `json:"tunnel_secret,omitempty"`
ConfigSrc string `json:"config_src,omitempty"`
}

type TunnelUpdateParams struct {
Expand Down Expand Up @@ -179,10 +184,10 @@ type TunnelListParams struct {
ResultInfo
}

// Tunnels lists all tunnels.
// ListTunnels 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, *ResultInfo, error) {
func (api *API) ListTunnels(ctx context.Context, rc *ResourceContainer, params TunnelListParams) ([]Tunnel, *ResultInfo, error) {
if rc.Identifier == "" {
return []Tunnel{}, &ResultInfo{}, ErrMissingAccountID
}
Expand Down Expand Up @@ -225,10 +230,10 @@ func (api *API) Tunnels(ctx context.Context, rc *ResourceContainer, params Tunne
return records, &listResponse.ResultInfo, nil
}

// Tunnel returns a single Argo tunnel.
// GetTunnel returns a single Argo tunnel.
//
// API reference: https://api.cloudflare.com/#cloudflare-tunnel-get-cloudflare-tunnel
func (api *API) Tunnel(ctx context.Context, rc *ResourceContainer, tunnelID string) (Tunnel, error) {
func (api *API) GetTunnel(ctx context.Context, rc *ResourceContainer, tunnelID string) (Tunnel, error) {
if rc.Identifier == "" {
return Tunnel{}, ErrMissingAccountID
}
Expand Down Expand Up @@ -386,10 +391,10 @@ func (api *API) GetTunnelConfiguration(ctx context.Context, rc *ResourceContaine
return tunnelDetails, nil
}

// TunnelConnections gets all connections on a tunnel.
// ListTunnelConnections gets all connections on a tunnel.
//
// API reference: https://api.cloudflare.com/#cloudflare-tunnel-list-cloudflare-tunnel-connections
func (api *API) TunnelConnections(ctx context.Context, rc *ResourceContainer, tunnelID string) ([]Connection, error) {
func (api *API) ListTunnelConnections(ctx context.Context, rc *ResourceContainer, tunnelID string) ([]Connection, error) {
if rc.Identifier == "" {
return []Connection{}, ErrMissingAccountID
}
Expand Down Expand Up @@ -461,10 +466,10 @@ func (api *API) CleanupTunnelConnections(ctx context.Context, rc *ResourceContai
return nil
}

// TunnelToken that allows to run a tunnel.
// GetTunnelToken that allows to run a tunnel.
//
// API reference: https://api.cloudflare.com/#cloudflare-tunnel-get-cloudflare-tunnel-token
func (api *API) TunnelToken(ctx context.Context, rc *ResourceContainer, tunnelID string) (string, error) {
func (api *API) GetTunnelToken(ctx context.Context, rc *ResourceContainer, tunnelID string) (string, error) {
if rc.Identifier == "" {
return "", ErrMissingAccountID
}
Expand Down