/
attacklayer3.go
320 lines (276 loc) · 13.5 KB
/
attacklayer3.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
// 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"
)
// AttackLayer3Service 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 [NewAttackLayer3Service] method
// instead.
type AttackLayer3Service struct {
Options []option.RequestOption
Summary *AttackLayer3SummaryService
TimeseriesGroups *AttackLayer3TimeseriesGroupService
Top *AttackLayer3TopService
}
// NewAttackLayer3Service 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 NewAttackLayer3Service(opts ...option.RequestOption) (r *AttackLayer3Service) {
r = &AttackLayer3Service{}
r.Options = opts
r.Summary = NewAttackLayer3SummaryService(opts...)
r.TimeseriesGroups = NewAttackLayer3TimeseriesGroupService(opts...)
r.Top = NewAttackLayer3TopService(opts...)
return
}
// Get attacks change over time by bytes.
func (r *AttackLayer3Service) Timeseries(ctx context.Context, query AttackLayer3TimeseriesParams, opts ...option.RequestOption) (res *AttackLayer3TimeseriesResponse, err error) {
opts = append(r.Options[:], opts...)
var env AttackLayer3TimeseriesResponseEnvelope
path := "radar/attacks/layer3/timeseries"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type AttackLayer3TimeseriesResponse struct {
Meta interface{} `json:"meta,required"`
Serie0 AttackLayer3TimeseriesResponseSerie0 `json:"serie_0,required"`
JSON attackLayer3TimeseriesResponseJSON `json:"-"`
}
// attackLayer3TimeseriesResponseJSON contains the JSON metadata for the struct
// [AttackLayer3TimeseriesResponse]
type attackLayer3TimeseriesResponseJSON struct {
Meta apijson.Field
Serie0 apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AttackLayer3TimeseriesResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r attackLayer3TimeseriesResponseJSON) RawJSON() string {
return r.raw
}
type AttackLayer3TimeseriesResponseSerie0 struct {
Timestamps []time.Time `json:"timestamps,required" format:"date-time"`
Values []string `json:"values,required"`
JSON attackLayer3TimeseriesResponseSerie0JSON `json:"-"`
}
// attackLayer3TimeseriesResponseSerie0JSON contains the JSON metadata for the
// struct [AttackLayer3TimeseriesResponseSerie0]
type attackLayer3TimeseriesResponseSerie0JSON struct {
Timestamps apijson.Field
Values apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AttackLayer3TimeseriesResponseSerie0) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r attackLayer3TimeseriesResponseSerie0JSON) RawJSON() string {
return r.raw
}
type AttackLayer3TimeseriesParams 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[AttackLayer3TimeseriesParamsAggInterval] `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"`
// Array of comma separated list of continents (alpha-2 continent codes). Start
// with `-` to exclude from results. For example, `-EU,NA` excludes results from
// Europe, but includes results from North America.
Continent param.Field[[]string] `query:"continent"`
// 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[[]AttackLayer3TimeseriesParamsDateRange] `query:"dateRange"`
// Array of datetimes to filter the start of a series.
DateStart param.Field[[]time.Time] `query:"dateStart" format:"date-time"`
// Together with the `location` parameter, will apply the filter to origin or
// target location.
Direction param.Field[AttackLayer3TimeseriesParamsDirection] `query:"direction"`
// Format results are returned in.
Format param.Field[AttackLayer3TimeseriesParamsFormat] `query:"format"`
// Filter for ip version.
IPVersion param.Field[[]AttackLayer3TimeseriesParamsIPVersion] `query:"ipVersion"`
// Array of comma separated list of locations (alpha-2 country codes). Start with
// `-` to exclude from results. For example, `-US,PT` excludes results from the US,
// but includes results from PT.
Location param.Field[[]string] `query:"location"`
// Measurement units, eg. bytes.
Metric param.Field[AttackLayer3TimeseriesParamsMetric] `query:"metric"`
// Array of names that will be used to name the series in responses.
Name param.Field[[]string] `query:"name"`
// Normalization method applied. Refer to
// [Normalization methods](https://developers.cloudflare.com/radar/concepts/normalization/).
Normalization param.Field[AttackLayer3TimeseriesParamsNormalization] `query:"normalization"`
// Array of L3/4 attack types.
Protocol param.Field[[]AttackLayer3TimeseriesParamsProtocol] `query:"protocol"`
}
// URLQuery serializes [AttackLayer3TimeseriesParams]'s query parameters as
// `url.Values`.
func (r AttackLayer3TimeseriesParams) 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 AttackLayer3TimeseriesParamsAggInterval string
const (
AttackLayer3TimeseriesParamsAggInterval15m AttackLayer3TimeseriesParamsAggInterval = "15m"
AttackLayer3TimeseriesParamsAggInterval1h AttackLayer3TimeseriesParamsAggInterval = "1h"
AttackLayer3TimeseriesParamsAggInterval1d AttackLayer3TimeseriesParamsAggInterval = "1d"
AttackLayer3TimeseriesParamsAggInterval1w AttackLayer3TimeseriesParamsAggInterval = "1w"
)
func (r AttackLayer3TimeseriesParamsAggInterval) IsKnown() bool {
switch r {
case AttackLayer3TimeseriesParamsAggInterval15m, AttackLayer3TimeseriesParamsAggInterval1h, AttackLayer3TimeseriesParamsAggInterval1d, AttackLayer3TimeseriesParamsAggInterval1w:
return true
}
return false
}
type AttackLayer3TimeseriesParamsDateRange string
const (
AttackLayer3TimeseriesParamsDateRange1d AttackLayer3TimeseriesParamsDateRange = "1d"
AttackLayer3TimeseriesParamsDateRange2d AttackLayer3TimeseriesParamsDateRange = "2d"
AttackLayer3TimeseriesParamsDateRange7d AttackLayer3TimeseriesParamsDateRange = "7d"
AttackLayer3TimeseriesParamsDateRange14d AttackLayer3TimeseriesParamsDateRange = "14d"
AttackLayer3TimeseriesParamsDateRange28d AttackLayer3TimeseriesParamsDateRange = "28d"
AttackLayer3TimeseriesParamsDateRange12w AttackLayer3TimeseriesParamsDateRange = "12w"
AttackLayer3TimeseriesParamsDateRange24w AttackLayer3TimeseriesParamsDateRange = "24w"
AttackLayer3TimeseriesParamsDateRange52w AttackLayer3TimeseriesParamsDateRange = "52w"
AttackLayer3TimeseriesParamsDateRange1dControl AttackLayer3TimeseriesParamsDateRange = "1dControl"
AttackLayer3TimeseriesParamsDateRange2dControl AttackLayer3TimeseriesParamsDateRange = "2dControl"
AttackLayer3TimeseriesParamsDateRange7dControl AttackLayer3TimeseriesParamsDateRange = "7dControl"
AttackLayer3TimeseriesParamsDateRange14dControl AttackLayer3TimeseriesParamsDateRange = "14dControl"
AttackLayer3TimeseriesParamsDateRange28dControl AttackLayer3TimeseriesParamsDateRange = "28dControl"
AttackLayer3TimeseriesParamsDateRange12wControl AttackLayer3TimeseriesParamsDateRange = "12wControl"
AttackLayer3TimeseriesParamsDateRange24wControl AttackLayer3TimeseriesParamsDateRange = "24wControl"
)
func (r AttackLayer3TimeseriesParamsDateRange) IsKnown() bool {
switch r {
case AttackLayer3TimeseriesParamsDateRange1d, AttackLayer3TimeseriesParamsDateRange2d, AttackLayer3TimeseriesParamsDateRange7d, AttackLayer3TimeseriesParamsDateRange14d, AttackLayer3TimeseriesParamsDateRange28d, AttackLayer3TimeseriesParamsDateRange12w, AttackLayer3TimeseriesParamsDateRange24w, AttackLayer3TimeseriesParamsDateRange52w, AttackLayer3TimeseriesParamsDateRange1dControl, AttackLayer3TimeseriesParamsDateRange2dControl, AttackLayer3TimeseriesParamsDateRange7dControl, AttackLayer3TimeseriesParamsDateRange14dControl, AttackLayer3TimeseriesParamsDateRange28dControl, AttackLayer3TimeseriesParamsDateRange12wControl, AttackLayer3TimeseriesParamsDateRange24wControl:
return true
}
return false
}
// Together with the `location` parameter, will apply the filter to origin or
// target location.
type AttackLayer3TimeseriesParamsDirection string
const (
AttackLayer3TimeseriesParamsDirectionOrigin AttackLayer3TimeseriesParamsDirection = "ORIGIN"
AttackLayer3TimeseriesParamsDirectionTarget AttackLayer3TimeseriesParamsDirection = "TARGET"
)
func (r AttackLayer3TimeseriesParamsDirection) IsKnown() bool {
switch r {
case AttackLayer3TimeseriesParamsDirectionOrigin, AttackLayer3TimeseriesParamsDirectionTarget:
return true
}
return false
}
// Format results are returned in.
type AttackLayer3TimeseriesParamsFormat string
const (
AttackLayer3TimeseriesParamsFormatJson AttackLayer3TimeseriesParamsFormat = "JSON"
AttackLayer3TimeseriesParamsFormatCsv AttackLayer3TimeseriesParamsFormat = "CSV"
)
func (r AttackLayer3TimeseriesParamsFormat) IsKnown() bool {
switch r {
case AttackLayer3TimeseriesParamsFormatJson, AttackLayer3TimeseriesParamsFormatCsv:
return true
}
return false
}
type AttackLayer3TimeseriesParamsIPVersion string
const (
AttackLayer3TimeseriesParamsIPVersionIPv4 AttackLayer3TimeseriesParamsIPVersion = "IPv4"
AttackLayer3TimeseriesParamsIPVersionIPv6 AttackLayer3TimeseriesParamsIPVersion = "IPv6"
)
func (r AttackLayer3TimeseriesParamsIPVersion) IsKnown() bool {
switch r {
case AttackLayer3TimeseriesParamsIPVersionIPv4, AttackLayer3TimeseriesParamsIPVersionIPv6:
return true
}
return false
}
// Measurement units, eg. bytes.
type AttackLayer3TimeseriesParamsMetric string
const (
AttackLayer3TimeseriesParamsMetricBytes AttackLayer3TimeseriesParamsMetric = "BYTES"
AttackLayer3TimeseriesParamsMetricBytesOld AttackLayer3TimeseriesParamsMetric = "BYTES_OLD"
)
func (r AttackLayer3TimeseriesParamsMetric) IsKnown() bool {
switch r {
case AttackLayer3TimeseriesParamsMetricBytes, AttackLayer3TimeseriesParamsMetricBytesOld:
return true
}
return false
}
// Normalization method applied. Refer to
// [Normalization methods](https://developers.cloudflare.com/radar/concepts/normalization/).
type AttackLayer3TimeseriesParamsNormalization string
const (
AttackLayer3TimeseriesParamsNormalizationPercentageChange AttackLayer3TimeseriesParamsNormalization = "PERCENTAGE_CHANGE"
AttackLayer3TimeseriesParamsNormalizationMin0Max AttackLayer3TimeseriesParamsNormalization = "MIN0_MAX"
)
func (r AttackLayer3TimeseriesParamsNormalization) IsKnown() bool {
switch r {
case AttackLayer3TimeseriesParamsNormalizationPercentageChange, AttackLayer3TimeseriesParamsNormalizationMin0Max:
return true
}
return false
}
type AttackLayer3TimeseriesParamsProtocol string
const (
AttackLayer3TimeseriesParamsProtocolUdp AttackLayer3TimeseriesParamsProtocol = "UDP"
AttackLayer3TimeseriesParamsProtocolTCP AttackLayer3TimeseriesParamsProtocol = "TCP"
AttackLayer3TimeseriesParamsProtocolIcmp AttackLayer3TimeseriesParamsProtocol = "ICMP"
AttackLayer3TimeseriesParamsProtocolGRE AttackLayer3TimeseriesParamsProtocol = "GRE"
)
func (r AttackLayer3TimeseriesParamsProtocol) IsKnown() bool {
switch r {
case AttackLayer3TimeseriesParamsProtocolUdp, AttackLayer3TimeseriesParamsProtocolTCP, AttackLayer3TimeseriesParamsProtocolIcmp, AttackLayer3TimeseriesParamsProtocolGRE:
return true
}
return false
}
type AttackLayer3TimeseriesResponseEnvelope struct {
Result AttackLayer3TimeseriesResponse `json:"result,required"`
Success bool `json:"success,required"`
JSON attackLayer3TimeseriesResponseEnvelopeJSON `json:"-"`
}
// attackLayer3TimeseriesResponseEnvelopeJSON contains the JSON metadata for the
// struct [AttackLayer3TimeseriesResponseEnvelope]
type attackLayer3TimeseriesResponseEnvelopeJSON struct {
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AttackLayer3TimeseriesResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r attackLayer3TimeseriesResponseEnvelopeJSON) RawJSON() string {
return r.raw
}