/
attacklayer7.go
378 lines (327 loc) · 16.8 KB
/
attacklayer7.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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
// 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"
)
// AttackLayer7Service 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 [NewAttackLayer7Service] method
// instead.
type AttackLayer7Service struct {
Options []option.RequestOption
Summary *AttackLayer7SummaryService
TimeseriesGroups *AttackLayer7TimeseriesGroupService
Top *AttackLayer7TopService
}
// NewAttackLayer7Service 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 NewAttackLayer7Service(opts ...option.RequestOption) (r *AttackLayer7Service) {
r = &AttackLayer7Service{}
r.Options = opts
r.Summary = NewAttackLayer7SummaryService(opts...)
r.TimeseriesGroups = NewAttackLayer7TimeseriesGroupService(opts...)
r.Top = NewAttackLayer7TopService(opts...)
return
}
// Get a timeseries of Layer 7 attacks. Values represent HTTP requests and are
// normalized using min-max by default.
func (r *AttackLayer7Service) Timeseries(ctx context.Context, query AttackLayer7TimeseriesParams, opts ...option.RequestOption) (res *AttackLayer7TimeseriesResponse, err error) {
opts = append(r.Options[:], opts...)
var env AttackLayer7TimeseriesResponseEnvelope
path := "radar/attacks/layer7/timeseries"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type AttackLayer7TimeseriesResponse struct {
Meta AttackLayer7TimeseriesResponseMeta `json:"meta,required"`
Serie0 AttackLayer7TimeseriesResponseSerie0 `json:"serie_0,required"`
JSON attackLayer7TimeseriesResponseJSON `json:"-"`
}
// attackLayer7TimeseriesResponseJSON contains the JSON metadata for the struct
// [AttackLayer7TimeseriesResponse]
type attackLayer7TimeseriesResponseJSON struct {
Meta apijson.Field
Serie0 apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AttackLayer7TimeseriesResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r attackLayer7TimeseriesResponseJSON) RawJSON() string {
return r.raw
}
type AttackLayer7TimeseriesResponseMeta struct {
AggInterval string `json:"aggInterval,required"`
DateRange []AttackLayer7TimeseriesResponseMetaDateRange `json:"dateRange,required"`
LastUpdated time.Time `json:"lastUpdated,required" format:"date-time"`
ConfidenceInfo AttackLayer7TimeseriesResponseMetaConfidenceInfo `json:"confidenceInfo"`
JSON attackLayer7TimeseriesResponseMetaJSON `json:"-"`
}
// attackLayer7TimeseriesResponseMetaJSON contains the JSON metadata for the struct
// [AttackLayer7TimeseriesResponseMeta]
type attackLayer7TimeseriesResponseMetaJSON struct {
AggInterval apijson.Field
DateRange apijson.Field
LastUpdated apijson.Field
ConfidenceInfo apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AttackLayer7TimeseriesResponseMeta) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r attackLayer7TimeseriesResponseMetaJSON) RawJSON() string {
return r.raw
}
type AttackLayer7TimeseriesResponseMetaDateRange 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 attackLayer7TimeseriesResponseMetaDateRangeJSON `json:"-"`
}
// attackLayer7TimeseriesResponseMetaDateRangeJSON contains the JSON metadata for
// the struct [AttackLayer7TimeseriesResponseMetaDateRange]
type attackLayer7TimeseriesResponseMetaDateRangeJSON struct {
EndTime apijson.Field
StartTime apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AttackLayer7TimeseriesResponseMetaDateRange) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r attackLayer7TimeseriesResponseMetaDateRangeJSON) RawJSON() string {
return r.raw
}
type AttackLayer7TimeseriesResponseMetaConfidenceInfo struct {
Annotations []AttackLayer7TimeseriesResponseMetaConfidenceInfoAnnotation `json:"annotations"`
Level int64 `json:"level"`
JSON attackLayer7TimeseriesResponseMetaConfidenceInfoJSON `json:"-"`
}
// attackLayer7TimeseriesResponseMetaConfidenceInfoJSON contains the JSON metadata
// for the struct [AttackLayer7TimeseriesResponseMetaConfidenceInfo]
type attackLayer7TimeseriesResponseMetaConfidenceInfoJSON struct {
Annotations apijson.Field
Level apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AttackLayer7TimeseriesResponseMetaConfidenceInfo) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r attackLayer7TimeseriesResponseMetaConfidenceInfoJSON) RawJSON() string {
return r.raw
}
type AttackLayer7TimeseriesResponseMetaConfidenceInfoAnnotation 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 attackLayer7TimeseriesResponseMetaConfidenceInfoAnnotationJSON `json:"-"`
}
// attackLayer7TimeseriesResponseMetaConfidenceInfoAnnotationJSON contains the JSON
// metadata for the struct
// [AttackLayer7TimeseriesResponseMetaConfidenceInfoAnnotation]
type attackLayer7TimeseriesResponseMetaConfidenceInfoAnnotationJSON 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 *AttackLayer7TimeseriesResponseMetaConfidenceInfoAnnotation) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r attackLayer7TimeseriesResponseMetaConfidenceInfoAnnotationJSON) RawJSON() string {
return r.raw
}
type AttackLayer7TimeseriesResponseSerie0 struct {
Timestamps []time.Time `json:"timestamps,required" format:"date-time"`
Values []string `json:"values,required"`
JSON attackLayer7TimeseriesResponseSerie0JSON `json:"-"`
}
// attackLayer7TimeseriesResponseSerie0JSON contains the JSON metadata for the
// struct [AttackLayer7TimeseriesResponseSerie0]
type attackLayer7TimeseriesResponseSerie0JSON struct {
Timestamps apijson.Field
Values apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AttackLayer7TimeseriesResponseSerie0) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r attackLayer7TimeseriesResponseSerie0JSON) RawJSON() string {
return r.raw
}
type AttackLayer7TimeseriesParams 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[AttackLayer7TimeseriesParamsAggInterval] `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 L7 attack types.
Attack param.Field[[]AttackLayer7TimeseriesParamsAttack] `query:"attack"`
// 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[[]AttackLayer7TimeseriesParamsDateRange] `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[AttackLayer7TimeseriesParamsFormat] `query:"format"`
// 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"`
// 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[AttackLayer7TimeseriesParamsNormalization] `query:"normalization"`
}
// URLQuery serializes [AttackLayer7TimeseriesParams]'s query parameters as
// `url.Values`.
func (r AttackLayer7TimeseriesParams) 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 AttackLayer7TimeseriesParamsAggInterval string
const (
AttackLayer7TimeseriesParamsAggInterval15m AttackLayer7TimeseriesParamsAggInterval = "15m"
AttackLayer7TimeseriesParamsAggInterval1h AttackLayer7TimeseriesParamsAggInterval = "1h"
AttackLayer7TimeseriesParamsAggInterval1d AttackLayer7TimeseriesParamsAggInterval = "1d"
AttackLayer7TimeseriesParamsAggInterval1w AttackLayer7TimeseriesParamsAggInterval = "1w"
)
func (r AttackLayer7TimeseriesParamsAggInterval) IsKnown() bool {
switch r {
case AttackLayer7TimeseriesParamsAggInterval15m, AttackLayer7TimeseriesParamsAggInterval1h, AttackLayer7TimeseriesParamsAggInterval1d, AttackLayer7TimeseriesParamsAggInterval1w:
return true
}
return false
}
type AttackLayer7TimeseriesParamsAttack string
const (
AttackLayer7TimeseriesParamsAttackDDoS AttackLayer7TimeseriesParamsAttack = "DDOS"
AttackLayer7TimeseriesParamsAttackWAF AttackLayer7TimeseriesParamsAttack = "WAF"
AttackLayer7TimeseriesParamsAttackBotManagement AttackLayer7TimeseriesParamsAttack = "BOT_MANAGEMENT"
AttackLayer7TimeseriesParamsAttackAccessRules AttackLayer7TimeseriesParamsAttack = "ACCESS_RULES"
AttackLayer7TimeseriesParamsAttackIPReputation AttackLayer7TimeseriesParamsAttack = "IP_REPUTATION"
AttackLayer7TimeseriesParamsAttackAPIShield AttackLayer7TimeseriesParamsAttack = "API_SHIELD"
AttackLayer7TimeseriesParamsAttackDataLossPrevention AttackLayer7TimeseriesParamsAttack = "DATA_LOSS_PREVENTION"
)
func (r AttackLayer7TimeseriesParamsAttack) IsKnown() bool {
switch r {
case AttackLayer7TimeseriesParamsAttackDDoS, AttackLayer7TimeseriesParamsAttackWAF, AttackLayer7TimeseriesParamsAttackBotManagement, AttackLayer7TimeseriesParamsAttackAccessRules, AttackLayer7TimeseriesParamsAttackIPReputation, AttackLayer7TimeseriesParamsAttackAPIShield, AttackLayer7TimeseriesParamsAttackDataLossPrevention:
return true
}
return false
}
type AttackLayer7TimeseriesParamsDateRange string
const (
AttackLayer7TimeseriesParamsDateRange1d AttackLayer7TimeseriesParamsDateRange = "1d"
AttackLayer7TimeseriesParamsDateRange2d AttackLayer7TimeseriesParamsDateRange = "2d"
AttackLayer7TimeseriesParamsDateRange7d AttackLayer7TimeseriesParamsDateRange = "7d"
AttackLayer7TimeseriesParamsDateRange14d AttackLayer7TimeseriesParamsDateRange = "14d"
AttackLayer7TimeseriesParamsDateRange28d AttackLayer7TimeseriesParamsDateRange = "28d"
AttackLayer7TimeseriesParamsDateRange12w AttackLayer7TimeseriesParamsDateRange = "12w"
AttackLayer7TimeseriesParamsDateRange24w AttackLayer7TimeseriesParamsDateRange = "24w"
AttackLayer7TimeseriesParamsDateRange52w AttackLayer7TimeseriesParamsDateRange = "52w"
AttackLayer7TimeseriesParamsDateRange1dControl AttackLayer7TimeseriesParamsDateRange = "1dControl"
AttackLayer7TimeseriesParamsDateRange2dControl AttackLayer7TimeseriesParamsDateRange = "2dControl"
AttackLayer7TimeseriesParamsDateRange7dControl AttackLayer7TimeseriesParamsDateRange = "7dControl"
AttackLayer7TimeseriesParamsDateRange14dControl AttackLayer7TimeseriesParamsDateRange = "14dControl"
AttackLayer7TimeseriesParamsDateRange28dControl AttackLayer7TimeseriesParamsDateRange = "28dControl"
AttackLayer7TimeseriesParamsDateRange12wControl AttackLayer7TimeseriesParamsDateRange = "12wControl"
AttackLayer7TimeseriesParamsDateRange24wControl AttackLayer7TimeseriesParamsDateRange = "24wControl"
)
func (r AttackLayer7TimeseriesParamsDateRange) IsKnown() bool {
switch r {
case AttackLayer7TimeseriesParamsDateRange1d, AttackLayer7TimeseriesParamsDateRange2d, AttackLayer7TimeseriesParamsDateRange7d, AttackLayer7TimeseriesParamsDateRange14d, AttackLayer7TimeseriesParamsDateRange28d, AttackLayer7TimeseriesParamsDateRange12w, AttackLayer7TimeseriesParamsDateRange24w, AttackLayer7TimeseriesParamsDateRange52w, AttackLayer7TimeseriesParamsDateRange1dControl, AttackLayer7TimeseriesParamsDateRange2dControl, AttackLayer7TimeseriesParamsDateRange7dControl, AttackLayer7TimeseriesParamsDateRange14dControl, AttackLayer7TimeseriesParamsDateRange28dControl, AttackLayer7TimeseriesParamsDateRange12wControl, AttackLayer7TimeseriesParamsDateRange24wControl:
return true
}
return false
}
// Format results are returned in.
type AttackLayer7TimeseriesParamsFormat string
const (
AttackLayer7TimeseriesParamsFormatJson AttackLayer7TimeseriesParamsFormat = "JSON"
AttackLayer7TimeseriesParamsFormatCsv AttackLayer7TimeseriesParamsFormat = "CSV"
)
func (r AttackLayer7TimeseriesParamsFormat) IsKnown() bool {
switch r {
case AttackLayer7TimeseriesParamsFormatJson, AttackLayer7TimeseriesParamsFormatCsv:
return true
}
return false
}
// Normalization method applied. Refer to
// [Normalization methods](https://developers.cloudflare.com/radar/concepts/normalization/).
type AttackLayer7TimeseriesParamsNormalization string
const (
AttackLayer7TimeseriesParamsNormalizationPercentageChange AttackLayer7TimeseriesParamsNormalization = "PERCENTAGE_CHANGE"
AttackLayer7TimeseriesParamsNormalizationMin0Max AttackLayer7TimeseriesParamsNormalization = "MIN0_MAX"
)
func (r AttackLayer7TimeseriesParamsNormalization) IsKnown() bool {
switch r {
case AttackLayer7TimeseriesParamsNormalizationPercentageChange, AttackLayer7TimeseriesParamsNormalizationMin0Max:
return true
}
return false
}
type AttackLayer7TimeseriesResponseEnvelope struct {
Result AttackLayer7TimeseriesResponse `json:"result,required"`
Success bool `json:"success,required"`
JSON attackLayer7TimeseriesResponseEnvelopeJSON `json:"-"`
}
// attackLayer7TimeseriesResponseEnvelopeJSON contains the JSON metadata for the
// struct [AttackLayer7TimeseriesResponseEnvelope]
type attackLayer7TimeseriesResponseEnvelopeJSON struct {
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AttackLayer7TimeseriesResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r attackLayer7TimeseriesResponseEnvelopeJSON) RawJSON() string {
return r.raw
}