-
Notifications
You must be signed in to change notification settings - Fork 541
/
trafficanomaly.go
294 lines (253 loc) · 12.1 KB
/
trafficanomaly.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
// 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"
)
// TrafficAnomalyService 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 [NewTrafficAnomalyService] method
// instead.
type TrafficAnomalyService struct {
Options []option.RequestOption
Locations *TrafficAnomalyLocationService
}
// NewTrafficAnomalyService 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 NewTrafficAnomalyService(opts ...option.RequestOption) (r *TrafficAnomalyService) {
r = &TrafficAnomalyService{}
r.Options = opts
r.Locations = NewTrafficAnomalyLocationService(opts...)
return
}
// Internet traffic anomalies are signals that might point to an outage, These
// alerts are automatically detected by Radar and then manually verified by our
// team. This endpoint returns the latest alerts.
func (r *TrafficAnomalyService) Get(ctx context.Context, query TrafficAnomalyGetParams, opts ...option.RequestOption) (res *TrafficAnomalyGetResponse, err error) {
opts = append(r.Options[:], opts...)
var env TrafficAnomalyGetResponseEnvelope
path := "radar/traffic_anomalies"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type TrafficAnomalyGetResponse struct {
TrafficAnomalies []TrafficAnomalyGetResponseTrafficAnomaly `json:"trafficAnomalies,required"`
JSON trafficAnomalyGetResponseJSON `json:"-"`
}
// trafficAnomalyGetResponseJSON contains the JSON metadata for the struct
// [TrafficAnomalyGetResponse]
type trafficAnomalyGetResponseJSON struct {
TrafficAnomalies apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TrafficAnomalyGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r trafficAnomalyGetResponseJSON) RawJSON() string {
return r.raw
}
type TrafficAnomalyGetResponseTrafficAnomaly struct {
StartDate string `json:"startDate,required"`
Status string `json:"status,required"`
Type string `json:"type,required"`
UUID string `json:"uuid,required"`
ASNDetails TrafficAnomalyGetResponseTrafficAnomaliesASNDetails `json:"asnDetails"`
EndDate string `json:"endDate"`
LocationDetails TrafficAnomalyGetResponseTrafficAnomaliesLocationDetails `json:"locationDetails"`
VisibleInDataSources []string `json:"visibleInDataSources"`
JSON trafficAnomalyGetResponseTrafficAnomalyJSON `json:"-"`
}
// trafficAnomalyGetResponseTrafficAnomalyJSON contains the JSON metadata for the
// struct [TrafficAnomalyGetResponseTrafficAnomaly]
type trafficAnomalyGetResponseTrafficAnomalyJSON struct {
StartDate apijson.Field
Status apijson.Field
Type apijson.Field
UUID apijson.Field
ASNDetails apijson.Field
EndDate apijson.Field
LocationDetails apijson.Field
VisibleInDataSources apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TrafficAnomalyGetResponseTrafficAnomaly) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r trafficAnomalyGetResponseTrafficAnomalyJSON) RawJSON() string {
return r.raw
}
type TrafficAnomalyGetResponseTrafficAnomaliesASNDetails struct {
ASN string `json:"asn,required"`
Name string `json:"name,required"`
Locations TrafficAnomalyGetResponseTrafficAnomaliesASNDetailsLocations `json:"locations"`
JSON trafficAnomalyGetResponseTrafficAnomaliesASNDetailsJSON `json:"-"`
}
// trafficAnomalyGetResponseTrafficAnomaliesASNDetailsJSON contains the JSON
// metadata for the struct [TrafficAnomalyGetResponseTrafficAnomaliesASNDetails]
type trafficAnomalyGetResponseTrafficAnomaliesASNDetailsJSON struct {
ASN apijson.Field
Name apijson.Field
Locations apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TrafficAnomalyGetResponseTrafficAnomaliesASNDetails) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r trafficAnomalyGetResponseTrafficAnomaliesASNDetailsJSON) RawJSON() string {
return r.raw
}
type TrafficAnomalyGetResponseTrafficAnomaliesASNDetailsLocations struct {
Code string `json:"code,required"`
Name string `json:"name,required"`
JSON trafficAnomalyGetResponseTrafficAnomaliesASNDetailsLocationsJSON `json:"-"`
}
// trafficAnomalyGetResponseTrafficAnomaliesASNDetailsLocationsJSON contains the
// JSON metadata for the struct
// [TrafficAnomalyGetResponseTrafficAnomaliesASNDetailsLocations]
type trafficAnomalyGetResponseTrafficAnomaliesASNDetailsLocationsJSON struct {
Code apijson.Field
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TrafficAnomalyGetResponseTrafficAnomaliesASNDetailsLocations) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r trafficAnomalyGetResponseTrafficAnomaliesASNDetailsLocationsJSON) RawJSON() string {
return r.raw
}
type TrafficAnomalyGetResponseTrafficAnomaliesLocationDetails struct {
Code string `json:"code,required"`
Name string `json:"name,required"`
JSON trafficAnomalyGetResponseTrafficAnomaliesLocationDetailsJSON `json:"-"`
}
// trafficAnomalyGetResponseTrafficAnomaliesLocationDetailsJSON contains the JSON
// metadata for the struct
// [TrafficAnomalyGetResponseTrafficAnomaliesLocationDetails]
type trafficAnomalyGetResponseTrafficAnomaliesLocationDetailsJSON struct {
Code apijson.Field
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TrafficAnomalyGetResponseTrafficAnomaliesLocationDetails) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r trafficAnomalyGetResponseTrafficAnomaliesLocationDetailsJSON) RawJSON() string {
return r.raw
}
type TrafficAnomalyGetParams struct {
// Single ASN as integer.
ASN param.Field[int64] `query:"asn"`
// End of the date range (inclusive).
DateEnd param.Field[time.Time] `query:"dateEnd" format:"date-time"`
// Shorthand date ranges for the last X days - use when you don't need specific
// start and end dates.
DateRange param.Field[TrafficAnomalyGetParamsDateRange] `query:"dateRange"`
// Start of the date range (inclusive).
DateStart param.Field[time.Time] `query:"dateStart" format:"date-time"`
// Format results are returned in.
Format param.Field[TrafficAnomalyGetParamsFormat] `query:"format"`
// Limit the number of objects in the response.
Limit param.Field[int64] `query:"limit"`
// Location Alpha2 code.
Location param.Field[string] `query:"location"`
// Number of objects to skip before grabbing results.
Offset param.Field[int64] `query:"offset"`
Status param.Field[TrafficAnomalyGetParamsStatus] `query:"status"`
}
// URLQuery serializes [TrafficAnomalyGetParams]'s query parameters as
// `url.Values`.
func (r TrafficAnomalyGetParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// Shorthand date ranges for the last X days - use when you don't need specific
// start and end dates.
type TrafficAnomalyGetParamsDateRange string
const (
TrafficAnomalyGetParamsDateRange1d TrafficAnomalyGetParamsDateRange = "1d"
TrafficAnomalyGetParamsDateRange2d TrafficAnomalyGetParamsDateRange = "2d"
TrafficAnomalyGetParamsDateRange7d TrafficAnomalyGetParamsDateRange = "7d"
TrafficAnomalyGetParamsDateRange14d TrafficAnomalyGetParamsDateRange = "14d"
TrafficAnomalyGetParamsDateRange28d TrafficAnomalyGetParamsDateRange = "28d"
TrafficAnomalyGetParamsDateRange12w TrafficAnomalyGetParamsDateRange = "12w"
TrafficAnomalyGetParamsDateRange24w TrafficAnomalyGetParamsDateRange = "24w"
TrafficAnomalyGetParamsDateRange52w TrafficAnomalyGetParamsDateRange = "52w"
TrafficAnomalyGetParamsDateRange1dControl TrafficAnomalyGetParamsDateRange = "1dControl"
TrafficAnomalyGetParamsDateRange2dControl TrafficAnomalyGetParamsDateRange = "2dControl"
TrafficAnomalyGetParamsDateRange7dControl TrafficAnomalyGetParamsDateRange = "7dControl"
TrafficAnomalyGetParamsDateRange14dControl TrafficAnomalyGetParamsDateRange = "14dControl"
TrafficAnomalyGetParamsDateRange28dControl TrafficAnomalyGetParamsDateRange = "28dControl"
TrafficAnomalyGetParamsDateRange12wControl TrafficAnomalyGetParamsDateRange = "12wControl"
TrafficAnomalyGetParamsDateRange24wControl TrafficAnomalyGetParamsDateRange = "24wControl"
)
func (r TrafficAnomalyGetParamsDateRange) IsKnown() bool {
switch r {
case TrafficAnomalyGetParamsDateRange1d, TrafficAnomalyGetParamsDateRange2d, TrafficAnomalyGetParamsDateRange7d, TrafficAnomalyGetParamsDateRange14d, TrafficAnomalyGetParamsDateRange28d, TrafficAnomalyGetParamsDateRange12w, TrafficAnomalyGetParamsDateRange24w, TrafficAnomalyGetParamsDateRange52w, TrafficAnomalyGetParamsDateRange1dControl, TrafficAnomalyGetParamsDateRange2dControl, TrafficAnomalyGetParamsDateRange7dControl, TrafficAnomalyGetParamsDateRange14dControl, TrafficAnomalyGetParamsDateRange28dControl, TrafficAnomalyGetParamsDateRange12wControl, TrafficAnomalyGetParamsDateRange24wControl:
return true
}
return false
}
// Format results are returned in.
type TrafficAnomalyGetParamsFormat string
const (
TrafficAnomalyGetParamsFormatJson TrafficAnomalyGetParamsFormat = "JSON"
TrafficAnomalyGetParamsFormatCsv TrafficAnomalyGetParamsFormat = "CSV"
)
func (r TrafficAnomalyGetParamsFormat) IsKnown() bool {
switch r {
case TrafficAnomalyGetParamsFormatJson, TrafficAnomalyGetParamsFormatCsv:
return true
}
return false
}
type TrafficAnomalyGetParamsStatus string
const (
TrafficAnomalyGetParamsStatusVerified TrafficAnomalyGetParamsStatus = "VERIFIED"
TrafficAnomalyGetParamsStatusUnverified TrafficAnomalyGetParamsStatus = "UNVERIFIED"
)
func (r TrafficAnomalyGetParamsStatus) IsKnown() bool {
switch r {
case TrafficAnomalyGetParamsStatusVerified, TrafficAnomalyGetParamsStatusUnverified:
return true
}
return false
}
type TrafficAnomalyGetResponseEnvelope struct {
Result TrafficAnomalyGetResponse `json:"result,required"`
Success bool `json:"success,required"`
JSON trafficAnomalyGetResponseEnvelopeJSON `json:"-"`
}
// trafficAnomalyGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [TrafficAnomalyGetResponseEnvelope]
type trafficAnomalyGetResponseEnvelopeJSON struct {
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *TrafficAnomalyGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r trafficAnomalyGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}