forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteams_proxy_endpoints.go
137 lines (113 loc) · 4.47 KB
/
teams_proxy_endpoints.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package cloudflare
import (
"context"
"fmt"
"net/http"
"time"
"github.com/goccy/go-json"
)
type TeamsProxyEndpointListResponse struct {
Response
ResultInfo `json:"result_info"`
Result []TeamsProxyEndpoint `json:"result"`
}
type TeamsProxyEndpointDetailResponse struct {
Response
Result TeamsProxyEndpoint `json:"result"`
}
type TeamsProxyEndpoint struct {
ID string `json:"id"`
Name string `json:"name"`
IPs []string `json:"ips"`
Subdomain string `json:"subdomain"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
// TeamsProxyEndpoint returns a single proxy endpoints within an account.
//
// API reference: https://api.cloudflare.com/#zero-trust-gateway-proxy-endpoints-proxy-endpoint-details
func (api *API) TeamsProxyEndpoint(ctx context.Context, accountID, proxyEndpointID string) (TeamsProxyEndpoint, error) {
uri := fmt.Sprintf("/%s/%s/gateway/proxy_endpoints/%s", AccountRouteRoot, accountID, proxyEndpointID)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return TeamsProxyEndpoint{}, err
}
var teamsProxyEndpointDetailResponse TeamsProxyEndpointDetailResponse
err = json.Unmarshal(res, &teamsProxyEndpointDetailResponse)
if err != nil {
return TeamsProxyEndpoint{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return teamsProxyEndpointDetailResponse.Result, nil
}
// TeamsProxyEndpoints returns all proxy endpoints within an account.
//
// API reference: https://api.cloudflare.com/#zero-trust-gateway-proxy-endpoints-list-proxy-endpoints
func (api *API) TeamsProxyEndpoints(ctx context.Context, accountID string) ([]TeamsProxyEndpoint, ResultInfo, error) {
uri := fmt.Sprintf("/%s/%s/gateway/proxy_endpoints", AccountRouteRoot, accountID)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return []TeamsProxyEndpoint{}, ResultInfo{}, err
}
var teamsProxyEndpointListResponse TeamsProxyEndpointListResponse
err = json.Unmarshal(res, &teamsProxyEndpointListResponse)
if err != nil {
return []TeamsProxyEndpoint{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return teamsProxyEndpointListResponse.Result, teamsProxyEndpointListResponse.ResultInfo, nil
}
// CreateTeamsProxyEndpoint creates a new proxy endpoint.
//
// API reference: https://api.cloudflare.com/#zero-trust-gateway-proxy-endpoints-create-proxy-endpoint
func (api *API) CreateTeamsProxyEndpoint(ctx context.Context, accountID string, proxyEndpoint TeamsProxyEndpoint) (TeamsProxyEndpoint, error) {
uri := fmt.Sprintf("/%s/%s/gateway/proxy_endpoints", AccountRouteRoot, accountID)
res, err := api.makeRequestContext(ctx, http.MethodPost, uri, proxyEndpoint)
if err != nil {
return TeamsProxyEndpoint{}, err
}
var teamsProxyEndpointDetailResponse TeamsProxyEndpointDetailResponse
err = json.Unmarshal(res, &teamsProxyEndpointDetailResponse)
if err != nil {
return TeamsProxyEndpoint{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return teamsProxyEndpointDetailResponse.Result, nil
}
// UpdateTeamsProxyEndpoint updates an existing teams Proxy Endpoint.
//
// API reference: https://api.cloudflare.com/#zero-trust-gateway-proxy-endpoints-update-proxy-endpoint
func (api *API) UpdateTeamsProxyEndpoint(ctx context.Context, accountID string, proxyEndpoint TeamsProxyEndpoint) (TeamsProxyEndpoint, error) {
if proxyEndpoint.ID == "" {
return TeamsProxyEndpoint{}, fmt.Errorf("Proxy Endpoint ID cannot be empty")
}
uri := fmt.Sprintf(
"/%s/%s/gateway/proxy_endpoints/%s",
AccountRouteRoot,
accountID,
proxyEndpoint.ID,
)
res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, proxyEndpoint)
if err != nil {
return TeamsProxyEndpoint{}, err
}
var teamsProxyEndpointDetailResponse TeamsProxyEndpointDetailResponse
err = json.Unmarshal(res, &teamsProxyEndpointDetailResponse)
if err != nil {
return TeamsProxyEndpoint{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return teamsProxyEndpointDetailResponse.Result, nil
}
// DeleteTeamsProxyEndpoint deletes a teams Proxy Endpoint.
//
// API reference: https://api.cloudflare.com/#zero-trust-gateway-proxy-endpoints-delete-proxy-endpoint
func (api *API) DeleteTeamsProxyEndpoint(ctx context.Context, accountID, proxyEndpointID string) error {
uri := fmt.Sprintf(
"/%s/%s/gateway/proxy_endpoints/%s",
AccountRouteRoot,
accountID,
proxyEndpointID,
)
_, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil)
if err != nil {
return err
}
return nil
}