/
tunnel.go
983 lines (875 loc) · 36.3 KB
/
tunnel.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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package zero_trust
import (
"context"
"fmt"
"net/http"
"net/url"
"reflect"
"time"
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/apiquery"
"github.com/cloudflare/cloudflare-go/v2/internal/pagination"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/internal/shared"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/tidwall/gjson"
)
// TunnelService 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 [NewTunnelService] method instead.
type TunnelService struct {
Options []option.RequestOption
Configurations *TunnelConfigurationService
Connections *TunnelConnectionService
Token *TunnelTokenService
Connectors *TunnelConnectorService
Management *TunnelManagementService
}
// NewTunnelService 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 NewTunnelService(opts ...option.RequestOption) (r *TunnelService) {
r = &TunnelService{}
r.Options = opts
r.Configurations = NewTunnelConfigurationService(opts...)
r.Connections = NewTunnelConnectionService(opts...)
r.Token = NewTunnelTokenService(opts...)
r.Connectors = NewTunnelConnectorService(opts...)
r.Management = NewTunnelManagementService(opts...)
return
}
// Creates a new Argo Tunnel in an account.
func (r *TunnelService) New(ctx context.Context, params TunnelNewParams, opts ...option.RequestOption) (res *TunnelNewResponse, err error) {
opts = append(r.Options[:], opts...)
var env TunnelNewResponseEnvelope
path := fmt.Sprintf("accounts/%s/tunnels", params.AccountID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Lists and filters all types of Tunnels in an account.
func (r *TunnelService) List(ctx context.Context, params TunnelListParams, opts ...option.RequestOption) (res *pagination.V4PagePaginationArray[TunnelListResponse], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := fmt.Sprintf("accounts/%s/tunnels", params.AccountID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Lists and filters all types of Tunnels in an account.
func (r *TunnelService) ListAutoPaging(ctx context.Context, params TunnelListParams, opts ...option.RequestOption) *pagination.V4PagePaginationArrayAutoPager[TunnelListResponse] {
return pagination.NewV4PagePaginationArrayAutoPager(r.List(ctx, params, opts...))
}
// Deletes an Argo Tunnel from an account.
func (r *TunnelService) Delete(ctx context.Context, tunnelID string, params TunnelDeleteParams, opts ...option.RequestOption) (res *TunnelDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
var env TunnelDeleteResponseEnvelope
path := fmt.Sprintf("accounts/%s/tunnels/%s", params.AccountID, tunnelID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Updates an existing Cloudflare Tunnel.
func (r *TunnelService) Edit(ctx context.Context, tunnelID string, params TunnelEditParams, opts ...option.RequestOption) (res *TunnelEditResponse, err error) {
opts = append(r.Options[:], opts...)
var env TunnelEditResponseEnvelope
path := fmt.Sprintf("accounts/%s/cfd_tunnel/%s", params.AccountID, tunnelID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Fetches a single Argo Tunnel.
func (r *TunnelService) Get(ctx context.Context, tunnelID string, query TunnelGetParams, opts ...option.RequestOption) (res *TunnelGetResponse, err error) {
opts = append(r.Options[:], opts...)
var env TunnelGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/tunnels/%s", query.AccountID, tunnelID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type Connection struct {
// The Cloudflare data center used for this connection.
ColoName string `json:"colo_name"`
// Cloudflare continues to track connections for several minutes after they
// disconnect. This is an optimization to improve latency and reliability of
// reconnecting. If `true`, the connection has disconnected but is still being
// tracked. If `false`, the connection is actively serving traffic.
IsPendingReconnect bool `json:"is_pending_reconnect"`
// UUID of the Cloudflare Tunnel connection.
UUID string `json:"uuid" format:"uuid"`
JSON connectionJSON `json:"-"`
}
// connectionJSON contains the JSON metadata for the struct [Connection]
type connectionJSON struct {
ColoName apijson.Field
IsPendingReconnect apijson.Field
UUID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Connection) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r connectionJSON) RawJSON() string {
return r.raw
}
type TunnelNewResponse struct {
// UUID of the tunnel.
ID string `json:"id,required" format:"uuid"`
// The tunnel connections between your origin and Cloudflare's edge.
Connections []Connection `json:"connections,required"`
// Timestamp of when the resource was created.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// A user-friendly name for a tunnel.
Name string `json:"name,required"`
// Timestamp of when the resource was deleted. If `null`, the resource has not been
// deleted.
DeletedAt time.Time `json:"deleted_at" format:"date-time"`
JSON tunnelNewResponseJSON `json:"-"`
}
// tunnelNewResponseJSON contains the JSON metadata for the struct
// [TunnelNewResponse]
type tunnelNewResponseJSON struct {
ID apijson.Field
Connections apijson.Field
CreatedAt apijson.Field
Name apijson.Field
DeletedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TunnelNewResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tunnelNewResponseJSON) RawJSON() string {
return r.raw
}
// A Cloudflare Tunnel that connects your origin to Cloudflare's edge.
type TunnelListResponse struct {
// Cloudflare account ID
AccountTag string `json:"account_tag"`
Connections interface{} `json:"connections,required"`
// Timestamp of when the tunnel established at least one connection to Cloudflare's
// edge. If `null`, the tunnel is inactive.
ConnsActiveAt time.Time `json:"conns_active_at" format:"date-time"`
// Timestamp of when the tunnel became inactive (no connections to Cloudflare's
// edge). If `null`, the tunnel is active.
ConnsInactiveAt time.Time `json:"conns_inactive_at" format:"date-time"`
// Timestamp of when the resource was created.
CreatedAt time.Time `json:"created_at" format:"date-time"`
// Timestamp of when the resource was deleted. If `null`, the resource has not been
// deleted.
DeletedAt time.Time `json:"deleted_at" format:"date-time"`
// UUID of the tunnel.
ID string `json:"id" format:"uuid"`
Metadata interface{} `json:"metadata,required"`
// A user-friendly name for a tunnel.
Name string `json:"name"`
// If `true`, the tunnel can be configured remotely from the Zero Trust dashboard.
// If `false`, the tunnel must be configured locally on the origin machine.
RemoteConfig bool `json:"remote_config"`
// The status of the tunnel. Valid values are `inactive` (tunnel has never been
// run), `degraded` (tunnel is active and able to serve traffic but in an unhealthy
// state), `healthy` (tunnel is active and able to serve traffic), or `down`
// (tunnel can not serve traffic as it has no connections to the Cloudflare Edge).
Status string `json:"status"`
// The type of tunnel.
TunType TunnelListResponseTunType `json:"tun_type"`
JSON tunnelListResponseJSON `json:"-"`
union TunnelListResponseUnion
}
// tunnelListResponseJSON contains the JSON metadata for the struct
// [TunnelListResponse]
type tunnelListResponseJSON struct {
AccountTag apijson.Field
Connections apijson.Field
ConnsActiveAt apijson.Field
ConnsInactiveAt apijson.Field
CreatedAt apijson.Field
DeletedAt apijson.Field
ID apijson.Field
Metadata apijson.Field
Name apijson.Field
RemoteConfig apijson.Field
Status apijson.Field
TunType apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r tunnelListResponseJSON) RawJSON() string {
return r.raw
}
func (r *TunnelListResponse) UnmarshalJSON(data []byte) (err error) {
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
func (r TunnelListResponse) AsUnion() TunnelListResponseUnion {
return r.union
}
// A Cloudflare Tunnel that connects your origin to Cloudflare's edge.
//
// Union satisfied by [shared.CloudflareTunnel] or
// [zero_trust.TunnelListResponseTunnelWARPConnectorTunnel].
type TunnelListResponseUnion interface {
ImplementsZeroTrustTunnelListResponse()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*TunnelListResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(shared.CloudflareTunnel{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(TunnelListResponseTunnelWARPConnectorTunnel{}),
},
)
}
// A Warp Connector Tunnel that connects your origin to Cloudflare's edge.
type TunnelListResponseTunnelWARPConnectorTunnel struct {
// UUID of the tunnel.
ID string `json:"id" format:"uuid"`
// Cloudflare account ID
AccountTag string `json:"account_tag"`
// The Cloudflare Tunnel connections between your origin and Cloudflare's edge.
Connections []TunnelListResponseTunnelWARPConnectorTunnelConnection `json:"connections"`
// Timestamp of when the tunnel established at least one connection to Cloudflare's
// edge. If `null`, the tunnel is inactive.
ConnsActiveAt time.Time `json:"conns_active_at" format:"date-time"`
// Timestamp of when the tunnel became inactive (no connections to Cloudflare's
// edge). If `null`, the tunnel is active.
ConnsInactiveAt time.Time `json:"conns_inactive_at" format:"date-time"`
// Timestamp of when the resource was created.
CreatedAt time.Time `json:"created_at" format:"date-time"`
// Timestamp of when the resource was deleted. If `null`, the resource has not been
// deleted.
DeletedAt time.Time `json:"deleted_at" format:"date-time"`
// Metadata associated with the tunnel.
Metadata interface{} `json:"metadata"`
// A user-friendly name for a tunnel.
Name string `json:"name"`
// The status of the tunnel. Valid values are `inactive` (tunnel has never been
// run), `degraded` (tunnel is active and able to serve traffic but in an unhealthy
// state), `healthy` (tunnel is active and able to serve traffic), or `down`
// (tunnel can not serve traffic as it has no connections to the Cloudflare Edge).
Status string `json:"status"`
// The type of tunnel.
TunType TunnelListResponseTunnelWARPConnectorTunnelTunType `json:"tun_type"`
JSON tunnelListResponseTunnelWARPConnectorTunnelJSON `json:"-"`
}
// tunnelListResponseTunnelWARPConnectorTunnelJSON contains the JSON metadata for
// the struct [TunnelListResponseTunnelWARPConnectorTunnel]
type tunnelListResponseTunnelWARPConnectorTunnelJSON struct {
ID apijson.Field
AccountTag apijson.Field
Connections apijson.Field
ConnsActiveAt apijson.Field
ConnsInactiveAt apijson.Field
CreatedAt apijson.Field
DeletedAt apijson.Field
Metadata apijson.Field
Name apijson.Field
Status apijson.Field
TunType apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TunnelListResponseTunnelWARPConnectorTunnel) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tunnelListResponseTunnelWARPConnectorTunnelJSON) RawJSON() string {
return r.raw
}
func (r TunnelListResponseTunnelWARPConnectorTunnel) ImplementsZeroTrustTunnelListResponse() {}
type TunnelListResponseTunnelWARPConnectorTunnelConnection struct {
// UUID of the Cloudflare Tunnel connection.
ID string `json:"id" format:"uuid"`
// UUID of the Cloudflare Tunnel connector.
ClientID string `json:"client_id" format:"uuid"`
// The cloudflared version used to establish this connection.
ClientVersion string `json:"client_version"`
// The Cloudflare data center used for this connection.
ColoName string `json:"colo_name"`
// Cloudflare continues to track connections for several minutes after they
// disconnect. This is an optimization to improve latency and reliability of
// reconnecting. If `true`, the connection has disconnected but is still being
// tracked. If `false`, the connection is actively serving traffic.
IsPendingReconnect bool `json:"is_pending_reconnect"`
// Timestamp of when the connection was established.
OpenedAt time.Time `json:"opened_at" format:"date-time"`
// The public IP address of the host running cloudflared.
OriginIP string `json:"origin_ip"`
// UUID of the Cloudflare Tunnel connection.
UUID string `json:"uuid" format:"uuid"`
JSON tunnelListResponseTunnelWARPConnectorTunnelConnectionJSON `json:"-"`
}
// tunnelListResponseTunnelWARPConnectorTunnelConnectionJSON contains the JSON
// metadata for the struct [TunnelListResponseTunnelWARPConnectorTunnelConnection]
type tunnelListResponseTunnelWARPConnectorTunnelConnectionJSON struct {
ID apijson.Field
ClientID apijson.Field
ClientVersion apijson.Field
ColoName apijson.Field
IsPendingReconnect apijson.Field
OpenedAt apijson.Field
OriginIP apijson.Field
UUID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TunnelListResponseTunnelWARPConnectorTunnelConnection) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tunnelListResponseTunnelWARPConnectorTunnelConnectionJSON) RawJSON() string {
return r.raw
}
// The type of tunnel.
type TunnelListResponseTunnelWARPConnectorTunnelTunType string
const (
TunnelListResponseTunnelWARPConnectorTunnelTunTypeCfdTunnel TunnelListResponseTunnelWARPConnectorTunnelTunType = "cfd_tunnel"
TunnelListResponseTunnelWARPConnectorTunnelTunTypeWARPConnector TunnelListResponseTunnelWARPConnectorTunnelTunType = "warp_connector"
TunnelListResponseTunnelWARPConnectorTunnelTunTypeIPSec TunnelListResponseTunnelWARPConnectorTunnelTunType = "ip_sec"
TunnelListResponseTunnelWARPConnectorTunnelTunTypeGRE TunnelListResponseTunnelWARPConnectorTunnelTunType = "gre"
TunnelListResponseTunnelWARPConnectorTunnelTunTypeCNI TunnelListResponseTunnelWARPConnectorTunnelTunType = "cni"
)
func (r TunnelListResponseTunnelWARPConnectorTunnelTunType) IsKnown() bool {
switch r {
case TunnelListResponseTunnelWARPConnectorTunnelTunTypeCfdTunnel, TunnelListResponseTunnelWARPConnectorTunnelTunTypeWARPConnector, TunnelListResponseTunnelWARPConnectorTunnelTunTypeIPSec, TunnelListResponseTunnelWARPConnectorTunnelTunTypeGRE, TunnelListResponseTunnelWARPConnectorTunnelTunTypeCNI:
return true
}
return false
}
// The type of tunnel.
type TunnelListResponseTunType string
const (
TunnelListResponseTunTypeCfdTunnel TunnelListResponseTunType = "cfd_tunnel"
TunnelListResponseTunTypeWARPConnector TunnelListResponseTunType = "warp_connector"
TunnelListResponseTunTypeIPSec TunnelListResponseTunType = "ip_sec"
TunnelListResponseTunTypeGRE TunnelListResponseTunType = "gre"
TunnelListResponseTunTypeCNI TunnelListResponseTunType = "cni"
)
func (r TunnelListResponseTunType) IsKnown() bool {
switch r {
case TunnelListResponseTunTypeCfdTunnel, TunnelListResponseTunTypeWARPConnector, TunnelListResponseTunTypeIPSec, TunnelListResponseTunTypeGRE, TunnelListResponseTunTypeCNI:
return true
}
return false
}
type TunnelDeleteResponse struct {
// UUID of the tunnel.
ID string `json:"id,required" format:"uuid"`
// The tunnel connections between your origin and Cloudflare's edge.
Connections []Connection `json:"connections,required"`
// Timestamp of when the resource was created.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// A user-friendly name for a tunnel.
Name string `json:"name,required"`
// Timestamp of when the resource was deleted. If `null`, the resource has not been
// deleted.
DeletedAt time.Time `json:"deleted_at" format:"date-time"`
JSON tunnelDeleteResponseJSON `json:"-"`
}
// tunnelDeleteResponseJSON contains the JSON metadata for the struct
// [TunnelDeleteResponse]
type tunnelDeleteResponseJSON struct {
ID apijson.Field
Connections apijson.Field
CreatedAt apijson.Field
Name apijson.Field
DeletedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TunnelDeleteResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tunnelDeleteResponseJSON) RawJSON() string {
return r.raw
}
// A Cloudflare Tunnel that connects your origin to Cloudflare's edge.
type TunnelEditResponse struct {
// Cloudflare account ID
AccountTag string `json:"account_tag"`
Connections interface{} `json:"connections,required"`
// Timestamp of when the tunnel established at least one connection to Cloudflare's
// edge. If `null`, the tunnel is inactive.
ConnsActiveAt time.Time `json:"conns_active_at" format:"date-time"`
// Timestamp of when the tunnel became inactive (no connections to Cloudflare's
// edge). If `null`, the tunnel is active.
ConnsInactiveAt time.Time `json:"conns_inactive_at" format:"date-time"`
// Timestamp of when the resource was created.
CreatedAt time.Time `json:"created_at" format:"date-time"`
// Timestamp of when the resource was deleted. If `null`, the resource has not been
// deleted.
DeletedAt time.Time `json:"deleted_at" format:"date-time"`
// UUID of the tunnel.
ID string `json:"id" format:"uuid"`
Metadata interface{} `json:"metadata,required"`
// A user-friendly name for a tunnel.
Name string `json:"name"`
// If `true`, the tunnel can be configured remotely from the Zero Trust dashboard.
// If `false`, the tunnel must be configured locally on the origin machine.
RemoteConfig bool `json:"remote_config"`
// The status of the tunnel. Valid values are `inactive` (tunnel has never been
// run), `degraded` (tunnel is active and able to serve traffic but in an unhealthy
// state), `healthy` (tunnel is active and able to serve traffic), or `down`
// (tunnel can not serve traffic as it has no connections to the Cloudflare Edge).
Status string `json:"status"`
// The type of tunnel.
TunType TunnelEditResponseTunType `json:"tun_type"`
JSON tunnelEditResponseJSON `json:"-"`
union TunnelEditResponseUnion
}
// tunnelEditResponseJSON contains the JSON metadata for the struct
// [TunnelEditResponse]
type tunnelEditResponseJSON struct {
AccountTag apijson.Field
Connections apijson.Field
ConnsActiveAt apijson.Field
ConnsInactiveAt apijson.Field
CreatedAt apijson.Field
DeletedAt apijson.Field
ID apijson.Field
Metadata apijson.Field
Name apijson.Field
RemoteConfig apijson.Field
Status apijson.Field
TunType apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r tunnelEditResponseJSON) RawJSON() string {
return r.raw
}
func (r *TunnelEditResponse) UnmarshalJSON(data []byte) (err error) {
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
func (r TunnelEditResponse) AsUnion() TunnelEditResponseUnion {
return r.union
}
// A Cloudflare Tunnel that connects your origin to Cloudflare's edge.
//
// Union satisfied by [shared.CloudflareTunnel] or
// [zero_trust.TunnelEditResponseTunnelWARPConnectorTunnel].
type TunnelEditResponseUnion interface {
ImplementsZeroTrustTunnelEditResponse()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*TunnelEditResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(shared.CloudflareTunnel{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(TunnelEditResponseTunnelWARPConnectorTunnel{}),
},
)
}
// A Warp Connector Tunnel that connects your origin to Cloudflare's edge.
type TunnelEditResponseTunnelWARPConnectorTunnel struct {
// UUID of the tunnel.
ID string `json:"id" format:"uuid"`
// Cloudflare account ID
AccountTag string `json:"account_tag"`
// The Cloudflare Tunnel connections between your origin and Cloudflare's edge.
Connections []TunnelEditResponseTunnelWARPConnectorTunnelConnection `json:"connections"`
// Timestamp of when the tunnel established at least one connection to Cloudflare's
// edge. If `null`, the tunnel is inactive.
ConnsActiveAt time.Time `json:"conns_active_at" format:"date-time"`
// Timestamp of when the tunnel became inactive (no connections to Cloudflare's
// edge). If `null`, the tunnel is active.
ConnsInactiveAt time.Time `json:"conns_inactive_at" format:"date-time"`
// Timestamp of when the resource was created.
CreatedAt time.Time `json:"created_at" format:"date-time"`
// Timestamp of when the resource was deleted. If `null`, the resource has not been
// deleted.
DeletedAt time.Time `json:"deleted_at" format:"date-time"`
// Metadata associated with the tunnel.
Metadata interface{} `json:"metadata"`
// A user-friendly name for a tunnel.
Name string `json:"name"`
// The status of the tunnel. Valid values are `inactive` (tunnel has never been
// run), `degraded` (tunnel is active and able to serve traffic but in an unhealthy
// state), `healthy` (tunnel is active and able to serve traffic), or `down`
// (tunnel can not serve traffic as it has no connections to the Cloudflare Edge).
Status string `json:"status"`
// The type of tunnel.
TunType TunnelEditResponseTunnelWARPConnectorTunnelTunType `json:"tun_type"`
JSON tunnelEditResponseTunnelWARPConnectorTunnelJSON `json:"-"`
}
// tunnelEditResponseTunnelWARPConnectorTunnelJSON contains the JSON metadata for
// the struct [TunnelEditResponseTunnelWARPConnectorTunnel]
type tunnelEditResponseTunnelWARPConnectorTunnelJSON struct {
ID apijson.Field
AccountTag apijson.Field
Connections apijson.Field
ConnsActiveAt apijson.Field
ConnsInactiveAt apijson.Field
CreatedAt apijson.Field
DeletedAt apijson.Field
Metadata apijson.Field
Name apijson.Field
Status apijson.Field
TunType apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TunnelEditResponseTunnelWARPConnectorTunnel) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tunnelEditResponseTunnelWARPConnectorTunnelJSON) RawJSON() string {
return r.raw
}
func (r TunnelEditResponseTunnelWARPConnectorTunnel) ImplementsZeroTrustTunnelEditResponse() {}
type TunnelEditResponseTunnelWARPConnectorTunnelConnection struct {
// UUID of the Cloudflare Tunnel connection.
ID string `json:"id" format:"uuid"`
// UUID of the Cloudflare Tunnel connector.
ClientID string `json:"client_id" format:"uuid"`
// The cloudflared version used to establish this connection.
ClientVersion string `json:"client_version"`
// The Cloudflare data center used for this connection.
ColoName string `json:"colo_name"`
// Cloudflare continues to track connections for several minutes after they
// disconnect. This is an optimization to improve latency and reliability of
// reconnecting. If `true`, the connection has disconnected but is still being
// tracked. If `false`, the connection is actively serving traffic.
IsPendingReconnect bool `json:"is_pending_reconnect"`
// Timestamp of when the connection was established.
OpenedAt time.Time `json:"opened_at" format:"date-time"`
// The public IP address of the host running cloudflared.
OriginIP string `json:"origin_ip"`
// UUID of the Cloudflare Tunnel connection.
UUID string `json:"uuid" format:"uuid"`
JSON tunnelEditResponseTunnelWARPConnectorTunnelConnectionJSON `json:"-"`
}
// tunnelEditResponseTunnelWARPConnectorTunnelConnectionJSON contains the JSON
// metadata for the struct [TunnelEditResponseTunnelWARPConnectorTunnelConnection]
type tunnelEditResponseTunnelWARPConnectorTunnelConnectionJSON struct {
ID apijson.Field
ClientID apijson.Field
ClientVersion apijson.Field
ColoName apijson.Field
IsPendingReconnect apijson.Field
OpenedAt apijson.Field
OriginIP apijson.Field
UUID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TunnelEditResponseTunnelWARPConnectorTunnelConnection) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tunnelEditResponseTunnelWARPConnectorTunnelConnectionJSON) RawJSON() string {
return r.raw
}
// The type of tunnel.
type TunnelEditResponseTunnelWARPConnectorTunnelTunType string
const (
TunnelEditResponseTunnelWARPConnectorTunnelTunTypeCfdTunnel TunnelEditResponseTunnelWARPConnectorTunnelTunType = "cfd_tunnel"
TunnelEditResponseTunnelWARPConnectorTunnelTunTypeWARPConnector TunnelEditResponseTunnelWARPConnectorTunnelTunType = "warp_connector"
TunnelEditResponseTunnelWARPConnectorTunnelTunTypeIPSec TunnelEditResponseTunnelWARPConnectorTunnelTunType = "ip_sec"
TunnelEditResponseTunnelWARPConnectorTunnelTunTypeGRE TunnelEditResponseTunnelWARPConnectorTunnelTunType = "gre"
TunnelEditResponseTunnelWARPConnectorTunnelTunTypeCNI TunnelEditResponseTunnelWARPConnectorTunnelTunType = "cni"
)
func (r TunnelEditResponseTunnelWARPConnectorTunnelTunType) IsKnown() bool {
switch r {
case TunnelEditResponseTunnelWARPConnectorTunnelTunTypeCfdTunnel, TunnelEditResponseTunnelWARPConnectorTunnelTunTypeWARPConnector, TunnelEditResponseTunnelWARPConnectorTunnelTunTypeIPSec, TunnelEditResponseTunnelWARPConnectorTunnelTunTypeGRE, TunnelEditResponseTunnelWARPConnectorTunnelTunTypeCNI:
return true
}
return false
}
// The type of tunnel.
type TunnelEditResponseTunType string
const (
TunnelEditResponseTunTypeCfdTunnel TunnelEditResponseTunType = "cfd_tunnel"
TunnelEditResponseTunTypeWARPConnector TunnelEditResponseTunType = "warp_connector"
TunnelEditResponseTunTypeIPSec TunnelEditResponseTunType = "ip_sec"
TunnelEditResponseTunTypeGRE TunnelEditResponseTunType = "gre"
TunnelEditResponseTunTypeCNI TunnelEditResponseTunType = "cni"
)
func (r TunnelEditResponseTunType) IsKnown() bool {
switch r {
case TunnelEditResponseTunTypeCfdTunnel, TunnelEditResponseTunTypeWARPConnector, TunnelEditResponseTunTypeIPSec, TunnelEditResponseTunTypeGRE, TunnelEditResponseTunTypeCNI:
return true
}
return false
}
type TunnelGetResponse struct {
// UUID of the tunnel.
ID string `json:"id,required" format:"uuid"`
// The tunnel connections between your origin and Cloudflare's edge.
Connections []Connection `json:"connections,required"`
// Timestamp of when the resource was created.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// A user-friendly name for a tunnel.
Name string `json:"name,required"`
// Timestamp of when the resource was deleted. If `null`, the resource has not been
// deleted.
DeletedAt time.Time `json:"deleted_at" format:"date-time"`
JSON tunnelGetResponseJSON `json:"-"`
}
// tunnelGetResponseJSON contains the JSON metadata for the struct
// [TunnelGetResponse]
type tunnelGetResponseJSON struct {
ID apijson.Field
Connections apijson.Field
CreatedAt apijson.Field
Name apijson.Field
DeletedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TunnelGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tunnelGetResponseJSON) RawJSON() string {
return r.raw
}
type TunnelNewParams struct {
// Cloudflare account ID
AccountID param.Field[string] `path:"account_id,required"`
// A user-friendly name for a tunnel.
Name param.Field[string] `json:"name,required"`
// Sets the password required to run a locally-managed tunnel. Must be at least 32
// bytes and encoded as a base64 string.
TunnelSecret param.Field[string] `json:"tunnel_secret,required"`
}
func (r TunnelNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type TunnelNewResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result TunnelNewResponse `json:"result,required"`
// Whether the API call was successful
Success TunnelNewResponseEnvelopeSuccess `json:"success,required"`
JSON tunnelNewResponseEnvelopeJSON `json:"-"`
}
// tunnelNewResponseEnvelopeJSON contains the JSON metadata for the struct
// [TunnelNewResponseEnvelope]
type tunnelNewResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TunnelNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tunnelNewResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type TunnelNewResponseEnvelopeSuccess bool
const (
TunnelNewResponseEnvelopeSuccessTrue TunnelNewResponseEnvelopeSuccess = true
)
func (r TunnelNewResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case TunnelNewResponseEnvelopeSuccessTrue:
return true
}
return false
}
type TunnelListParams struct {
// Cloudflare account ID
AccountID param.Field[string] `path:"account_id,required"`
ExcludePrefix param.Field[string] `query:"exclude_prefix"`
// If provided, include only tunnels that were created (and not deleted) before
// this time.
ExistedAt param.Field[time.Time] `query:"existed_at" format:"date-time"`
IncludePrefix param.Field[string] `query:"include_prefix"`
// If `true`, only include deleted tunnels. If `false`, exclude deleted tunnels. If
// empty, all tunnels will be included.
IsDeleted param.Field[bool] `query:"is_deleted"`
// A user-friendly name for the tunnel.
Name param.Field[string] `query:"name"`
// Page number of paginated results.
Page param.Field[float64] `query:"page"`
// Number of results to display.
PerPage param.Field[float64] `query:"per_page"`
// The types of tunnels to filter separated by a comma.
TunTypes param.Field[string] `query:"tun_types"`
// UUID of the tunnel.
UUID param.Field[string] `query:"uuid" format:"uuid"`
WasActiveAt param.Field[time.Time] `query:"was_active_at" format:"date-time"`
WasInactiveAt param.Field[time.Time] `query:"was_inactive_at" format:"date-time"`
}
// URLQuery serializes [TunnelListParams]'s query parameters as `url.Values`.
func (r TunnelListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type TunnelDeleteParams struct {
// Cloudflare account ID
AccountID param.Field[string] `path:"account_id,required"`
Body interface{} `json:"body,required"`
}
func (r TunnelDeleteParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r.Body)
}
type TunnelDeleteResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result TunnelDeleteResponse `json:"result,required"`
// Whether the API call was successful
Success TunnelDeleteResponseEnvelopeSuccess `json:"success,required"`
JSON tunnelDeleteResponseEnvelopeJSON `json:"-"`
}
// tunnelDeleteResponseEnvelopeJSON contains the JSON metadata for the struct
// [TunnelDeleteResponseEnvelope]
type tunnelDeleteResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TunnelDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tunnelDeleteResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type TunnelDeleteResponseEnvelopeSuccess bool
const (
TunnelDeleteResponseEnvelopeSuccessTrue TunnelDeleteResponseEnvelopeSuccess = true
)
func (r TunnelDeleteResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case TunnelDeleteResponseEnvelopeSuccessTrue:
return true
}
return false
}
type TunnelEditParams struct {
// Cloudflare account ID
AccountID param.Field[string] `path:"account_id,required"`
// A user-friendly name for a tunnel.
Name param.Field[string] `json:"name"`
// Sets the password required to run a locally-managed tunnel. Must be at least 32
// bytes and encoded as a base64 string.
TunnelSecret param.Field[string] `json:"tunnel_secret"`
}
func (r TunnelEditParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type TunnelEditResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// A Cloudflare Tunnel that connects your origin to Cloudflare's edge.
Result TunnelEditResponse `json:"result,required"`
// Whether the API call was successful
Success TunnelEditResponseEnvelopeSuccess `json:"success,required"`
JSON tunnelEditResponseEnvelopeJSON `json:"-"`
}
// tunnelEditResponseEnvelopeJSON contains the JSON metadata for the struct
// [TunnelEditResponseEnvelope]
type tunnelEditResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TunnelEditResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tunnelEditResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type TunnelEditResponseEnvelopeSuccess bool
const (
TunnelEditResponseEnvelopeSuccessTrue TunnelEditResponseEnvelopeSuccess = true
)
func (r TunnelEditResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case TunnelEditResponseEnvelopeSuccessTrue:
return true
}
return false
}
type TunnelGetParams struct {
// Cloudflare account ID
AccountID param.Field[string] `path:"account_id,required"`
}
type TunnelGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result TunnelGetResponse `json:"result,required"`
// Whether the API call was successful
Success TunnelGetResponseEnvelopeSuccess `json:"success,required"`
JSON tunnelGetResponseEnvelopeJSON `json:"-"`
}
// tunnelGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [TunnelGetResponseEnvelope]
type tunnelGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TunnelGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r tunnelGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type TunnelGetResponseEnvelopeSuccess bool
const (
TunnelGetResponseEnvelopeSuccessTrue TunnelGetResponseEnvelopeSuccess = true
)
func (r TunnelGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case TunnelGetResponseEnvelopeSuccessTrue:
return true
}
return false
}