/
versionbytag.go
483 lines (433 loc) · 20 KB
/
versionbytag.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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package rulesets
import (
"context"
"fmt"
"net/http"
"reflect"
"time"
"github.com/cloudflare/cloudflare-go/v2/internal/apijson"
"github.com/cloudflare/cloudflare-go/v2/internal/param"
"github.com/cloudflare/cloudflare-go/v2/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v2/option"
"github.com/tidwall/gjson"
)
// VersionByTagService 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 [NewVersionByTagService] method
// instead.
type VersionByTagService struct {
Options []option.RequestOption
}
// NewVersionByTagService 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 NewVersionByTagService(opts ...option.RequestOption) (r *VersionByTagService) {
r = &VersionByTagService{}
r.Options = opts
return
}
// Fetches the rules of a managed account ruleset version for a given tag.
func (r *VersionByTagService) Get(ctx context.Context, rulesetID string, rulesetVersion string, ruleTag string, query VersionByTagGetParams, opts ...option.RequestOption) (res *VersionByTagGetResponse, err error) {
opts = append(r.Options[:], opts...)
var env VersionByTagGetResponseEnvelope
path := fmt.Sprintf("accounts/%s/rulesets/%s/versions/%s/by_tag/%s", query.AccountID, rulesetID, rulesetVersion, ruleTag)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// A ruleset object.
type VersionByTagGetResponse struct {
// The unique ID of the ruleset.
ID string `json:"id,required"`
// The kind of the ruleset.
Kind VersionByTagGetResponseKind `json:"kind,required"`
// The timestamp of when the ruleset was last modified.
LastUpdated time.Time `json:"last_updated,required" format:"date-time"`
// The human-readable name of the ruleset.
Name string `json:"name,required"`
// The phase of the ruleset.
Phase VersionByTagGetResponsePhase `json:"phase,required"`
// The list of rules in the ruleset.
Rules []VersionByTagGetResponseRule `json:"rules,required"`
// The version of the ruleset.
Version string `json:"version,required"`
// An informative description of the ruleset.
Description string `json:"description"`
JSON versionByTagGetResponseJSON `json:"-"`
}
// versionByTagGetResponseJSON contains the JSON metadata for the struct
// [VersionByTagGetResponse]
type versionByTagGetResponseJSON struct {
ID apijson.Field
Kind apijson.Field
LastUpdated apijson.Field
Name apijson.Field
Phase apijson.Field
Rules apijson.Field
Version apijson.Field
Description apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *VersionByTagGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r versionByTagGetResponseJSON) RawJSON() string {
return r.raw
}
// The kind of the ruleset.
type VersionByTagGetResponseKind string
const (
VersionByTagGetResponseKindManaged VersionByTagGetResponseKind = "managed"
VersionByTagGetResponseKindCustom VersionByTagGetResponseKind = "custom"
VersionByTagGetResponseKindRoot VersionByTagGetResponseKind = "root"
VersionByTagGetResponseKindZone VersionByTagGetResponseKind = "zone"
)
func (r VersionByTagGetResponseKind) IsKnown() bool {
switch r {
case VersionByTagGetResponseKindManaged, VersionByTagGetResponseKindCustom, VersionByTagGetResponseKindRoot, VersionByTagGetResponseKindZone:
return true
}
return false
}
// The phase of the ruleset.
type VersionByTagGetResponsePhase string
const (
VersionByTagGetResponsePhaseDDoSL4 VersionByTagGetResponsePhase = "ddos_l4"
VersionByTagGetResponsePhaseDDoSL7 VersionByTagGetResponsePhase = "ddos_l7"
VersionByTagGetResponsePhaseHTTPConfigSettings VersionByTagGetResponsePhase = "http_config_settings"
VersionByTagGetResponsePhaseHTTPCustomErrors VersionByTagGetResponsePhase = "http_custom_errors"
VersionByTagGetResponsePhaseHTTPLogCustomFields VersionByTagGetResponsePhase = "http_log_custom_fields"
VersionByTagGetResponsePhaseHTTPRatelimit VersionByTagGetResponsePhase = "http_ratelimit"
VersionByTagGetResponsePhaseHTTPRequestCacheSettings VersionByTagGetResponsePhase = "http_request_cache_settings"
VersionByTagGetResponsePhaseHTTPRequestDynamicRedirect VersionByTagGetResponsePhase = "http_request_dynamic_redirect"
VersionByTagGetResponsePhaseHTTPRequestFirewallCustom VersionByTagGetResponsePhase = "http_request_firewall_custom"
VersionByTagGetResponsePhaseHTTPRequestFirewallManaged VersionByTagGetResponsePhase = "http_request_firewall_managed"
VersionByTagGetResponsePhaseHTTPRequestLateTransform VersionByTagGetResponsePhase = "http_request_late_transform"
VersionByTagGetResponsePhaseHTTPRequestOrigin VersionByTagGetResponsePhase = "http_request_origin"
VersionByTagGetResponsePhaseHTTPRequestRedirect VersionByTagGetResponsePhase = "http_request_redirect"
VersionByTagGetResponsePhaseHTTPRequestSanitize VersionByTagGetResponsePhase = "http_request_sanitize"
VersionByTagGetResponsePhaseHTTPRequestSBFM VersionByTagGetResponsePhase = "http_request_sbfm"
VersionByTagGetResponsePhaseHTTPRequestSelectConfiguration VersionByTagGetResponsePhase = "http_request_select_configuration"
VersionByTagGetResponsePhaseHTTPRequestTransform VersionByTagGetResponsePhase = "http_request_transform"
VersionByTagGetResponsePhaseHTTPResponseCompression VersionByTagGetResponsePhase = "http_response_compression"
VersionByTagGetResponsePhaseHTTPResponseFirewallManaged VersionByTagGetResponsePhase = "http_response_firewall_managed"
VersionByTagGetResponsePhaseHTTPResponseHeadersTransform VersionByTagGetResponsePhase = "http_response_headers_transform"
VersionByTagGetResponsePhaseMagicTransit VersionByTagGetResponsePhase = "magic_transit"
VersionByTagGetResponsePhaseMagicTransitIDsManaged VersionByTagGetResponsePhase = "magic_transit_ids_managed"
VersionByTagGetResponsePhaseMagicTransitManaged VersionByTagGetResponsePhase = "magic_transit_managed"
)
func (r VersionByTagGetResponsePhase) IsKnown() bool {
switch r {
case VersionByTagGetResponsePhaseDDoSL4, VersionByTagGetResponsePhaseDDoSL7, VersionByTagGetResponsePhaseHTTPConfigSettings, VersionByTagGetResponsePhaseHTTPCustomErrors, VersionByTagGetResponsePhaseHTTPLogCustomFields, VersionByTagGetResponsePhaseHTTPRatelimit, VersionByTagGetResponsePhaseHTTPRequestCacheSettings, VersionByTagGetResponsePhaseHTTPRequestDynamicRedirect, VersionByTagGetResponsePhaseHTTPRequestFirewallCustom, VersionByTagGetResponsePhaseHTTPRequestFirewallManaged, VersionByTagGetResponsePhaseHTTPRequestLateTransform, VersionByTagGetResponsePhaseHTTPRequestOrigin, VersionByTagGetResponsePhaseHTTPRequestRedirect, VersionByTagGetResponsePhaseHTTPRequestSanitize, VersionByTagGetResponsePhaseHTTPRequestSBFM, VersionByTagGetResponsePhaseHTTPRequestSelectConfiguration, VersionByTagGetResponsePhaseHTTPRequestTransform, VersionByTagGetResponsePhaseHTTPResponseCompression, VersionByTagGetResponsePhaseHTTPResponseFirewallManaged, VersionByTagGetResponsePhaseHTTPResponseHeadersTransform, VersionByTagGetResponsePhaseMagicTransit, VersionByTagGetResponsePhaseMagicTransitIDsManaged, VersionByTagGetResponsePhaseMagicTransitManaged:
return true
}
return false
}
type VersionByTagGetResponseRule struct {
// The action to perform when the rule matches.
Action VersionByTagGetResponseRulesAction `json:"action"`
ActionParameters interface{} `json:"action_parameters,required"`
Categories interface{} `json:"categories,required"`
// An informative description of the rule.
Description string `json:"description"`
// Whether the rule should be executed.
Enabled bool `json:"enabled"`
// The expression defining which traffic will match the rule.
Expression string `json:"expression"`
// The unique ID of the rule.
ID string `json:"id"`
// The timestamp of when the rule was last modified.
LastUpdated time.Time `json:"last_updated,required" format:"date-time"`
// An object configuring the rule's logging behavior.
Logging Logging `json:"logging"`
// The reference of the rule (the rule ID by default).
Ref string `json:"ref"`
// The version of the rule.
Version string `json:"version,required"`
JSON versionByTagGetResponseRuleJSON `json:"-"`
union VersionByTagGetResponseRulesUnion
}
// versionByTagGetResponseRuleJSON contains the JSON metadata for the struct
// [VersionByTagGetResponseRule]
type versionByTagGetResponseRuleJSON struct {
Action apijson.Field
ActionParameters apijson.Field
Categories apijson.Field
Description apijson.Field
Enabled apijson.Field
Expression apijson.Field
ID apijson.Field
LastUpdated apijson.Field
Logging apijson.Field
Ref apijson.Field
Version apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r versionByTagGetResponseRuleJSON) RawJSON() string {
return r.raw
}
func (r *VersionByTagGetResponseRule) UnmarshalJSON(data []byte) (err error) {
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
func (r VersionByTagGetResponseRule) AsUnion() VersionByTagGetResponseRulesUnion {
return r.union
}
// Union satisfied by [rulesets.BlockRule], [rulesets.ChallengeRule],
// [rulesets.CompressResponseRule], [rulesets.ExecuteRule],
// [rulesets.JSChallengeRule], [rulesets.LogRule], [rulesets.ManagedChallengeRule],
// [rulesets.RedirectRule], [rulesets.RewriteRule], [rulesets.RouteRule],
// [rulesets.ScoreRule], [rulesets.ServeErrorRule], [rulesets.SetConfigRule],
// [rulesets.SkipRule] or [rulesets.SetCacheSettingsRule].
type VersionByTagGetResponseRulesUnion interface {
implementsRulesetsVersionByTagGetResponseRule()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*VersionByTagGetResponseRulesUnion)(nil)).Elem(),
"action",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BlockRule{}),
DiscriminatorValue: "block",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ChallengeRule{}),
DiscriminatorValue: "challenge",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(CompressResponseRule{}),
DiscriminatorValue: "compress_response",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ExecuteRule{}),
DiscriminatorValue: "execute",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(JSChallengeRule{}),
DiscriminatorValue: "js_challenge",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(LogRule{}),
DiscriminatorValue: "log",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ManagedChallengeRule{}),
DiscriminatorValue: "managed_challenge",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(RedirectRule{}),
DiscriminatorValue: "redirect",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(RewriteRule{}),
DiscriminatorValue: "rewrite",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(RouteRule{}),
DiscriminatorValue: "route",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ScoreRule{}),
DiscriminatorValue: "score",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(ServeErrorRule{}),
DiscriminatorValue: "serve_error",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(SetConfigRule{}),
DiscriminatorValue: "set_config",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(SkipRule{}),
DiscriminatorValue: "skip",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(SetCacheSettingsRule{}),
DiscriminatorValue: "set_cache_settings",
},
)
}
// The action to perform when the rule matches.
type VersionByTagGetResponseRulesAction string
const (
VersionByTagGetResponseRulesActionBlock VersionByTagGetResponseRulesAction = "block"
VersionByTagGetResponseRulesActionChallenge VersionByTagGetResponseRulesAction = "challenge"
VersionByTagGetResponseRulesActionCompressResponse VersionByTagGetResponseRulesAction = "compress_response"
VersionByTagGetResponseRulesActionExecute VersionByTagGetResponseRulesAction = "execute"
VersionByTagGetResponseRulesActionJSChallenge VersionByTagGetResponseRulesAction = "js_challenge"
VersionByTagGetResponseRulesActionLog VersionByTagGetResponseRulesAction = "log"
VersionByTagGetResponseRulesActionManagedChallenge VersionByTagGetResponseRulesAction = "managed_challenge"
VersionByTagGetResponseRulesActionRedirect VersionByTagGetResponseRulesAction = "redirect"
VersionByTagGetResponseRulesActionRewrite VersionByTagGetResponseRulesAction = "rewrite"
VersionByTagGetResponseRulesActionRoute VersionByTagGetResponseRulesAction = "route"
VersionByTagGetResponseRulesActionScore VersionByTagGetResponseRulesAction = "score"
VersionByTagGetResponseRulesActionServeError VersionByTagGetResponseRulesAction = "serve_error"
VersionByTagGetResponseRulesActionSetConfig VersionByTagGetResponseRulesAction = "set_config"
VersionByTagGetResponseRulesActionSkip VersionByTagGetResponseRulesAction = "skip"
VersionByTagGetResponseRulesActionSetCacheSettings VersionByTagGetResponseRulesAction = "set_cache_settings"
)
func (r VersionByTagGetResponseRulesAction) IsKnown() bool {
switch r {
case VersionByTagGetResponseRulesActionBlock, VersionByTagGetResponseRulesActionChallenge, VersionByTagGetResponseRulesActionCompressResponse, VersionByTagGetResponseRulesActionExecute, VersionByTagGetResponseRulesActionJSChallenge, VersionByTagGetResponseRulesActionLog, VersionByTagGetResponseRulesActionManagedChallenge, VersionByTagGetResponseRulesActionRedirect, VersionByTagGetResponseRulesActionRewrite, VersionByTagGetResponseRulesActionRoute, VersionByTagGetResponseRulesActionScore, VersionByTagGetResponseRulesActionServeError, VersionByTagGetResponseRulesActionSetConfig, VersionByTagGetResponseRulesActionSkip, VersionByTagGetResponseRulesActionSetCacheSettings:
return true
}
return false
}
type VersionByTagGetParams struct {
// The unique ID of the account.
AccountID param.Field[string] `path:"account_id,required"`
}
// A response object.
type VersionByTagGetResponseEnvelope struct {
// A list of error messages.
Errors []VersionByTagGetResponseEnvelopeErrors `json:"errors,required"`
// A list of warning messages.
Messages []VersionByTagGetResponseEnvelopeMessages `json:"messages,required"`
// A ruleset object.
Result VersionByTagGetResponse `json:"result,required"`
// Whether the API call was successful.
Success VersionByTagGetResponseEnvelopeSuccess `json:"success,required"`
JSON versionByTagGetResponseEnvelopeJSON `json:"-"`
}
// versionByTagGetResponseEnvelopeJSON contains the JSON metadata for the struct
// [VersionByTagGetResponseEnvelope]
type versionByTagGetResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *VersionByTagGetResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r versionByTagGetResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
// A message.
type VersionByTagGetResponseEnvelopeErrors struct {
// A text description of this message.
Message string `json:"message,required"`
// A unique code for this message.
Code int64 `json:"code"`
// The source of this message.
Source VersionByTagGetResponseEnvelopeErrorsSource `json:"source"`
JSON versionByTagGetResponseEnvelopeErrorsJSON `json:"-"`
}
// versionByTagGetResponseEnvelopeErrorsJSON contains the JSON metadata for the
// struct [VersionByTagGetResponseEnvelopeErrors]
type versionByTagGetResponseEnvelopeErrorsJSON struct {
Message apijson.Field
Code apijson.Field
Source apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *VersionByTagGetResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r versionByTagGetResponseEnvelopeErrorsJSON) RawJSON() string {
return r.raw
}
// The source of this message.
type VersionByTagGetResponseEnvelopeErrorsSource struct {
// A JSON pointer to the field that is the source of the message.
Pointer string `json:"pointer,required"`
JSON versionByTagGetResponseEnvelopeErrorsSourceJSON `json:"-"`
}
// versionByTagGetResponseEnvelopeErrorsSourceJSON contains the JSON metadata for
// the struct [VersionByTagGetResponseEnvelopeErrorsSource]
type versionByTagGetResponseEnvelopeErrorsSourceJSON struct {
Pointer apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *VersionByTagGetResponseEnvelopeErrorsSource) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r versionByTagGetResponseEnvelopeErrorsSourceJSON) RawJSON() string {
return r.raw
}
// A message.
type VersionByTagGetResponseEnvelopeMessages struct {
// A text description of this message.
Message string `json:"message,required"`
// A unique code for this message.
Code int64 `json:"code"`
// The source of this message.
Source VersionByTagGetResponseEnvelopeMessagesSource `json:"source"`
JSON versionByTagGetResponseEnvelopeMessagesJSON `json:"-"`
}
// versionByTagGetResponseEnvelopeMessagesJSON contains the JSON metadata for the
// struct [VersionByTagGetResponseEnvelopeMessages]
type versionByTagGetResponseEnvelopeMessagesJSON struct {
Message apijson.Field
Code apijson.Field
Source apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *VersionByTagGetResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r versionByTagGetResponseEnvelopeMessagesJSON) RawJSON() string {
return r.raw
}
// The source of this message.
type VersionByTagGetResponseEnvelopeMessagesSource struct {
// A JSON pointer to the field that is the source of the message.
Pointer string `json:"pointer,required"`
JSON versionByTagGetResponseEnvelopeMessagesSourceJSON `json:"-"`
}
// versionByTagGetResponseEnvelopeMessagesSourceJSON contains the JSON metadata for
// the struct [VersionByTagGetResponseEnvelopeMessagesSource]
type versionByTagGetResponseEnvelopeMessagesSourceJSON struct {
Pointer apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *VersionByTagGetResponseEnvelopeMessagesSource) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r versionByTagGetResponseEnvelopeMessagesSourceJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful.
type VersionByTagGetResponseEnvelopeSuccess bool
const (
VersionByTagGetResponseEnvelopeSuccessTrue VersionByTagGetResponseEnvelopeSuccess = true
)
func (r VersionByTagGetResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case VersionByTagGetResponseEnvelopeSuccessTrue:
return true
}
return false
}