forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
teams_accounts.go
287 lines (233 loc) · 9.29 KB
/
teams_accounts.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package cloudflare
import (
"context"
"fmt"
"net/http"
"time"
"github.com/goccy/go-json"
)
type TeamsAccount struct {
GatewayTag string `json:"gateway_tag"` // Internal teams ID
ProviderName string `json:"provider_name"` // Auth provider
ID string `json:"id"` // cloudflare account ID
}
// TeamsAccountResponse is the API response, containing information on teams
// account.
type TeamsAccountResponse struct {
Response
Result TeamsAccount `json:"result"`
}
// TeamsConfigResponse is the API response, containing information on teams
// account config.
type TeamsConfigResponse struct {
Response
Result TeamsConfiguration `json:"result"`
}
// TeamsConfiguration data model.
type TeamsConfiguration struct {
Settings TeamsAccountSettings `json:"settings"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
}
type TeamsAccountSettings struct {
Antivirus *TeamsAntivirus `json:"antivirus,omitempty"`
TLSDecrypt *TeamsTLSDecrypt `json:"tls_decrypt,omitempty"`
ActivityLog *TeamsActivityLog `json:"activity_log,omitempty"`
BlockPage *TeamsBlockPage `json:"block_page,omitempty"`
BrowserIsolation *BrowserIsolation `json:"browser_isolation,omitempty"`
FIPS *TeamsFIPS `json:"fips,omitempty"`
ProtocolDetection *TeamsProtocolDetection `json:"protocol_detection,omitempty"`
BodyScanning *TeamsBodyScanning `json:"body_scanning,omitempty"`
ExtendedEmailMatching *TeamsExtendedEmailMatching `json:"extended_email_matching,omitempty"`
CustomCertificate *TeamsCustomCertificate `json:"custom_certificate,omitempty"`
}
type BrowserIsolation struct {
UrlBrowserIsolationEnabled *bool `json:"url_browser_isolation_enabled,omitempty"`
NonIdentityEnabled *bool `json:"non_identity_enabled,omitempty"`
}
type TeamsAntivirus struct {
EnabledDownloadPhase bool `json:"enabled_download_phase"`
EnabledUploadPhase bool `json:"enabled_upload_phase"`
FailClosed bool `json:"fail_closed"`
NotificationSettings *TeamsNotificationSettings `json:"notification_settings"`
}
type TeamsFIPS struct {
TLS bool `json:"tls"`
}
type TeamsTLSDecrypt struct {
Enabled bool `json:"enabled"`
}
type TeamsProtocolDetection struct {
Enabled bool `json:"enabled"`
}
type TeamsActivityLog struct {
Enabled bool `json:"enabled"`
}
type TeamsBlockPage struct {
Enabled *bool `json:"enabled,omitempty"`
FooterText string `json:"footer_text,omitempty"`
HeaderText string `json:"header_text,omitempty"`
LogoPath string `json:"logo_path,omitempty"`
BackgroundColor string `json:"background_color,omitempty"`
Name string `json:"name,omitempty"`
MailtoAddress string `json:"mailto_address,omitempty"`
MailtoSubject string `json:"mailto_subject,omitempty"`
SuppressFooter *bool `json:"suppress_footer,omitempty"`
}
type TeamsInspectionMode = string
const (
TeamsShallowInspectionMode TeamsInspectionMode = "shallow"
TeamsDeepInspectionMode TeamsInspectionMode = "deep"
)
type TeamsBodyScanning struct {
InspectionMode TeamsInspectionMode `json:"inspection_mode,omitempty"`
}
type TeamsExtendedEmailMatching struct {
Enabled *bool `json:"enabled,omitempty"`
}
type TeamsCustomCertificate struct {
Enabled *bool `json:"enabled,omitempty"`
ID string `json:"id,omitempty"`
BindingStatus string `json:"binding_status,omitempty"`
QsPackId string `json:"qs_pack_id,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
type TeamsRuleType = string
const (
TeamsHttpRuleType TeamsRuleType = "http"
TeamsDnsRuleType TeamsRuleType = "dns"
TeamsL4RuleType TeamsRuleType = "l4"
)
type TeamsAccountLoggingConfiguration struct {
LogAll bool `json:"log_all"`
LogBlocks bool `json:"log_blocks"`
}
type TeamsLoggingSettings struct {
LoggingSettingsByRuleType map[TeamsRuleType]TeamsAccountLoggingConfiguration `json:"settings_by_rule_type"`
RedactPii bool `json:"redact_pii,omitempty"`
}
type TeamsDeviceSettings struct {
GatewayProxyEnabled bool `json:"gateway_proxy_enabled"`
GatewayProxyUDPEnabled bool `json:"gateway_udp_proxy_enabled"`
RootCertificateInstallationEnabled bool `json:"root_certificate_installation_enabled"`
}
type TeamsDeviceSettingsResponse struct {
Response
Result TeamsDeviceSettings `json:"result"`
}
type TeamsLoggingSettingsResponse struct {
Response
Result TeamsLoggingSettings `json:"result"`
}
// TeamsAccount returns teams account information with internal and external ID.
//
// API reference: TBA.
func (api *API) TeamsAccount(ctx context.Context, accountID string) (TeamsAccount, error) {
uri := fmt.Sprintf("/accounts/%s/gateway", accountID)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return TeamsAccount{}, err
}
var teamsAccountResponse TeamsAccountResponse
err = json.Unmarshal(res, &teamsAccountResponse)
if err != nil {
return TeamsAccount{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return teamsAccountResponse.Result, nil
}
// TeamsAccountConfiguration returns teams account configuration.
//
// API reference: TBA.
func (api *API) TeamsAccountConfiguration(ctx context.Context, accountID string) (TeamsConfiguration, error) {
uri := fmt.Sprintf("/accounts/%s/gateway/configuration", accountID)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return TeamsConfiguration{}, err
}
var teamsConfigResponse TeamsConfigResponse
err = json.Unmarshal(res, &teamsConfigResponse)
if err != nil {
return TeamsConfiguration{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return teamsConfigResponse.Result, nil
}
// TeamsAccountDeviceConfiguration returns teams account device configuration with udp status.
//
// API reference: TBA.
func (api *API) TeamsAccountDeviceConfiguration(ctx context.Context, accountID string) (TeamsDeviceSettings, error) {
uri := fmt.Sprintf("/accounts/%s/devices/settings", accountID)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return TeamsDeviceSettings{}, err
}
var teamsDeviceResponse TeamsDeviceSettingsResponse
err = json.Unmarshal(res, &teamsDeviceResponse)
if err != nil {
return TeamsDeviceSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return teamsDeviceResponse.Result, nil
}
// TeamsAccountLoggingConfiguration returns teams account logging configuration.
//
// API reference: TBA.
func (api *API) TeamsAccountLoggingConfiguration(ctx context.Context, accountID string) (TeamsLoggingSettings, error) {
uri := fmt.Sprintf("/accounts/%s/gateway/logging", accountID)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return TeamsLoggingSettings{}, err
}
var teamsConfigResponse TeamsLoggingSettingsResponse
err = json.Unmarshal(res, &teamsConfigResponse)
if err != nil {
return TeamsLoggingSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return teamsConfigResponse.Result, nil
}
// TeamsAccountUpdateConfiguration updates a teams account configuration.
//
// API reference: TBA.
func (api *API) TeamsAccountUpdateConfiguration(ctx context.Context, accountID string, config TeamsConfiguration) (TeamsConfiguration, error) {
uri := fmt.Sprintf("/accounts/%s/gateway/configuration", accountID)
res, err := api.makeRequestContext(ctx, http.MethodPut, uri, config)
if err != nil {
return TeamsConfiguration{}, err
}
var teamsConfigResponse TeamsConfigResponse
err = json.Unmarshal(res, &teamsConfigResponse)
if err != nil {
return TeamsConfiguration{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return teamsConfigResponse.Result, nil
}
// TeamsAccountUpdateLoggingConfiguration updates the log settings and returns new teams account logging configuration.
//
// API reference: TBA.
func (api *API) TeamsAccountUpdateLoggingConfiguration(ctx context.Context, accountID string, config TeamsLoggingSettings) (TeamsLoggingSettings, error) {
uri := fmt.Sprintf("/accounts/%s/gateway/logging", accountID)
res, err := api.makeRequestContext(ctx, http.MethodPut, uri, config)
if err != nil {
return TeamsLoggingSettings{}, err
}
var teamsConfigResponse TeamsLoggingSettingsResponse
err = json.Unmarshal(res, &teamsConfigResponse)
if err != nil {
return TeamsLoggingSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return teamsConfigResponse.Result, nil
}
// TeamsAccountDeviceUpdateConfiguration updates teams account device configuration including udp filtering status.
//
// API reference: TBA.
func (api *API) TeamsAccountDeviceUpdateConfiguration(ctx context.Context, accountID string, settings TeamsDeviceSettings) (TeamsDeviceSettings, error) {
uri := fmt.Sprintf("/accounts/%s/devices/settings", accountID)
res, err := api.makeRequestContext(ctx, http.MethodPut, uri, settings)
if err != nil {
return TeamsDeviceSettings{}, err
}
var teamsDeviceResponse TeamsDeviceSettingsResponse
err = json.Unmarshal(res, &teamsDeviceResponse)
if err != nil {
return TeamsDeviceSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
return teamsDeviceResponse.Result, nil
}