-
Notifications
You must be signed in to change notification settings - Fork 542
/
gretunnel.go
588 lines (508 loc) · 19.9 KB
/
gretunnel.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package magic_transit
import (
"context"
"fmt"
"net/http"
"time"
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/cloudflare/cloudflare-go/v2/shared"
)
// GRETunnelService contains methods and other services that help with interacting
// with the cloudflare API. Note, unlike clients, this service does not read
// variables from the environment automatically. You should not instantiate this
// service directly, and instead use the [NewGRETunnelService] method instead.
type GRETunnelService struct {
Options []option.RequestOption
}
// NewGRETunnelService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewGRETunnelService(opts ...option.RequestOption) (r *GRETunnelService) {
r = &GRETunnelService{}
r.Options = opts
return
}
// Creates new GRE tunnels. Use `?validate_only=true` as an optional query
// parameter to only run validation without persisting changes.
func (r *GRETunnelService) New(ctx context.Context, params GRETunnelNewParams, opts ...option.RequestOption) (res *GRETunnelNewResponse, err error) {
opts = append(r.Options[:], opts...)
var env GRETunnelNewResponseEnvelope
path := fmt.Sprintf("accounts/%s/magic/gre_tunnels", params.AccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Updates a specific GRE tunnel. Use `?validate_only=true` as an optional query
// parameter to only run validation without persisting changes.
func (r *GRETunnelService) Update(ctx context.Context, tunnelIdentifier string, params GRETunnelUpdateParams, opts ...option.RequestOption) (res *GRETunnelUpdateResponse, err error) {
opts = append(r.Options[:], opts...)
var env GRETunnelUpdateResponseEnvelope
path := fmt.Sprintf("accounts/%s/magic/gre_tunnels/%s", params.AccountID, tunnelIdentifier)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Lists GRE tunnels associated with an account.
func (r *GRETunnelService) List(ctx context.Context, query GRETunnelListParams, opts ...option.RequestOption) (res *GRETunnelListResponse, err error) {
opts = append(r.Options[:], opts...)
var env GRETunnelListResponseEnvelope
path := fmt.Sprintf("accounts/%s/magic/gre_tunnels", query.AccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Disables and removes a specific static GRE tunnel. Use `?validate_only=true` as
// an optional query parameter to only run validation without persisting changes.
func (r *GRETunnelService) Delete(ctx context.Context, tunnelIdentifier string, body GRETunnelDeleteParams, opts ...option.RequestOption) (res *GRETunnelDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
var env GRETunnelDeleteResponseEnvelope
path := fmt.Sprintf("accounts/%s/magic/gre_tunnels/%s", body.AccountID, tunnelIdentifier)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Lists informtion for a specific GRE tunnel.
func (r *GRETunnelService) Get(ctx context.Context, tunnelIdentifier string, query GRETunnelGetParams, opts ...option.RequestOption) (res *GRETunnelGetResponse, err error) {
opts = append(r.Options[:], opts...)
var env GRETunnelGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/magic/gre_tunnels/%s", query.AccountID, tunnelIdentifier)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type GRETunnelNewResponse struct {
GRETunnels []GRETunnelNewResponseGRETunnel `json:"gre_tunnels"`
JSON greTunnelNewResponseJSON `json:"-"`
}
// greTunnelNewResponseJSON contains the JSON metadata for the struct
// [GRETunnelNewResponse]
type greTunnelNewResponseJSON struct {
GRETunnels apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *GRETunnelNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r greTunnelNewResponseJSON) RawJSON() string {
return r.raw
}
type GRETunnelNewResponseGRETunnel struct {
// The IP address assigned to the Cloudflare side of the GRE tunnel.
CloudflareGREEndpoint string `json:"cloudflare_gre_endpoint,required"`
// The IP address assigned to the customer side of the GRE tunnel.
CustomerGREEndpoint string `json:"customer_gre_endpoint,required"`
// A 31-bit prefix (/31 in CIDR notation) supporting two hosts, one for each side
// of the tunnel. Select the subnet from the following private IP space:
// 10.0.0.0–10.255.255.255, 172.16.0.0–172.31.255.255, 192.168.0.0–192.168.255.255.
InterfaceAddress string `json:"interface_address,required"`
// The name of the tunnel. The name cannot contain spaces or special characters,
// must be 15 characters or less, and cannot share a name with another GRE tunnel.
Name string `json:"name,required"`
// Tunnel identifier tag.
ID string `json:"id"`
// The date and time the tunnel was created.
CreatedOn time.Time `json:"created_on" format:"date-time"`
// An optional description of the GRE tunnel.
Description string `json:"description"`
HealthCheck HealthCheck `json:"health_check"`
// The date and time the tunnel was last modified.
ModifiedOn time.Time `json:"modified_on" format:"date-time"`
// Maximum Transmission Unit (MTU) in bytes for the GRE tunnel. The minimum value
// is 576.
Mtu int64 `json:"mtu"`
// Time To Live (TTL) in number of hops of the GRE tunnel.
TTL int64 `json:"ttl"`
JSON greTunnelNewResponseGRETunnelJSON `json:"-"`
}
// greTunnelNewResponseGRETunnelJSON contains the JSON metadata for the struct
// [GRETunnelNewResponseGRETunnel]
type greTunnelNewResponseGRETunnelJSON struct {
CloudflareGREEndpoint apijson.Field
CustomerGREEndpoint apijson.Field
InterfaceAddress apijson.Field
Name apijson.Field
ID apijson.Field
CreatedOn apijson.Field
Description apijson.Field
HealthCheck apijson.Field
ModifiedOn apijson.Field
Mtu apijson.Field
TTL apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *GRETunnelNewResponseGRETunnel) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r greTunnelNewResponseGRETunnelJSON) RawJSON() string {
return r.raw
}
type GRETunnelUpdateResponse struct {
Modified bool `json:"modified"`
ModifiedGRETunnel interface{} `json:"modified_gre_tunnel"`
JSON greTunnelUpdateResponseJSON `json:"-"`
}
// greTunnelUpdateResponseJSON contains the JSON metadata for the struct
// [GRETunnelUpdateResponse]
type greTunnelUpdateResponseJSON struct {
Modified apijson.Field
ModifiedGRETunnel apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *GRETunnelUpdateResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r greTunnelUpdateResponseJSON) RawJSON() string {
return r.raw
}
type GRETunnelListResponse struct {
GRETunnels []GRETunnelListResponseGRETunnel `json:"gre_tunnels"`
JSON greTunnelListResponseJSON `json:"-"`
}
// greTunnelListResponseJSON contains the JSON metadata for the struct
// [GRETunnelListResponse]
type greTunnelListResponseJSON struct {
GRETunnels apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *GRETunnelListResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r greTunnelListResponseJSON) RawJSON() string {
return r.raw
}
type GRETunnelListResponseGRETunnel struct {
// The IP address assigned to the Cloudflare side of the GRE tunnel.
CloudflareGREEndpoint string `json:"cloudflare_gre_endpoint,required"`
// The IP address assigned to the customer side of the GRE tunnel.
CustomerGREEndpoint string `json:"customer_gre_endpoint,required"`
// A 31-bit prefix (/31 in CIDR notation) supporting two hosts, one for each side
// of the tunnel. Select the subnet from the following private IP space:
// 10.0.0.0–10.255.255.255, 172.16.0.0–172.31.255.255, 192.168.0.0–192.168.255.255.
InterfaceAddress string `json:"interface_address,required"`
// The name of the tunnel. The name cannot contain spaces or special characters,
// must be 15 characters or less, and cannot share a name with another GRE tunnel.
Name string `json:"name,required"`
// Tunnel identifier tag.
ID string `json:"id"`
// The date and time the tunnel was created.
CreatedOn time.Time `json:"created_on" format:"date-time"`
// An optional description of the GRE tunnel.
Description string `json:"description"`
HealthCheck HealthCheck `json:"health_check"`
// The date and time the tunnel was last modified.
ModifiedOn time.Time `json:"modified_on" format:"date-time"`
// Maximum Transmission Unit (MTU) in bytes for the GRE tunnel. The minimum value
// is 576.
Mtu int64 `json:"mtu"`
// Time To Live (TTL) in number of hops of the GRE tunnel.
TTL int64 `json:"ttl"`
JSON greTunnelListResponseGRETunnelJSON `json:"-"`
}
// greTunnelListResponseGRETunnelJSON contains the JSON metadata for the struct
// [GRETunnelListResponseGRETunnel]
type greTunnelListResponseGRETunnelJSON struct {
CloudflareGREEndpoint apijson.Field
CustomerGREEndpoint apijson.Field
InterfaceAddress apijson.Field
Name apijson.Field
ID apijson.Field
CreatedOn apijson.Field
Description apijson.Field
HealthCheck apijson.Field
ModifiedOn apijson.Field
Mtu apijson.Field
TTL apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *GRETunnelListResponseGRETunnel) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r greTunnelListResponseGRETunnelJSON) RawJSON() string {
return r.raw
}
type GRETunnelDeleteResponse struct {
Deleted bool `json:"deleted"`
DeletedGRETunnel interface{} `json:"deleted_gre_tunnel"`
JSON greTunnelDeleteResponseJSON `json:"-"`
}
// greTunnelDeleteResponseJSON contains the JSON metadata for the struct
// [GRETunnelDeleteResponse]
type greTunnelDeleteResponseJSON struct {
Deleted apijson.Field
DeletedGRETunnel apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *GRETunnelDeleteResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r greTunnelDeleteResponseJSON) RawJSON() string {
return r.raw
}
type GRETunnelGetResponse struct {
GRETunnel interface{} `json:"gre_tunnel"`
JSON greTunnelGetResponseJSON `json:"-"`
}
// greTunnelGetResponseJSON contains the JSON metadata for the struct
// [GRETunnelGetResponse]
type greTunnelGetResponseJSON struct {
GRETunnel apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *GRETunnelGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r greTunnelGetResponseJSON) RawJSON() string {
return r.raw
}
type GRETunnelNewParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
Body interface{} `json:"body,required"`
}
func (r GRETunnelNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Body)
}
type GRETunnelNewResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result GRETunnelNewResponse `json:"result,required"`
// Whether the API call was successful
Success GRETunnelNewResponseEnvelopeSuccess `json:"success,required"`
JSON greTunnelNewResponseEnvelopeJSON `json:"-"`
}
// greTunnelNewResponseEnvelopeJSON contains the JSON metadata for the struct
// [GRETunnelNewResponseEnvelope]
type greTunnelNewResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *GRETunnelNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r greTunnelNewResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type GRETunnelNewResponseEnvelopeSuccess bool
const (
GRETunnelNewResponseEnvelopeSuccessTrue GRETunnelNewResponseEnvelopeSuccess = true
)
func (r GRETunnelNewResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case GRETunnelNewResponseEnvelopeSuccessTrue:
return true
}
return false
}
type GRETunnelUpdateParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
// The IP address assigned to the Cloudflare side of the GRE tunnel.
CloudflareGREEndpoint param.Field[string] `json:"cloudflare_gre_endpoint,required"`
// The IP address assigned to the customer side of the GRE tunnel.
CustomerGREEndpoint param.Field[string] `json:"customer_gre_endpoint,required"`
// A 31-bit prefix (/31 in CIDR notation) supporting two hosts, one for each side
// of the tunnel. Select the subnet from the following private IP space:
// 10.0.0.0–10.255.255.255, 172.16.0.0–172.31.255.255, 192.168.0.0–192.168.255.255.
InterfaceAddress param.Field[string] `json:"interface_address,required"`
// The name of the tunnel. The name cannot contain spaces or special characters,
// must be 15 characters or less, and cannot share a name with another GRE tunnel.
Name param.Field[string] `json:"name,required"`
// An optional description of the GRE tunnel.
Description param.Field[string] `json:"description"`
HealthCheck param.Field[HealthCheckParam] `json:"health_check"`
// Maximum Transmission Unit (MTU) in bytes for the GRE tunnel. The minimum value
// is 576.
Mtu param.Field[int64] `json:"mtu"`
// Time To Live (TTL) in number of hops of the GRE tunnel.
TTL param.Field[int64] `json:"ttl"`
}
func (r GRETunnelUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type GRETunnelUpdateResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result GRETunnelUpdateResponse `json:"result,required"`
// Whether the API call was successful
Success GRETunnelUpdateResponseEnvelopeSuccess `json:"success,required"`
JSON greTunnelUpdateResponseEnvelopeJSON `json:"-"`
}
// greTunnelUpdateResponseEnvelopeJSON contains the JSON metadata for the struct
// [GRETunnelUpdateResponseEnvelope]
type greTunnelUpdateResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *GRETunnelUpdateResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r greTunnelUpdateResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type GRETunnelUpdateResponseEnvelopeSuccess bool
const (
GRETunnelUpdateResponseEnvelopeSuccessTrue GRETunnelUpdateResponseEnvelopeSuccess = true
)
func (r GRETunnelUpdateResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case GRETunnelUpdateResponseEnvelopeSuccessTrue:
return true
}
return false
}
type GRETunnelListParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type GRETunnelListResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result GRETunnelListResponse `json:"result,required"`
// Whether the API call was successful
Success GRETunnelListResponseEnvelopeSuccess `json:"success,required"`
JSON greTunnelListResponseEnvelopeJSON `json:"-"`
}
// greTunnelListResponseEnvelopeJSON contains the JSON metadata for the struct
// [GRETunnelListResponseEnvelope]
type greTunnelListResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *GRETunnelListResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r greTunnelListResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type GRETunnelListResponseEnvelopeSuccess bool
const (
GRETunnelListResponseEnvelopeSuccessTrue GRETunnelListResponseEnvelopeSuccess = true
)
func (r GRETunnelListResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case GRETunnelListResponseEnvelopeSuccessTrue:
return true
}
return false
}
type GRETunnelDeleteParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type GRETunnelDeleteResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result GRETunnelDeleteResponse `json:"result,required"`
// Whether the API call was successful
Success GRETunnelDeleteResponseEnvelopeSuccess `json:"success,required"`
JSON greTunnelDeleteResponseEnvelopeJSON `json:"-"`
}
// greTunnelDeleteResponseEnvelopeJSON contains the JSON metadata for the struct
// [GRETunnelDeleteResponseEnvelope]
type greTunnelDeleteResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *GRETunnelDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r greTunnelDeleteResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type GRETunnelDeleteResponseEnvelopeSuccess bool
const (
GRETunnelDeleteResponseEnvelopeSuccessTrue GRETunnelDeleteResponseEnvelopeSuccess = true
)
func (r GRETunnelDeleteResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case GRETunnelDeleteResponseEnvelopeSuccessTrue:
return true
}
return false
}
type GRETunnelGetParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type GRETunnelGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result GRETunnelGetResponse `json:"result,required"`
// Whether the API call was successful
Success GRETunnelGetResponseEnvelopeSuccess `json:"success,required"`
JSON greTunnelGetResponseEnvelopeJSON `json:"-"`
}
// greTunnelGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [GRETunnelGetResponseEnvelope]
type greTunnelGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *GRETunnelGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r greTunnelGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type GRETunnelGetResponseEnvelopeSuccess bool
const (
GRETunnelGetResponseEnvelopeSuccessTrue GRETunnelGetResponseEnvelopeSuccess = true
)
func (r GRETunnelGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case GRETunnelGetResponseEnvelopeSuccessTrue:
return true
}
return false
}