/
riskscoring.go
335 lines (286 loc) · 11.1 KB
/
riskscoring.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package zero_trust
import (
"context"
"fmt"
"net/http"
"net/url"
"reflect"
"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/internal/shared"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/tidwall/gjson"
)
// RiskScoringService 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 [NewRiskScoringService] method
// instead.
type RiskScoringService struct {
Options []option.RequestOption
Behaviours *RiskScoringBehaviourService
Summary *RiskScoringSummaryService
}
// NewRiskScoringService 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 NewRiskScoringService(opts ...option.RequestOption) (r *RiskScoringService) {
r = &RiskScoringService{}
r.Options = opts
r.Behaviours = NewRiskScoringBehaviourService(opts...)
r.Summary = NewRiskScoringSummaryService(opts...)
return
}
// Get risk event/score information for a specific user
func (r *RiskScoringService) Get(ctx context.Context, accountIdentifier string, userID string, query RiskScoringGetParams, opts ...option.RequestOption) (res *RiskScoringGetResponse, err error) {
opts = append(r.Options[:], opts...)
var env RiskScoringGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/zt_risk_scoring/%s", accountIdentifier, userID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Clear the risk score for a particular user
func (r *RiskScoringService) Reset(ctx context.Context, accountIdentifier string, userID string, opts ...option.RequestOption) (res *RiskScoringResetResponseUnion, err error) {
opts = append(r.Options[:], opts...)
var env RiskScoringResetResponseEnvelope
path := fmt.Sprintf("accounts/%s/zt_risk_scoring/%s/reset", accountIdentifier, userID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
type RiskScoringGetResponse struct {
Email string `json:"email"`
Events []RiskScoringGetResponseEvent `json:"events"`
LastResetTime time.Time `json:"last_reset_time,nullable" format:"date-time"`
Name string `json:"name"`
RiskLevel RiskScoringGetResponseRiskLevel `json:"risk_level,nullable"`
JSON riskScoringGetResponseJSON `json:"-"`
}
// riskScoringGetResponseJSON contains the JSON metadata for the struct
// [RiskScoringGetResponse]
type riskScoringGetResponseJSON struct {
Email apijson.Field
Events apijson.Field
LastResetTime apijson.Field
Name apijson.Field
RiskLevel apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *RiskScoringGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r riskScoringGetResponseJSON) RawJSON() string {
return r.raw
}
type RiskScoringGetResponseEvent struct {
ID string `json:"id,required"`
Name string `json:"name,required"`
RiskLevel RiskScoringGetResponseEventsRiskLevel `json:"risk_level,required,nullable"`
Timestamp time.Time `json:"timestamp,required" format:"date-time"`
EventDetails interface{} `json:"event_details"`
JSON riskScoringGetResponseEventJSON `json:"-"`
}
// riskScoringGetResponseEventJSON contains the JSON metadata for the struct
// [RiskScoringGetResponseEvent]
type riskScoringGetResponseEventJSON struct {
ID apijson.Field
Name apijson.Field
RiskLevel apijson.Field
Timestamp apijson.Field
EventDetails apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *RiskScoringGetResponseEvent) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r riskScoringGetResponseEventJSON) RawJSON() string {
return r.raw
}
type RiskScoringGetResponseEventsRiskLevel string
const (
RiskScoringGetResponseEventsRiskLevelLow RiskScoringGetResponseEventsRiskLevel = "low"
RiskScoringGetResponseEventsRiskLevelMedium RiskScoringGetResponseEventsRiskLevel = "medium"
RiskScoringGetResponseEventsRiskLevelHigh RiskScoringGetResponseEventsRiskLevel = "high"
)
func (r RiskScoringGetResponseEventsRiskLevel) IsKnown() bool {
switch r {
case RiskScoringGetResponseEventsRiskLevelLow, RiskScoringGetResponseEventsRiskLevelMedium, RiskScoringGetResponseEventsRiskLevelHigh:
return true
}
return false
}
type RiskScoringGetResponseRiskLevel string
const (
RiskScoringGetResponseRiskLevelLow RiskScoringGetResponseRiskLevel = "low"
RiskScoringGetResponseRiskLevelMedium RiskScoringGetResponseRiskLevel = "medium"
RiskScoringGetResponseRiskLevelHigh RiskScoringGetResponseRiskLevel = "high"
)
func (r RiskScoringGetResponseRiskLevel) IsKnown() bool {
switch r {
case RiskScoringGetResponseRiskLevelLow, RiskScoringGetResponseRiskLevelMedium, RiskScoringGetResponseRiskLevelHigh:
return true
}
return false
}
// Union satisfied by [zero_trust.RiskScoringResetResponseUnknown] or
// [shared.UnionString].
type RiskScoringResetResponseUnion interface {
ImplementsZeroTrustRiskScoringResetResponseUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*RiskScoringResetResponseUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}
type RiskScoringGetParams struct {
Direction param.Field[RiskScoringGetParamsDirection] `query:"direction"`
OrderBy param.Field[RiskScoringGetParamsOrderBy] `query:"order_by"`
Page param.Field[int64] `query:"page"`
PerPage param.Field[int64] `query:"per_page"`
}
// URLQuery serializes [RiskScoringGetParams]'s query parameters as `url.Values`.
func (r RiskScoringGetParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type RiskScoringGetParamsDirection string
const (
RiskScoringGetParamsDirectionDesc RiskScoringGetParamsDirection = "desc"
RiskScoringGetParamsDirectionAsc RiskScoringGetParamsDirection = "asc"
)
func (r RiskScoringGetParamsDirection) IsKnown() bool {
switch r {
case RiskScoringGetParamsDirectionDesc, RiskScoringGetParamsDirectionAsc:
return true
}
return false
}
type RiskScoringGetParamsOrderBy string
const (
RiskScoringGetParamsOrderByTimestamp RiskScoringGetParamsOrderBy = "timestamp"
RiskScoringGetParamsOrderByRiskLevel RiskScoringGetParamsOrderBy = "risk_level"
)
func (r RiskScoringGetParamsOrderBy) IsKnown() bool {
switch r {
case RiskScoringGetParamsOrderByTimestamp, RiskScoringGetParamsOrderByRiskLevel:
return true
}
return false
}
type RiskScoringGetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result RiskScoringGetResponse `json:"result,required"`
// Whether the API call was successful
Success RiskScoringGetResponseEnvelopeSuccess `json:"success,required"`
ResultInfo RiskScoringGetResponseEnvelopeResultInfo `json:"result_info"`
JSON riskScoringGetResponseEnvelopeJSON `json:"-"`
}
// riskScoringGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [RiskScoringGetResponseEnvelope]
type riskScoringGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
ResultInfo apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *RiskScoringGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r riskScoringGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type RiskScoringGetResponseEnvelopeSuccess bool
const (
RiskScoringGetResponseEnvelopeSuccessTrue RiskScoringGetResponseEnvelopeSuccess = true
)
func (r RiskScoringGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case RiskScoringGetResponseEnvelopeSuccessTrue:
return true
}
return false
}
type RiskScoringGetResponseEnvelopeResultInfo struct {
Count int64 `json:"count,required"`
Page int64 `json:"page,required"`
PerPage int64 `json:"per_page,required"`
TotalCount int64 `json:"total_count,required"`
JSON riskScoringGetResponseEnvelopeResultInfoJSON `json:"-"`
}
// riskScoringGetResponseEnvelopeResultInfoJSON contains the JSON metadata for the
// struct [RiskScoringGetResponseEnvelopeResultInfo]
type riskScoringGetResponseEnvelopeResultInfoJSON struct {
Count apijson.Field
Page apijson.Field
PerPage apijson.Field
TotalCount apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *RiskScoringGetResponseEnvelopeResultInfo) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r riskScoringGetResponseEnvelopeResultInfoJSON) RawJSON() string {
return r.raw
}
type RiskScoringResetResponseEnvelope struct {
Errors []shared.ResponseInfo `json:"errors,required"`
Messages []shared.ResponseInfo `json:"messages,required"`
Result RiskScoringResetResponseUnion `json:"result,required"`
// Whether the API call was successful
Success RiskScoringResetResponseEnvelopeSuccess `json:"success,required"`
JSON riskScoringResetResponseEnvelopeJSON `json:"-"`
}
// riskScoringResetResponseEnvelopeJSON contains the JSON metadata for the struct
// [RiskScoringResetResponseEnvelope]
type riskScoringResetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *RiskScoringResetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r riskScoringResetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type RiskScoringResetResponseEnvelopeSuccess bool
const (
RiskScoringResetResponseEnvelopeSuccessTrue RiskScoringResetResponseEnvelopeSuccess = true
)
func (r RiskScoringResetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case RiskScoringResetResponseEnvelopeSuccessTrue:
return true
}
return false
}