/
prefixbgpbinding.go
363 lines (310 loc) · 12.9 KB
/
prefixbgpbinding.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package addressing
import (
"context"
"fmt"
"net/http"
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"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"
)
// PrefixBGPBindingService 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 [NewPrefixBGPBindingService] method
// instead.
type PrefixBGPBindingService struct {
Options []option.RequestOption
}
// NewPrefixBGPBindingService 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 NewPrefixBGPBindingService(opts ...option.RequestOption) (r *PrefixBGPBindingService) {
r = &PrefixBGPBindingService{}
r.Options = opts
return
}
// Creates a new Service Binding, routing traffic to IPs within the given CIDR to a
// service running on Cloudflare's network. **Note:** This API may only be used on
// prefixes currently configured with a Magic Transit service binding, and only
// allows creating service bindings for the Cloudflare CDN or Cloudflare Spectrum.
func (r *PrefixBGPBindingService) New(ctx context.Context, prefixID string, params PrefixBGPBindingNewParams, opts ...option.RequestOption) (res *ServiceBinding, err error) {
opts = append(r.Options[:], opts...)
var env PrefixBGPBindingNewResponseEnvelope
path := fmt.Sprintf("accounts/%s/addressing/prefixes/%s/bindings", params.AccountID, prefixID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// List the Cloudflare services this prefix is currently bound to. Traffic sent to
// an address within an IP prefix will be routed to the Cloudflare service of the
// most-specific Service Binding matching the address. **Example:** binding
// `192.0.2.0/24` to Cloudflare Magic Transit and `192.0.2.1/32` to the Cloudflare
// CDN would route traffic for `192.0.2.1` to the CDN, and traffic for all other
// IPs in the prefix to Cloudflare Magic Transit.
func (r *PrefixBGPBindingService) List(ctx context.Context, prefixID string, query PrefixBGPBindingListParams, opts ...option.RequestOption) (res *pagination.SinglePage[ServiceBinding], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := fmt.Sprintf("accounts/%s/addressing/prefixes/%s/bindings", query.AccountID, prefixID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List the Cloudflare services this prefix is currently bound to. Traffic sent to
// an address within an IP prefix will be routed to the Cloudflare service of the
// most-specific Service Binding matching the address. **Example:** binding
// `192.0.2.0/24` to Cloudflare Magic Transit and `192.0.2.1/32` to the Cloudflare
// CDN would route traffic for `192.0.2.1` to the CDN, and traffic for all other
// IPs in the prefix to Cloudflare Magic Transit.
func (r *PrefixBGPBindingService) ListAutoPaging(ctx context.Context, prefixID string, query PrefixBGPBindingListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[ServiceBinding] {
return pagination.NewSinglePageAutoPager(r.List(ctx, prefixID, query, opts...))
}
// Delete a Service Binding
func (r *PrefixBGPBindingService) Delete(ctx context.Context, prefixID string, bindingID string, body PrefixBGPBindingDeleteParams, opts ...option.RequestOption) (res *PrefixBGPBindingDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
path := fmt.Sprintf("accounts/%s/addressing/prefixes/%s/bindings/%s", body.AccountID, prefixID, bindingID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
// Fetch a single Service Binding
func (r *PrefixBGPBindingService) Get(ctx context.Context, prefixID string, bindingID string, query PrefixBGPBindingGetParams, opts ...option.RequestOption) (res *ServiceBinding, err error) {
opts = append(r.Options[:], opts...)
var env PrefixBGPBindingGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/addressing/prefixes/%s/bindings/%s", query.AccountID, prefixID, bindingID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type ServiceBinding struct {
// Identifier
ID string `json:"id"`
// IP Prefix in Classless Inter-Domain Routing format.
CIDR string `json:"cidr"`
// Status of a Service Binding's deployment to the Cloudflare network
Provisioning ServiceBindingProvisioning `json:"provisioning"`
// Identifier
ServiceID string `json:"service_id"`
// Name of a service running on the Cloudflare network
ServiceName string `json:"service_name"`
JSON serviceBindingJSON `json:"-"`
}
// serviceBindingJSON contains the JSON metadata for the struct [ServiceBinding]
type serviceBindingJSON struct {
ID apijson.Field
CIDR apijson.Field
Provisioning apijson.Field
ServiceID apijson.Field
ServiceName apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ServiceBinding) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r serviceBindingJSON) RawJSON() string {
return r.raw
}
func (r ServiceBinding) implementsWorkersBinding() {}
// Status of a Service Binding's deployment to the Cloudflare network
type ServiceBindingProvisioning struct {
// When a binding has been deployed to a majority of Cloudflare datacenters, the
// binding will become active and can be used with its associated service.
State ServiceBindingProvisioningState `json:"state"`
JSON serviceBindingProvisioningJSON `json:"-"`
}
// serviceBindingProvisioningJSON contains the JSON metadata for the struct
// [ServiceBindingProvisioning]
type serviceBindingProvisioningJSON struct {
State apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ServiceBindingProvisioning) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r serviceBindingProvisioningJSON) RawJSON() string {
return r.raw
}
// When a binding has been deployed to a majority of Cloudflare datacenters, the
// binding will become active and can be used with its associated service.
type ServiceBindingProvisioningState string
const (
ServiceBindingProvisioningStateProvisioning ServiceBindingProvisioningState = "provisioning"
ServiceBindingProvisioningStateActive ServiceBindingProvisioningState = "active"
)
func (r ServiceBindingProvisioningState) IsKnown() bool {
switch r {
case ServiceBindingProvisioningStateProvisioning, ServiceBindingProvisioningStateActive:
return true
}
return false
}
type ServiceBindingParam struct {
// IP Prefix in Classless Inter-Domain Routing format.
CIDR param.Field[string] `json:"cidr"`
// Status of a Service Binding's deployment to the Cloudflare network
Provisioning param.Field[ServiceBindingProvisioningParam] `json:"provisioning"`
// Identifier
ServiceID param.Field[string] `json:"service_id"`
// Name of a service running on the Cloudflare network
ServiceName param.Field[string] `json:"service_name"`
}
func (r ServiceBindingParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r ServiceBindingParam) implementsWorkersBindingUnionParam() {}
// Status of a Service Binding's deployment to the Cloudflare network
type ServiceBindingProvisioningParam struct {
// When a binding has been deployed to a majority of Cloudflare datacenters, the
// binding will become active and can be used with its associated service.
State param.Field[ServiceBindingProvisioningState] `json:"state"`
}
func (r ServiceBindingProvisioningParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type PrefixBGPBindingDeleteResponse struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success PrefixBGPBindingDeleteResponseSuccess `json:"success,required"`
JSON prefixBGPBindingDeleteResponseJSON `json:"-"`
}
// prefixBGPBindingDeleteResponseJSON contains the JSON metadata for the struct
// [PrefixBGPBindingDeleteResponse]
type prefixBGPBindingDeleteResponseJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PrefixBGPBindingDeleteResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r prefixBGPBindingDeleteResponseJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type PrefixBGPBindingDeleteResponseSuccess bool
const (
PrefixBGPBindingDeleteResponseSuccessTrue PrefixBGPBindingDeleteResponseSuccess = true
)
func (r PrefixBGPBindingDeleteResponseSuccess) IsKnown() bool {
switch r {
case PrefixBGPBindingDeleteResponseSuccessTrue:
return true
}
return false
}
type PrefixBGPBindingNewParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
// IP Prefix in Classless Inter-Domain Routing format.
CIDR param.Field[string] `json:"cidr"`
// Identifier
ServiceID param.Field[string] `json:"service_id"`
}
func (r PrefixBGPBindingNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type PrefixBGPBindingNewResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success PrefixBGPBindingNewResponseEnvelopeSuccess `json:"success,required"`
Result ServiceBinding `json:"result"`
JSON prefixBGPBindingNewResponseEnvelopeJSON `json:"-"`
}
// prefixBGPBindingNewResponseEnvelopeJSON contains the JSON metadata for the
// struct [PrefixBGPBindingNewResponseEnvelope]
type prefixBGPBindingNewResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PrefixBGPBindingNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r prefixBGPBindingNewResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type PrefixBGPBindingNewResponseEnvelopeSuccess bool
const (
PrefixBGPBindingNewResponseEnvelopeSuccessTrue PrefixBGPBindingNewResponseEnvelopeSuccess = true
)
func (r PrefixBGPBindingNewResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case PrefixBGPBindingNewResponseEnvelopeSuccessTrue:
return true
}
return false
}
type PrefixBGPBindingListParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type PrefixBGPBindingDeleteParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type PrefixBGPBindingGetParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type PrefixBGPBindingGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success PrefixBGPBindingGetResponseEnvelopeSuccess `json:"success,required"`
Result ServiceBinding `json:"result"`
JSON prefixBGPBindingGetResponseEnvelopeJSON `json:"-"`
}
// prefixBGPBindingGetResponseEnvelopeJSON contains the JSON metadata for the
// struct [PrefixBGPBindingGetResponseEnvelope]
type prefixBGPBindingGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PrefixBGPBindingGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r prefixBGPBindingGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type PrefixBGPBindingGetResponseEnvelopeSuccess bool
const (
PrefixBGPBindingGetResponseEnvelopeSuccessTrue PrefixBGPBindingGetResponseEnvelopeSuccess = true
)
func (r PrefixBGPBindingGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case PrefixBGPBindingGetResponseEnvelopeSuccessTrue:
return true
}
return false
}