/
prefixbgpprefix.go
302 lines (261 loc) · 10.5 KB
/
prefixbgpprefix.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package addressing
import (
"context"
"fmt"
"net/http"
"time"
"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"
)
// PrefixBGPPrefixService 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 [NewPrefixBGPPrefixService] method
// instead.
type PrefixBGPPrefixService struct {
Options []option.RequestOption
}
// NewPrefixBGPPrefixService 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 NewPrefixBGPPrefixService(opts ...option.RequestOption) (r *PrefixBGPPrefixService) {
r = &PrefixBGPPrefixService{}
r.Options = opts
return
}
// List all BGP Prefixes within the specified IP Prefix. BGP Prefixes are used to
// control which specific subnets are advertised to the Internet. It is possible to
// advertise subnets more specific than an IP Prefix by creating more specific BGP
// Prefixes.
func (r *PrefixBGPPrefixService) List(ctx context.Context, prefixID string, query PrefixBGPPrefixListParams, opts ...option.RequestOption) (res *pagination.SinglePage[BGPPrefix], 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/bgp/prefixes", 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 all BGP Prefixes within the specified IP Prefix. BGP Prefixes are used to
// control which specific subnets are advertised to the Internet. It is possible to
// advertise subnets more specific than an IP Prefix by creating more specific BGP
// Prefixes.
func (r *PrefixBGPPrefixService) ListAutoPaging(ctx context.Context, prefixID string, query PrefixBGPPrefixListParams, opts ...option.RequestOption) *pagination.SinglePageAutoPager[BGPPrefix] {
return pagination.NewSinglePageAutoPager(r.List(ctx, prefixID, query, opts...))
}
// Update the properties of a BGP Prefix, such as the on demand advertisement
// status (advertised or withdrawn).
func (r *PrefixBGPPrefixService) Edit(ctx context.Context, prefixID string, bgpPrefixID string, params PrefixBGPPrefixEditParams, opts ...option.RequestOption) (res *BGPPrefix, err error) {
opts = append(r.Options[:], opts...)
var env PrefixBGPPrefixEditResponseEnvelope
path := fmt.Sprintf("accounts/%s/addressing/prefixes/%s/bgp/prefixes/%s", params.AccountID, prefixID, bgpPrefixID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Retrieve a single BGP Prefix according to its identifier
func (r *PrefixBGPPrefixService) Get(ctx context.Context, prefixID string, bgpPrefixID string, query PrefixBGPPrefixGetParams, opts ...option.RequestOption) (res *BGPPrefix, err error) {
opts = append(r.Options[:], opts...)
var env PrefixBGPPrefixGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/addressing/prefixes/%s/bgp/prefixes/%s", query.AccountID, prefixID, bgpPrefixID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type BGPPrefix struct {
// Identifier
ID string `json:"id"`
// Autonomous System Number (ASN) the prefix will be advertised under.
ASN int64 `json:"asn,nullable"`
BGPSignalOpts BGPPrefixBGPSignalOpts `json:"bgp_signal_opts"`
// IP Prefix in Classless Inter-Domain Routing format.
CIDR string `json:"cidr"`
CreatedAt time.Time `json:"created_at" format:"date-time"`
ModifiedAt time.Time `json:"modified_at" format:"date-time"`
OnDemand BGPPrefixOnDemand `json:"on_demand"`
JSON bgpPrefixJSON `json:"-"`
}
// bgpPrefixJSON contains the JSON metadata for the struct [BGPPrefix]
type bgpPrefixJSON struct {
ID apijson.Field
ASN apijson.Field
BGPSignalOpts apijson.Field
CIDR apijson.Field
CreatedAt apijson.Field
ModifiedAt apijson.Field
OnDemand apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BGPPrefix) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r bgpPrefixJSON) RawJSON() string {
return r.raw
}
type BGPPrefixBGPSignalOpts struct {
// Whether control of advertisement of the prefix to the Internet is enabled to be
// performed via BGP signal
Enabled bool `json:"enabled"`
// Last time BGP signaling control was toggled. This field is null if BGP signaling
// has never been enabled.
ModifiedAt time.Time `json:"modified_at,nullable" format:"date-time"`
JSON bgpPrefixBGPSignalOptsJSON `json:"-"`
}
// bgpPrefixBGPSignalOptsJSON contains the JSON metadata for the struct
// [BGPPrefixBGPSignalOpts]
type bgpPrefixBGPSignalOptsJSON struct {
Enabled apijson.Field
ModifiedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BGPPrefixBGPSignalOpts) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r bgpPrefixBGPSignalOptsJSON) RawJSON() string {
return r.raw
}
type BGPPrefixOnDemand struct {
// Prefix advertisement status to the Internet. This field is only not 'null' if on
// demand is enabled.
Advertised bool `json:"advertised,nullable"`
// Last time the advertisement status was changed. This field is only not 'null' if
// on demand is enabled.
AdvertisedModifiedAt time.Time `json:"advertised_modified_at,nullable" format:"date-time"`
// Whether advertisement of the prefix to the Internet may be dynamically enabled
// or disabled.
OnDemandEnabled bool `json:"on_demand_enabled"`
// Whether advertisement status of the prefix is locked, meaning it cannot be
// changed.
OnDemandLocked bool `json:"on_demand_locked"`
JSON bgpPrefixOnDemandJSON `json:"-"`
}
// bgpPrefixOnDemandJSON contains the JSON metadata for the struct
// [BGPPrefixOnDemand]
type bgpPrefixOnDemandJSON struct {
Advertised apijson.Field
AdvertisedModifiedAt apijson.Field
OnDemandEnabled apijson.Field
OnDemandLocked apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BGPPrefixOnDemand) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r bgpPrefixOnDemandJSON) RawJSON() string {
return r.raw
}
type PrefixBGPPrefixListParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type PrefixBGPPrefixEditParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
OnDemand param.Field[PrefixBGPPrefixEditParamsOnDemand] `json:"on_demand"`
}
func (r PrefixBGPPrefixEditParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type PrefixBGPPrefixEditParamsOnDemand struct {
Advertised param.Field[bool] `json:"advertised"`
}
func (r PrefixBGPPrefixEditParamsOnDemand) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type PrefixBGPPrefixEditResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success PrefixBGPPrefixEditResponseEnvelopeSuccess `json:"success,required"`
Result BGPPrefix `json:"result"`
JSON prefixBGPPrefixEditResponseEnvelopeJSON `json:"-"`
}
// prefixBGPPrefixEditResponseEnvelopeJSON contains the JSON metadata for the
// struct [PrefixBGPPrefixEditResponseEnvelope]
type prefixBGPPrefixEditResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PrefixBGPPrefixEditResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r prefixBGPPrefixEditResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type PrefixBGPPrefixEditResponseEnvelopeSuccess bool
const (
PrefixBGPPrefixEditResponseEnvelopeSuccessTrue PrefixBGPPrefixEditResponseEnvelopeSuccess = true
)
func (r PrefixBGPPrefixEditResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case PrefixBGPPrefixEditResponseEnvelopeSuccessTrue:
return true
}
return false
}
type PrefixBGPPrefixGetParams struct {
// Identifier
AccountID param.Field[string] `path:"account_id,required"`
}
type PrefixBGPPrefixGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
// Whether the API call was successful
Success PrefixBGPPrefixGetResponseEnvelopeSuccess `json:"success,required"`
Result BGPPrefix `json:"result"`
JSON prefixBGPPrefixGetResponseEnvelopeJSON `json:"-"`
}
// prefixBGPPrefixGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [PrefixBGPPrefixGetResponseEnvelope]
type prefixBGPPrefixGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Success apijson.Field
Result apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PrefixBGPPrefixGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r prefixBGPPrefixGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type PrefixBGPPrefixGetResponseEnvelopeSuccess bool
const (
PrefixBGPPrefixGetResponseEnvelopeSuccessTrue PrefixBGPPrefixGetResponseEnvelopeSuccess = true
)
func (r PrefixBGPPrefixGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case PrefixBGPPrefixGetResponseEnvelopeSuccessTrue:
return true
}
return false
}