-
Notifications
You must be signed in to change notification settings - Fork 541
/
bgp.go
347 lines (299 loc) · 13.3 KB
/
bgp.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package radar
import (
"context"
"net/http"
"net/url"
"time"
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/apiquery"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/option"
)
// BGPService 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 [NewBGPService] method instead.
type BGPService struct {
Options []option.RequestOption
Leaks *BGPLeakService
Top *BGPTopService
Hijacks *BGPHijackService
Routes *BGPRouteService
}
// NewBGPService 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 NewBGPService(opts ...option.RequestOption) (r *BGPService) {
r = &BGPService{}
r.Options = opts
r.Leaks = NewBGPLeakService(opts...)
r.Top = NewBGPTopService(opts...)
r.Hijacks = NewBGPHijackService(opts...)
r.Routes = NewBGPRouteService(opts...)
return
}
// Gets BGP updates change over time. Raw values are returned. When requesting
// updates of an autonomous system (AS), only BGP updates of type announcement are
// returned.
func (r *BGPService) Timeseries(ctx context.Context, query BGPTimeseriesParams, opts ...option.RequestOption) (res *BGPTimeseriesResponse, err error) {
opts = append(r.Options[:], opts...)
var env BGPTimeseriesResponseEnvelope
path := "radar/bgp/timeseries"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type BGPTimeseriesResponse struct {
Meta BGPTimeseriesResponseMeta `json:"meta,required"`
Serie0 BGPTimeseriesResponseSerie0 `json:"serie_0,required"`
JSON bgpTimeseriesResponseJSON `json:"-"`
}
// bgpTimeseriesResponseJSON contains the JSON metadata for the struct
// [BGPTimeseriesResponse]
type bgpTimeseriesResponseJSON struct {
Meta apijson.Field
Serie0 apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BGPTimeseriesResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r bgpTimeseriesResponseJSON) RawJSON() string {
return r.raw
}
type BGPTimeseriesResponseMeta struct {
AggInterval string `json:"aggInterval,required"`
DateRange []BGPTimeseriesResponseMetaDateRange `json:"dateRange,required"`
LastUpdated time.Time `json:"lastUpdated,required" format:"date-time"`
ConfidenceInfo BGPTimeseriesResponseMetaConfidenceInfo `json:"confidenceInfo"`
JSON bgpTimeseriesResponseMetaJSON `json:"-"`
}
// bgpTimeseriesResponseMetaJSON contains the JSON metadata for the struct
// [BGPTimeseriesResponseMeta]
type bgpTimeseriesResponseMetaJSON struct {
AggInterval apijson.Field
DateRange apijson.Field
LastUpdated apijson.Field
ConfidenceInfo apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BGPTimeseriesResponseMeta) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r bgpTimeseriesResponseMetaJSON) RawJSON() string {
return r.raw
}
type BGPTimeseriesResponseMetaDateRange struct {
// Adjusted end of date range.
EndTime time.Time `json:"endTime,required" format:"date-time"`
// Adjusted start of date range.
StartTime time.Time `json:"startTime,required" format:"date-time"`
JSON bgpTimeseriesResponseMetaDateRangeJSON `json:"-"`
}
// bgpTimeseriesResponseMetaDateRangeJSON contains the JSON metadata for the struct
// [BGPTimeseriesResponseMetaDateRange]
type bgpTimeseriesResponseMetaDateRangeJSON struct {
EndTime apijson.Field
StartTime apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BGPTimeseriesResponseMetaDateRange) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r bgpTimeseriesResponseMetaDateRangeJSON) RawJSON() string {
return r.raw
}
type BGPTimeseriesResponseMetaConfidenceInfo struct {
Annotations []BGPTimeseriesResponseMetaConfidenceInfoAnnotation `json:"annotations"`
Level int64 `json:"level"`
JSON bgpTimeseriesResponseMetaConfidenceInfoJSON `json:"-"`
}
// bgpTimeseriesResponseMetaConfidenceInfoJSON contains the JSON metadata for the
// struct [BGPTimeseriesResponseMetaConfidenceInfo]
type bgpTimeseriesResponseMetaConfidenceInfoJSON struct {
Annotations apijson.Field
Level apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BGPTimeseriesResponseMetaConfidenceInfo) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r bgpTimeseriesResponseMetaConfidenceInfoJSON) RawJSON() string {
return r.raw
}
type BGPTimeseriesResponseMetaConfidenceInfoAnnotation struct {
DataSource string `json:"dataSource,required"`
Description string `json:"description,required"`
EventType string `json:"eventType,required"`
IsInstantaneous interface{} `json:"isInstantaneous,required"`
EndTime time.Time `json:"endTime" format:"date-time"`
LinkedURL string `json:"linkedUrl"`
StartTime time.Time `json:"startTime" format:"date-time"`
JSON bgpTimeseriesResponseMetaConfidenceInfoAnnotationJSON `json:"-"`
}
// bgpTimeseriesResponseMetaConfidenceInfoAnnotationJSON contains the JSON metadata
// for the struct [BGPTimeseriesResponseMetaConfidenceInfoAnnotation]
type bgpTimeseriesResponseMetaConfidenceInfoAnnotationJSON struct {
DataSource apijson.Field
Description apijson.Field
EventType apijson.Field
IsInstantaneous apijson.Field
EndTime apijson.Field
LinkedURL apijson.Field
StartTime apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BGPTimeseriesResponseMetaConfidenceInfoAnnotation) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r bgpTimeseriesResponseMetaConfidenceInfoAnnotationJSON) RawJSON() string {
return r.raw
}
type BGPTimeseriesResponseSerie0 struct {
Timestamps []time.Time `json:"timestamps,required" format:"date-time"`
Values []string `json:"values,required"`
JSON bgpTimeseriesResponseSerie0JSON `json:"-"`
}
// bgpTimeseriesResponseSerie0JSON contains the JSON metadata for the struct
// [BGPTimeseriesResponseSerie0]
type bgpTimeseriesResponseSerie0JSON struct {
Timestamps apijson.Field
Values apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BGPTimeseriesResponseSerie0) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r bgpTimeseriesResponseSerie0JSON) RawJSON() string {
return r.raw
}
type BGPTimeseriesParams struct {
// Aggregation interval results should be returned in (for example, in 15 minutes
// or 1 hour intervals). Refer to
// [Aggregation intervals](https://developers.cloudflare.com/radar/concepts/aggregation-intervals/).
AggInterval param.Field[BGPTimeseriesParamsAggInterval] `query:"aggInterval"`
// Array of comma separated list of ASNs, start with `-` to exclude from results.
// For example, `-174, 3356` excludes results from AS174, but includes results from
// AS3356.
ASN param.Field[[]string] `query:"asn"`
// End of the date range (inclusive).
DateEnd param.Field[[]time.Time] `query:"dateEnd" format:"date-time"`
// For example, use `7d` and `7dControl` to compare this week with the previous
// week. Use this parameter or set specific start and end dates (`dateStart` and
// `dateEnd` parameters).
DateRange param.Field[[]BGPTimeseriesParamsDateRange] `query:"dateRange"`
// Array of datetimes to filter the start of a series.
DateStart param.Field[[]time.Time] `query:"dateStart" format:"date-time"`
// Format results are returned in.
Format param.Field[BGPTimeseriesParamsFormat] `query:"format"`
// Array of names that will be used to name the series in responses.
Name param.Field[[]string] `query:"name"`
// Array of BGP network prefixes.
Prefix param.Field[[]string] `query:"prefix"`
// Array of BGP update types.
UpdateType param.Field[[]BGPTimeseriesParamsUpdateType] `query:"updateType"`
}
// URLQuery serializes [BGPTimeseriesParams]'s query parameters as `url.Values`.
func (r BGPTimeseriesParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Aggregation interval results should be returned in (for example, in 15 minutes
// or 1 hour intervals). Refer to
// [Aggregation intervals](https://developers.cloudflare.com/radar/concepts/aggregation-intervals/).
type BGPTimeseriesParamsAggInterval string
const (
BGPTimeseriesParamsAggInterval15m BGPTimeseriesParamsAggInterval = "15m"
BGPTimeseriesParamsAggInterval1h BGPTimeseriesParamsAggInterval = "1h"
BGPTimeseriesParamsAggInterval1d BGPTimeseriesParamsAggInterval = "1d"
BGPTimeseriesParamsAggInterval1w BGPTimeseriesParamsAggInterval = "1w"
)
func (r BGPTimeseriesParamsAggInterval) IsKnown() bool {
switch r {
case BGPTimeseriesParamsAggInterval15m, BGPTimeseriesParamsAggInterval1h, BGPTimeseriesParamsAggInterval1d, BGPTimeseriesParamsAggInterval1w:
return true
}
return false
}
type BGPTimeseriesParamsDateRange string
const (
BGPTimeseriesParamsDateRange1d BGPTimeseriesParamsDateRange = "1d"
BGPTimeseriesParamsDateRange2d BGPTimeseriesParamsDateRange = "2d"
BGPTimeseriesParamsDateRange7d BGPTimeseriesParamsDateRange = "7d"
BGPTimeseriesParamsDateRange14d BGPTimeseriesParamsDateRange = "14d"
BGPTimeseriesParamsDateRange28d BGPTimeseriesParamsDateRange = "28d"
BGPTimeseriesParamsDateRange12w BGPTimeseriesParamsDateRange = "12w"
BGPTimeseriesParamsDateRange24w BGPTimeseriesParamsDateRange = "24w"
BGPTimeseriesParamsDateRange52w BGPTimeseriesParamsDateRange = "52w"
BGPTimeseriesParamsDateRange1dControl BGPTimeseriesParamsDateRange = "1dControl"
BGPTimeseriesParamsDateRange2dControl BGPTimeseriesParamsDateRange = "2dControl"
BGPTimeseriesParamsDateRange7dControl BGPTimeseriesParamsDateRange = "7dControl"
BGPTimeseriesParamsDateRange14dControl BGPTimeseriesParamsDateRange = "14dControl"
BGPTimeseriesParamsDateRange28dControl BGPTimeseriesParamsDateRange = "28dControl"
BGPTimeseriesParamsDateRange12wControl BGPTimeseriesParamsDateRange = "12wControl"
BGPTimeseriesParamsDateRange24wControl BGPTimeseriesParamsDateRange = "24wControl"
)
func (r BGPTimeseriesParamsDateRange) IsKnown() bool {
switch r {
case BGPTimeseriesParamsDateRange1d, BGPTimeseriesParamsDateRange2d, BGPTimeseriesParamsDateRange7d, BGPTimeseriesParamsDateRange14d, BGPTimeseriesParamsDateRange28d, BGPTimeseriesParamsDateRange12w, BGPTimeseriesParamsDateRange24w, BGPTimeseriesParamsDateRange52w, BGPTimeseriesParamsDateRange1dControl, BGPTimeseriesParamsDateRange2dControl, BGPTimeseriesParamsDateRange7dControl, BGPTimeseriesParamsDateRange14dControl, BGPTimeseriesParamsDateRange28dControl, BGPTimeseriesParamsDateRange12wControl, BGPTimeseriesParamsDateRange24wControl:
return true
}
return false
}
// Format results are returned in.
type BGPTimeseriesParamsFormat string
const (
BGPTimeseriesParamsFormatJson BGPTimeseriesParamsFormat = "JSON"
BGPTimeseriesParamsFormatCsv BGPTimeseriesParamsFormat = "CSV"
)
func (r BGPTimeseriesParamsFormat) IsKnown() bool {
switch r {
case BGPTimeseriesParamsFormatJson, BGPTimeseriesParamsFormatCsv:
return true
}
return false
}
type BGPTimeseriesParamsUpdateType string
const (
BGPTimeseriesParamsUpdateTypeAnnouncement BGPTimeseriesParamsUpdateType = "ANNOUNCEMENT"
BGPTimeseriesParamsUpdateTypeWithdrawal BGPTimeseriesParamsUpdateType = "WITHDRAWAL"
)
func (r BGPTimeseriesParamsUpdateType) IsKnown() bool {
switch r {
case BGPTimeseriesParamsUpdateTypeAnnouncement, BGPTimeseriesParamsUpdateTypeWithdrawal:
return true
}
return false
}
type BGPTimeseriesResponseEnvelope struct {
Result BGPTimeseriesResponse `json:"result,required"`
Success bool `json:"success,required"`
JSON bgpTimeseriesResponseEnvelopeJSON `json:"-"`
}
// bgpTimeseriesResponseEnvelopeJSON contains the JSON metadata for the struct
// [BGPTimeseriesResponseEnvelope]
type bgpTimeseriesResponseEnvelopeJSON struct {
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BGPTimeseriesResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r bgpTimeseriesResponseEnvelopeJSON) RawJSON() string {
return r.raw
}