/
spectrum.go
384 lines (327 loc) · 11.5 KB
/
spectrum.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package spectrum
import (
"reflect"
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"github.com/cloudflare/cloudflare-go/v2/internal/shared"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/tidwall/gjson"
)
// SpectrumService 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 [NewSpectrumService] method instead.
type SpectrumService struct {
Options []option.RequestOption
Analytics *AnalyticsService
Apps *AppService
}
// NewSpectrumService 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 NewSpectrumService(opts ...option.RequestOption) (r *SpectrumService) {
r = &SpectrumService{}
r.Options = opts
r.Analytics = NewAnalyticsService(opts...)
r.Apps = NewAppService(opts...)
return
}
// The name and type of DNS record for the Spectrum application.
type DNS struct {
// The name of the DNS record associated with the application.
Name string `json:"name" format:"hostname"`
// The type of DNS record associated with the application.
Type DNSType `json:"type"`
JSON dnsJSON `json:"-"`
}
// dnsJSON contains the JSON metadata for the struct [DNS]
type dnsJSON struct {
Name apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DNS) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r dnsJSON) RawJSON() string {
return r.raw
}
// The type of DNS record associated with the application.
type DNSType string
const (
DNSTypeCNAME DNSType = "CNAME"
DNSTypeAddress DNSType = "ADDRESS"
)
func (r DNSType) IsKnown() bool {
switch r {
case DNSTypeCNAME, DNSTypeAddress:
return true
}
return false
}
// The name and type of DNS record for the Spectrum application.
type DNSParam struct {
// The name of the DNS record associated with the application.
Name param.Field[string] `json:"name" format:"hostname"`
// The type of DNS record associated with the application.
Type param.Field[DNSType] `json:"type"`
}
func (r DNSParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// The anycast edge IP configuration for the hostname of this application.
type EdgeIPs struct {
// The IP versions supported for inbound connections on Spectrum anycast IPs.
Connectivity EdgeIPsConnectivity `json:"connectivity"`
// The type of edge IP configuration specified. Dynamically allocated edge IPs use
// Spectrum anycast IPs in accordance with the connectivity you specify. Only valid
// with CNAME DNS names.
Type EdgeIPsType `json:"type"`
IPs interface{} `json:"ips,required"`
JSON edgeIPsJSON `json:"-"`
union EdgeIPsUnion
}
// edgeIPsJSON contains the JSON metadata for the struct [EdgeIPs]
type edgeIPsJSON struct {
Connectivity apijson.Field
Type apijson.Field
IPs apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r edgeIPsJSON) RawJSON() string {
return r.raw
}
func (r *EdgeIPs) UnmarshalJSON(data []byte) (err error) {
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
func (r EdgeIPs) AsUnion() EdgeIPsUnion {
return r.union
}
// The anycast edge IP configuration for the hostname of this application.
//
// Union satisfied by [spectrum.EdgeIPsObject] or [spectrum.EdgeIPsObject].
type EdgeIPsUnion interface {
implementsSpectrumEdgeIPs()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*EdgeIPsUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(EdgeIPsObject{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(EdgeIPsObject{}),
},
)
}
type EdgeIPsObject struct {
// The IP versions supported for inbound connections on Spectrum anycast IPs.
Connectivity EdgeIPsObjectConnectivity `json:"connectivity"`
// The type of edge IP configuration specified. Dynamically allocated edge IPs use
// Spectrum anycast IPs in accordance with the connectivity you specify. Only valid
// with CNAME DNS names.
Type EdgeIPsObjectType `json:"type"`
JSON edgeIPsObjectJSON `json:"-"`
}
// edgeIPsObjectJSON contains the JSON metadata for the struct [EdgeIPsObject]
type edgeIPsObjectJSON struct {
Connectivity apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *EdgeIPsObject) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r edgeIPsObjectJSON) RawJSON() string {
return r.raw
}
func (r EdgeIPsObject) implementsSpectrumEdgeIPs() {}
// The IP versions supported for inbound connections on Spectrum anycast IPs.
type EdgeIPsObjectConnectivity string
const (
EdgeIPsObjectConnectivityAll EdgeIPsObjectConnectivity = "all"
EdgeIPsObjectConnectivityIPV4 EdgeIPsObjectConnectivity = "ipv4"
EdgeIPsObjectConnectivityIPV6 EdgeIPsObjectConnectivity = "ipv6"
)
func (r EdgeIPsObjectConnectivity) IsKnown() bool {
switch r {
case EdgeIPsObjectConnectivityAll, EdgeIPsObjectConnectivityIPV4, EdgeIPsObjectConnectivityIPV6:
return true
}
return false
}
// The type of edge IP configuration specified. Dynamically allocated edge IPs use
// Spectrum anycast IPs in accordance with the connectivity you specify. Only valid
// with CNAME DNS names.
type EdgeIPsObjectType string
const (
EdgeIPsObjectTypeDynamic EdgeIPsObjectType = "dynamic"
)
func (r EdgeIPsObjectType) IsKnown() bool {
switch r {
case EdgeIPsObjectTypeDynamic:
return true
}
return false
}
// The IP versions supported for inbound connections on Spectrum anycast IPs.
type EdgeIPsConnectivity string
const (
EdgeIPsConnectivityAll EdgeIPsConnectivity = "all"
EdgeIPsConnectivityIPV4 EdgeIPsConnectivity = "ipv4"
EdgeIPsConnectivityIPV6 EdgeIPsConnectivity = "ipv6"
)
func (r EdgeIPsConnectivity) IsKnown() bool {
switch r {
case EdgeIPsConnectivityAll, EdgeIPsConnectivityIPV4, EdgeIPsConnectivityIPV6:
return true
}
return false
}
// The type of edge IP configuration specified. Dynamically allocated edge IPs use
// Spectrum anycast IPs in accordance with the connectivity you specify. Only valid
// with CNAME DNS names.
type EdgeIPsType string
const (
EdgeIPsTypeDynamic EdgeIPsType = "dynamic"
EdgeIPsTypeStatic EdgeIPsType = "static"
)
func (r EdgeIPsType) IsKnown() bool {
switch r {
case EdgeIPsTypeDynamic, EdgeIPsTypeStatic:
return true
}
return false
}
// The anycast edge IP configuration for the hostname of this application.
type EdgeIPsParam struct {
// The IP versions supported for inbound connections on Spectrum anycast IPs.
Connectivity param.Field[EdgeIPsConnectivity] `json:"connectivity"`
// The type of edge IP configuration specified. Dynamically allocated edge IPs use
// Spectrum anycast IPs in accordance with the connectivity you specify. Only valid
// with CNAME DNS names.
Type param.Field[EdgeIPsType] `json:"type"`
IPs param.Field[interface{}] `json:"ips,required"`
}
func (r EdgeIPsParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r EdgeIPsParam) implementsSpectrumEdgeIPsUnionParam() {}
// The anycast edge IP configuration for the hostname of this application.
//
// Satisfied by [spectrum.EdgeIPsObjectParam], [spectrum.EdgeIPsObjectParam],
// [EdgeIPsParam].
type EdgeIPsUnionParam interface {
implementsSpectrumEdgeIPsUnionParam()
}
type EdgeIPsObjectParam struct {
// The IP versions supported for inbound connections on Spectrum anycast IPs.
Connectivity param.Field[EdgeIPsObjectConnectivity] `json:"connectivity"`
// The type of edge IP configuration specified. Dynamically allocated edge IPs use
// Spectrum anycast IPs in accordance with the connectivity you specify. Only valid
// with CNAME DNS names.
Type param.Field[EdgeIPsObjectType] `json:"type"`
}
func (r EdgeIPsObjectParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r EdgeIPsObjectParam) implementsSpectrumEdgeIPsUnionParam() {}
// The name and type of DNS record for the Spectrum application.
type OriginDNS struct {
// The name of the DNS record associated with the origin.
Name string `json:"name" format:"hostname"`
// The TTL of our resolution of your DNS record in seconds.
TTL int64 `json:"ttl"`
// The type of DNS record associated with the origin. "" is used to specify a
// combination of A/AAAA records.
Type OriginDNSType `json:"type"`
JSON originDNSJSON `json:"-"`
}
// originDNSJSON contains the JSON metadata for the struct [OriginDNS]
type originDNSJSON struct {
Name apijson.Field
TTL apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *OriginDNS) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r originDNSJSON) RawJSON() string {
return r.raw
}
// The type of DNS record associated with the origin. "" is used to specify a
// combination of A/AAAA records.
type OriginDNSType string
const (
OriginDNSTypeEmpty OriginDNSType = ""
OriginDNSTypeA OriginDNSType = "A"
OriginDNSTypeAAAA OriginDNSType = "AAAA"
OriginDNSTypeSRV OriginDNSType = "SRV"
)
func (r OriginDNSType) IsKnown() bool {
switch r {
case OriginDNSTypeEmpty, OriginDNSTypeA, OriginDNSTypeAAAA, OriginDNSTypeSRV:
return true
}
return false
}
// The name and type of DNS record for the Spectrum application.
type OriginDNSParam struct {
// The name of the DNS record associated with the origin.
Name param.Field[string] `json:"name" format:"hostname"`
// The TTL of our resolution of your DNS record in seconds.
TTL param.Field[int64] `json:"ttl"`
// The type of DNS record associated with the origin. "" is used to specify a
// combination of A/AAAA records.
Type param.Field[OriginDNSType] `json:"type"`
}
func (r OriginDNSParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// The destination port at the origin. Only specified in conjunction with
// origin_dns. May use an integer to specify a single origin port, for example
// `1000`, or a string to specify a range of origin ports, for example
// `"1000-2000"`. Notes: If specifying a port range, the number of ports in the
// range must match the number of ports specified in the "protocol" field.
//
// Union satisfied by [shared.UnionInt] or [shared.UnionString].
type OriginPortUnion interface {
ImplementsSpectrumOriginPortUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*OriginPortUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionInt(0)),
},
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}
// The destination port at the origin. Only specified in conjunction with
// origin_dns. May use an integer to specify a single origin port, for example
// `1000`, or a string to specify a range of origin ports, for example
// `"1000-2000"`. Notes: If specifying a port range, the number of ports in the
// range must match the number of ports specified in the "protocol" field.
//
// Satisfied by [shared.UnionInt], [shared.UnionString].
type OriginPortUnionParam interface {
ImplementsSpectrumOriginPortUnionParam()
}