/
accessrule.go
1195 lines (1016 loc) · 43.5 KB
/
accessrule.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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package firewall
import (
"context"
"fmt"
"net/http"
"net/url"
"reflect"
"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"
)
// AccessRuleService 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 [NewAccessRuleService] method instead.
type AccessRuleService struct {
Options []option.RequestOption
}
// NewAccessRuleService 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 NewAccessRuleService(opts ...option.RequestOption) (r *AccessRuleService) {
r = &AccessRuleService{}
r.Options = opts
return
}
// Creates a new IP Access rule for an account or zone. The rule will apply to all
// zones in the account or zone.
//
// Note: To create an IP Access rule that applies to a single zone, refer to the
// [IP Access rules for a zone](#ip-access-rules-for-a-zone) endpoints.
func (r *AccessRuleService) New(ctx context.Context, params AccessRuleNewParams, opts ...option.RequestOption) (res *AccessRuleNewResponse, err error) {
opts = append(r.Options[:], opts...)
var env AccessRuleNewResponseEnvelope
var accountOrZone string
var accountOrZoneID param.Field[string]
if params.AccountID.Present {
accountOrZone = "accounts"
accountOrZoneID = params.AccountID
} else {
accountOrZone = "zones"
accountOrZoneID = params.ZoneID
}
path := fmt.Sprintf("%s/%s/firewall/access_rules/rules", accountOrZone, accountOrZoneID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Fetches IP Access rules of an account or zone. These rules apply to all the
// zones in the account or zone. You can filter the results using several optional
// parameters.
func (r *AccessRuleService) List(ctx context.Context, params AccessRuleListParams, opts ...option.RequestOption) (res *shared.V4PagePaginationArray[AccessRuleListResponse], err error) {
var raw *http.Response
opts = append(r.Options, opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
var accountOrZone string
var accountOrZoneID param.Field[string]
if params.AccountID.Present {
accountOrZone = "accounts"
accountOrZoneID = params.AccountID
} else {
accountOrZone = "zones"
accountOrZoneID = params.ZoneID
}
path := fmt.Sprintf("%s/%s/firewall/access_rules/rules", accountOrZone, accountOrZoneID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Fetches IP Access rules of an account or zone. These rules apply to all the
// zones in the account or zone. You can filter the results using several optional
// parameters.
func (r *AccessRuleService) ListAutoPaging(ctx context.Context, params AccessRuleListParams, opts ...option.RequestOption) *shared.V4PagePaginationArrayAutoPager[AccessRuleListResponse] {
return shared.NewV4PagePaginationArrayAutoPager(r.List(ctx, params, opts...))
}
// Deletes an existing IP Access rule defined.
//
// Note: This operation will affect all zones in the account or zone.
func (r *AccessRuleService) Delete(ctx context.Context, identifier interface{}, body AccessRuleDeleteParams, opts ...option.RequestOption) (res *AccessRuleDeleteResponse, err error) {
opts = append(r.Options[:], opts...)
var env AccessRuleDeleteResponseEnvelope
var accountOrZone string
var accountOrZoneID param.Field[string]
if body.AccountID.Present {
accountOrZone = "accounts"
accountOrZoneID = body.AccountID
} else {
accountOrZone = "zones"
accountOrZoneID = body.ZoneID
}
path := fmt.Sprintf("%s/%s/firewall/access_rules/rules/%v", accountOrZone, accountOrZoneID, identifier)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Updates an IP Access rule defined.
//
// Note: This operation will affect all zones in the account or zone.
func (r *AccessRuleService) Edit(ctx context.Context, identifier interface{}, params AccessRuleEditParams, opts ...option.RequestOption) (res *AccessRuleEditResponse, err error) {
opts = append(r.Options[:], opts...)
var env AccessRuleEditResponseEnvelope
var accountOrZone string
var accountOrZoneID param.Field[string]
if params.AccountID.Present {
accountOrZone = "accounts"
accountOrZoneID = params.AccountID
} else {
accountOrZone = "zones"
accountOrZoneID = params.ZoneID
}
path := fmt.Sprintf("%s/%s/firewall/access_rules/rules/%v", accountOrZone, accountOrZoneID, identifier)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPatch, path, params, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Fetches the details of an IP Access rule defined.
func (r *AccessRuleService) Get(ctx context.Context, identifier interface{}, query AccessRuleGetParams, opts ...option.RequestOption) (res *AccessRuleGetResponse, err error) {
opts = append(r.Options[:], opts...)
var env AccessRuleGetResponseEnvelope
var accountOrZone string
var accountOrZoneID param.Field[string]
if query.AccountID.Present {
accountOrZone = "accounts"
accountOrZoneID = query.AccountID
} else {
accountOrZone = "zones"
accountOrZoneID = query.ZoneID
}
path := fmt.Sprintf("%s/%s/firewall/access_rules/rules/%v", accountOrZone, accountOrZoneID, identifier)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &env, opts...)
if err != nil {
return
}
res = &env.Result
return
}
// Union satisfied by [firewall.AccessRuleNewResponseUnknown] or
// [shared.UnionString].
type AccessRuleNewResponse interface {
ImplementsFirewallAccessRuleNewResponse()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*AccessRuleNewResponse)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}
type AccessRuleListResponse = interface{}
type AccessRuleDeleteResponse struct {
// Identifier
ID string `json:"id,required"`
JSON accessRuleDeleteResponseJSON `json:"-"`
}
// accessRuleDeleteResponseJSON contains the JSON metadata for the struct
// [AccessRuleDeleteResponse]
type accessRuleDeleteResponseJSON struct {
ID apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccessRuleDeleteResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accessRuleDeleteResponseJSON) RawJSON() string {
return r.raw
}
// Union satisfied by [firewall.AccessRuleEditResponseUnknown] or
// [shared.UnionString].
type AccessRuleEditResponse interface {
ImplementsFirewallAccessRuleEditResponse()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*AccessRuleEditResponse)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}
// Union satisfied by [firewall.AccessRuleGetResponseUnknown] or
// [shared.UnionString].
type AccessRuleGetResponse interface {
ImplementsFirewallAccessRuleGetResponse()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*AccessRuleGetResponse)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
)
}
type AccessRuleNewParams struct {
// The rule configuration.
Configuration param.Field[AccessRuleNewParamsConfiguration] `json:"configuration,required"`
// The action to apply to a matched request.
Mode param.Field[AccessRuleNewParamsMode] `json:"mode,required"`
// The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.
AccountID param.Field[string] `path:"account_id"`
// The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.
ZoneID param.Field[string] `path:"zone_id"`
// An informative summary of the rule, typically used as a reminder or explanation.
Notes param.Field[string] `json:"notes"`
}
func (r AccessRuleNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// The rule configuration.
//
// Satisfied by
// [firewall.AccessRuleNewParamsConfigurationLegacyJhsIPConfiguration],
// [firewall.AccessRuleNewParamsConfigurationLegacyJhsIPV6Configuration],
// [firewall.AccessRuleNewParamsConfigurationLegacyJhsCIDRConfiguration],
// [firewall.AccessRuleNewParamsConfigurationLegacyJhsASNConfiguration],
// [firewall.AccessRuleNewParamsConfigurationLegacyJhsCountryConfiguration].
type AccessRuleNewParamsConfiguration interface {
implementsFirewallAccessRuleNewParamsConfiguration()
}
type AccessRuleNewParamsConfigurationLegacyJhsIPConfiguration struct {
// The configuration target. You must set the target to `ip` when specifying an IP
// address in the rule.
Target param.Field[AccessRuleNewParamsConfigurationLegacyJhsIPConfigurationTarget] `json:"target"`
// The IP address to match. This address will be compared to the IP address of
// incoming requests.
Value param.Field[string] `json:"value"`
}
func (r AccessRuleNewParamsConfigurationLegacyJhsIPConfiguration) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r AccessRuleNewParamsConfigurationLegacyJhsIPConfiguration) implementsFirewallAccessRuleNewParamsConfiguration() {
}
// The configuration target. You must set the target to `ip` when specifying an IP
// address in the rule.
type AccessRuleNewParamsConfigurationLegacyJhsIPConfigurationTarget string
const (
AccessRuleNewParamsConfigurationLegacyJhsIPConfigurationTargetIP AccessRuleNewParamsConfigurationLegacyJhsIPConfigurationTarget = "ip"
)
func (r AccessRuleNewParamsConfigurationLegacyJhsIPConfigurationTarget) IsKnown() bool {
switch r {
case AccessRuleNewParamsConfigurationLegacyJhsIPConfigurationTargetIP:
return true
}
return false
}
type AccessRuleNewParamsConfigurationLegacyJhsIPV6Configuration struct {
// The configuration target. You must set the target to `ip6` when specifying an
// IPv6 address in the rule.
Target param.Field[AccessRuleNewParamsConfigurationLegacyJhsIPV6ConfigurationTarget] `json:"target"`
// The IPv6 address to match.
Value param.Field[string] `json:"value"`
}
func (r AccessRuleNewParamsConfigurationLegacyJhsIPV6Configuration) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r AccessRuleNewParamsConfigurationLegacyJhsIPV6Configuration) implementsFirewallAccessRuleNewParamsConfiguration() {
}
// The configuration target. You must set the target to `ip6` when specifying an
// IPv6 address in the rule.
type AccessRuleNewParamsConfigurationLegacyJhsIPV6ConfigurationTarget string
const (
AccessRuleNewParamsConfigurationLegacyJhsIPV6ConfigurationTargetIp6 AccessRuleNewParamsConfigurationLegacyJhsIPV6ConfigurationTarget = "ip6"
)
func (r AccessRuleNewParamsConfigurationLegacyJhsIPV6ConfigurationTarget) IsKnown() bool {
switch r {
case AccessRuleNewParamsConfigurationLegacyJhsIPV6ConfigurationTargetIp6:
return true
}
return false
}
type AccessRuleNewParamsConfigurationLegacyJhsCIDRConfiguration struct {
// The configuration target. You must set the target to `ip_range` when specifying
// an IP address range in the rule.
Target param.Field[AccessRuleNewParamsConfigurationLegacyJhsCIDRConfigurationTarget] `json:"target"`
// The IP address range to match. You can only use prefix lengths `/16` and `/24`
// for IPv4 ranges, and prefix lengths `/32`, `/48`, and `/64` for IPv6 ranges.
Value param.Field[string] `json:"value"`
}
func (r AccessRuleNewParamsConfigurationLegacyJhsCIDRConfiguration) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r AccessRuleNewParamsConfigurationLegacyJhsCIDRConfiguration) implementsFirewallAccessRuleNewParamsConfiguration() {
}
// The configuration target. You must set the target to `ip_range` when specifying
// an IP address range in the rule.
type AccessRuleNewParamsConfigurationLegacyJhsCIDRConfigurationTarget string
const (
AccessRuleNewParamsConfigurationLegacyJhsCIDRConfigurationTargetIPRange AccessRuleNewParamsConfigurationLegacyJhsCIDRConfigurationTarget = "ip_range"
)
func (r AccessRuleNewParamsConfigurationLegacyJhsCIDRConfigurationTarget) IsKnown() bool {
switch r {
case AccessRuleNewParamsConfigurationLegacyJhsCIDRConfigurationTargetIPRange:
return true
}
return false
}
type AccessRuleNewParamsConfigurationLegacyJhsASNConfiguration struct {
// The configuration target. You must set the target to `asn` when specifying an
// Autonomous System Number (ASN) in the rule.
Target param.Field[AccessRuleNewParamsConfigurationLegacyJhsASNConfigurationTarget] `json:"target"`
// The AS number to match.
Value param.Field[string] `json:"value"`
}
func (r AccessRuleNewParamsConfigurationLegacyJhsASNConfiguration) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r AccessRuleNewParamsConfigurationLegacyJhsASNConfiguration) implementsFirewallAccessRuleNewParamsConfiguration() {
}
// The configuration target. You must set the target to `asn` when specifying an
// Autonomous System Number (ASN) in the rule.
type AccessRuleNewParamsConfigurationLegacyJhsASNConfigurationTarget string
const (
AccessRuleNewParamsConfigurationLegacyJhsASNConfigurationTargetASN AccessRuleNewParamsConfigurationLegacyJhsASNConfigurationTarget = "asn"
)
func (r AccessRuleNewParamsConfigurationLegacyJhsASNConfigurationTarget) IsKnown() bool {
switch r {
case AccessRuleNewParamsConfigurationLegacyJhsASNConfigurationTargetASN:
return true
}
return false
}
type AccessRuleNewParamsConfigurationLegacyJhsCountryConfiguration struct {
// The configuration target. You must set the target to `country` when specifying a
// country code in the rule.
Target param.Field[AccessRuleNewParamsConfigurationLegacyJhsCountryConfigurationTarget] `json:"target"`
// The two-letter ISO-3166-1 alpha-2 code to match. For more information, refer to
// [IP Access rules: Parameters](https://developers.cloudflare.com/waf/tools/ip-access-rules/parameters/#country).
Value param.Field[string] `json:"value"`
}
func (r AccessRuleNewParamsConfigurationLegacyJhsCountryConfiguration) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r AccessRuleNewParamsConfigurationLegacyJhsCountryConfiguration) implementsFirewallAccessRuleNewParamsConfiguration() {
}
// The configuration target. You must set the target to `country` when specifying a
// country code in the rule.
type AccessRuleNewParamsConfigurationLegacyJhsCountryConfigurationTarget string
const (
AccessRuleNewParamsConfigurationLegacyJhsCountryConfigurationTargetCountry AccessRuleNewParamsConfigurationLegacyJhsCountryConfigurationTarget = "country"
)
func (r AccessRuleNewParamsConfigurationLegacyJhsCountryConfigurationTarget) IsKnown() bool {
switch r {
case AccessRuleNewParamsConfigurationLegacyJhsCountryConfigurationTargetCountry:
return true
}
return false
}
// The action to apply to a matched request.
type AccessRuleNewParamsMode string
const (
AccessRuleNewParamsModeBlock AccessRuleNewParamsMode = "block"
AccessRuleNewParamsModeChallenge AccessRuleNewParamsMode = "challenge"
AccessRuleNewParamsModeWhitelist AccessRuleNewParamsMode = "whitelist"
AccessRuleNewParamsModeJsChallenge AccessRuleNewParamsMode = "js_challenge"
AccessRuleNewParamsModeManagedChallenge AccessRuleNewParamsMode = "managed_challenge"
)
func (r AccessRuleNewParamsMode) IsKnown() bool {
switch r {
case AccessRuleNewParamsModeBlock, AccessRuleNewParamsModeChallenge, AccessRuleNewParamsModeWhitelist, AccessRuleNewParamsModeJsChallenge, AccessRuleNewParamsModeManagedChallenge:
return true
}
return false
}
type AccessRuleNewResponseEnvelope struct {
Errors []AccessRuleNewResponseEnvelopeErrors `json:"errors,required"`
Messages []AccessRuleNewResponseEnvelopeMessages `json:"messages,required"`
Result AccessRuleNewResponse `json:"result,required,nullable"`
// Whether the API call was successful
Success AccessRuleNewResponseEnvelopeSuccess `json:"success,required"`
JSON accessRuleNewResponseEnvelopeJSON `json:"-"`
}
// accessRuleNewResponseEnvelopeJSON contains the JSON metadata for the struct
// [AccessRuleNewResponseEnvelope]
type accessRuleNewResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccessRuleNewResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accessRuleNewResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
type AccessRuleNewResponseEnvelopeErrors struct {
Code int64 `json:"code,required"`
Message string `json:"message,required"`
JSON accessRuleNewResponseEnvelopeErrorsJSON `json:"-"`
}
// accessRuleNewResponseEnvelopeErrorsJSON contains the JSON metadata for the
// struct [AccessRuleNewResponseEnvelopeErrors]
type accessRuleNewResponseEnvelopeErrorsJSON struct {
Code apijson.Field
Message apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccessRuleNewResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accessRuleNewResponseEnvelopeErrorsJSON) RawJSON() string {
return r.raw
}
type AccessRuleNewResponseEnvelopeMessages struct {
Code int64 `json:"code,required"`
Message string `json:"message,required"`
JSON accessRuleNewResponseEnvelopeMessagesJSON `json:"-"`
}
// accessRuleNewResponseEnvelopeMessagesJSON contains the JSON metadata for the
// struct [AccessRuleNewResponseEnvelopeMessages]
type accessRuleNewResponseEnvelopeMessagesJSON struct {
Code apijson.Field
Message apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccessRuleNewResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accessRuleNewResponseEnvelopeMessagesJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type AccessRuleNewResponseEnvelopeSuccess bool
const (
AccessRuleNewResponseEnvelopeSuccessTrue AccessRuleNewResponseEnvelopeSuccess = true
)
func (r AccessRuleNewResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case AccessRuleNewResponseEnvelopeSuccessTrue:
return true
}
return false
}
type AccessRuleListParams struct {
// The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.
AccountID param.Field[string] `path:"account_id"`
// The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.
ZoneID param.Field[string] `path:"zone_id"`
// The direction used to sort returned rules.
Direction param.Field[AccessRuleListParamsDirection] `query:"direction"`
EgsPagination param.Field[AccessRuleListParamsEgsPagination] `query:"egs-pagination"`
Filters param.Field[AccessRuleListParamsFilters] `query:"filters"`
// The field used to sort returned rules.
Order param.Field[AccessRuleListParamsOrder] `query:"order"`
// Requested page within paginated list of results.
Page param.Field[float64] `query:"page"`
// Maximum number of results requested.
PerPage param.Field[float64] `query:"per_page"`
}
// URLQuery serializes [AccessRuleListParams]'s query parameters as `url.Values`.
func (r AccessRuleListParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// The direction used to sort returned rules.
type AccessRuleListParamsDirection string
const (
AccessRuleListParamsDirectionAsc AccessRuleListParamsDirection = "asc"
AccessRuleListParamsDirectionDesc AccessRuleListParamsDirection = "desc"
)
func (r AccessRuleListParamsDirection) IsKnown() bool {
switch r {
case AccessRuleListParamsDirectionAsc, AccessRuleListParamsDirectionDesc:
return true
}
return false
}
type AccessRuleListParamsEgsPagination struct {
Json param.Field[AccessRuleListParamsEgsPaginationJson] `query:"json"`
}
// URLQuery serializes [AccessRuleListParamsEgsPagination]'s query parameters as
// `url.Values`.
func (r AccessRuleListParamsEgsPagination) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type AccessRuleListParamsEgsPaginationJson struct {
// The page number of paginated results.
Page param.Field[float64] `query:"page"`
// The maximum number of results per page. You can only set the value to `1` or to
// a multiple of 5 such as `5`, `10`, `15`, or `20`.
PerPage param.Field[float64] `query:"per_page"`
}
// URLQuery serializes [AccessRuleListParamsEgsPaginationJson]'s query parameters
// as `url.Values`.
func (r AccessRuleListParamsEgsPaginationJson) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
type AccessRuleListParamsFilters struct {
// The target to search in existing rules.
ConfigurationTarget param.Field[AccessRuleListParamsFiltersConfigurationTarget] `query:"configuration.target"`
// The target value to search for in existing rules: an IP address, an IP address
// range, or a country code, depending on the provided `configuration.target`.
// Notes: You can search for a single IPv4 address, an IP address range with a
// subnet of '/16' or '/24', or a two-letter ISO-3166-1 alpha-2 country code.
ConfigurationValue param.Field[string] `query:"configuration.value"`
// When set to `all`, all the search requirements must match. When set to `any`,
// only one of the search requirements has to match.
Match param.Field[AccessRuleListParamsFiltersMatch] `query:"match"`
// The action to apply to a matched request.
Mode param.Field[AccessRuleListParamsFiltersMode] `query:"mode"`
// The string to search for in the notes of existing IP Access rules. Notes: For
// example, the string 'attack' would match IP Access rules with notes 'Attack
// 26/02' and 'Attack 27/02'. The search is case insensitive.
Notes param.Field[string] `query:"notes"`
}
// URLQuery serializes [AccessRuleListParamsFilters]'s query parameters as
// `url.Values`.
func (r AccessRuleListParamsFilters) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}
// The target to search in existing rules.
type AccessRuleListParamsFiltersConfigurationTarget string
const (
AccessRuleListParamsFiltersConfigurationTargetIP AccessRuleListParamsFiltersConfigurationTarget = "ip"
AccessRuleListParamsFiltersConfigurationTargetIPRange AccessRuleListParamsFiltersConfigurationTarget = "ip_range"
AccessRuleListParamsFiltersConfigurationTargetASN AccessRuleListParamsFiltersConfigurationTarget = "asn"
AccessRuleListParamsFiltersConfigurationTargetCountry AccessRuleListParamsFiltersConfigurationTarget = "country"
)
func (r AccessRuleListParamsFiltersConfigurationTarget) IsKnown() bool {
switch r {
case AccessRuleListParamsFiltersConfigurationTargetIP, AccessRuleListParamsFiltersConfigurationTargetIPRange, AccessRuleListParamsFiltersConfigurationTargetASN, AccessRuleListParamsFiltersConfigurationTargetCountry:
return true
}
return false
}
// When set to `all`, all the search requirements must match. When set to `any`,
// only one of the search requirements has to match.
type AccessRuleListParamsFiltersMatch string
const (
AccessRuleListParamsFiltersMatchAny AccessRuleListParamsFiltersMatch = "any"
AccessRuleListParamsFiltersMatchAll AccessRuleListParamsFiltersMatch = "all"
)
func (r AccessRuleListParamsFiltersMatch) IsKnown() bool {
switch r {
case AccessRuleListParamsFiltersMatchAny, AccessRuleListParamsFiltersMatchAll:
return true
}
return false
}
// The action to apply to a matched request.
type AccessRuleListParamsFiltersMode string
const (
AccessRuleListParamsFiltersModeBlock AccessRuleListParamsFiltersMode = "block"
AccessRuleListParamsFiltersModeChallenge AccessRuleListParamsFiltersMode = "challenge"
AccessRuleListParamsFiltersModeWhitelist AccessRuleListParamsFiltersMode = "whitelist"
AccessRuleListParamsFiltersModeJsChallenge AccessRuleListParamsFiltersMode = "js_challenge"
AccessRuleListParamsFiltersModeManagedChallenge AccessRuleListParamsFiltersMode = "managed_challenge"
)
func (r AccessRuleListParamsFiltersMode) IsKnown() bool {
switch r {
case AccessRuleListParamsFiltersModeBlock, AccessRuleListParamsFiltersModeChallenge, AccessRuleListParamsFiltersModeWhitelist, AccessRuleListParamsFiltersModeJsChallenge, AccessRuleListParamsFiltersModeManagedChallenge:
return true
}
return false
}
// The field used to sort returned rules.
type AccessRuleListParamsOrder string
const (
AccessRuleListParamsOrderConfigurationTarget AccessRuleListParamsOrder = "configuration.target"
AccessRuleListParamsOrderConfigurationValue AccessRuleListParamsOrder = "configuration.value"
AccessRuleListParamsOrderMode AccessRuleListParamsOrder = "mode"
)
func (r AccessRuleListParamsOrder) IsKnown() bool {
switch r {
case AccessRuleListParamsOrderConfigurationTarget, AccessRuleListParamsOrderConfigurationValue, AccessRuleListParamsOrderMode:
return true
}
return false
}
type AccessRuleDeleteParams struct {
// The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.
AccountID param.Field[string] `path:"account_id"`
// The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.
ZoneID param.Field[string] `path:"zone_id"`
}
type AccessRuleDeleteResponseEnvelope struct {
Errors []AccessRuleDeleteResponseEnvelopeErrors `json:"errors,required"`
Messages []AccessRuleDeleteResponseEnvelopeMessages `json:"messages,required"`
Result AccessRuleDeleteResponse `json:"result,required,nullable"`
// Whether the API call was successful
Success AccessRuleDeleteResponseEnvelopeSuccess `json:"success,required"`
JSON accessRuleDeleteResponseEnvelopeJSON `json:"-"`
}
// accessRuleDeleteResponseEnvelopeJSON contains the JSON metadata for the struct
// [AccessRuleDeleteResponseEnvelope]
type accessRuleDeleteResponseEnvelopeJSON struct {
Errors apijson.Field
Messages apijson.Field
Result apijson.Field
Success apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccessRuleDeleteResponseEnvelope) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accessRuleDeleteResponseEnvelopeJSON) RawJSON() string {
return r.raw
}
type AccessRuleDeleteResponseEnvelopeErrors struct {
Code int64 `json:"code,required"`
Message string `json:"message,required"`
JSON accessRuleDeleteResponseEnvelopeErrorsJSON `json:"-"`
}
// accessRuleDeleteResponseEnvelopeErrorsJSON contains the JSON metadata for the
// struct [AccessRuleDeleteResponseEnvelopeErrors]
type accessRuleDeleteResponseEnvelopeErrorsJSON struct {
Code apijson.Field
Message apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccessRuleDeleteResponseEnvelopeErrors) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accessRuleDeleteResponseEnvelopeErrorsJSON) RawJSON() string {
return r.raw
}
type AccessRuleDeleteResponseEnvelopeMessages struct {
Code int64 `json:"code,required"`
Message string `json:"message,required"`
JSON accessRuleDeleteResponseEnvelopeMessagesJSON `json:"-"`
}
// accessRuleDeleteResponseEnvelopeMessagesJSON contains the JSON metadata for the
// struct [AccessRuleDeleteResponseEnvelopeMessages]
type accessRuleDeleteResponseEnvelopeMessagesJSON struct {
Code apijson.Field
Message apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AccessRuleDeleteResponseEnvelopeMessages) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r accessRuleDeleteResponseEnvelopeMessagesJSON) RawJSON() string {
return r.raw
}
// Whether the API call was successful
type AccessRuleDeleteResponseEnvelopeSuccess bool
const (
AccessRuleDeleteResponseEnvelopeSuccessTrue AccessRuleDeleteResponseEnvelopeSuccess = true
)
func (r AccessRuleDeleteResponseEnvelopeSuccess) IsKnown() bool {
switch r {
case AccessRuleDeleteResponseEnvelopeSuccessTrue:
return true
}
return false
}
type AccessRuleEditParams struct {
// The rule configuration.
Configuration param.Field[AccessRuleEditParamsConfiguration] `json:"configuration,required"`
// The action to apply to a matched request.
Mode param.Field[AccessRuleEditParamsMode] `json:"mode,required"`
// The Account ID to use for this endpoint. Mutually exclusive with the Zone ID.
AccountID param.Field[string] `path:"account_id"`
// The Zone ID to use for this endpoint. Mutually exclusive with the Account ID.
ZoneID param.Field[string] `path:"zone_id"`
// An informative summary of the rule, typically used as a reminder or explanation.
Notes param.Field[string] `json:"notes"`
}
func (r AccessRuleEditParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// The rule configuration.
//
// Satisfied by
// [firewall.AccessRuleEditParamsConfigurationLegacyJhsIPConfiguration],
// [firewall.AccessRuleEditParamsConfigurationLegacyJhsIPV6Configuration],
// [firewall.AccessRuleEditParamsConfigurationLegacyJhsCIDRConfiguration],
// [firewall.AccessRuleEditParamsConfigurationLegacyJhsASNConfiguration],
// [firewall.AccessRuleEditParamsConfigurationLegacyJhsCountryConfiguration].
type AccessRuleEditParamsConfiguration interface {
implementsFirewallAccessRuleEditParamsConfiguration()
}
type AccessRuleEditParamsConfigurationLegacyJhsIPConfiguration struct {
// The configuration target. You must set the target to `ip` when specifying an IP
// address in the rule.
Target param.Field[AccessRuleEditParamsConfigurationLegacyJhsIPConfigurationTarget] `json:"target"`
// The IP address to match. This address will be compared to the IP address of
// incoming requests.
Value param.Field[string] `json:"value"`
}
func (r AccessRuleEditParamsConfigurationLegacyJhsIPConfiguration) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r AccessRuleEditParamsConfigurationLegacyJhsIPConfiguration) implementsFirewallAccessRuleEditParamsConfiguration() {
}
// The configuration target. You must set the target to `ip` when specifying an IP
// address in the rule.
type AccessRuleEditParamsConfigurationLegacyJhsIPConfigurationTarget string
const (
AccessRuleEditParamsConfigurationLegacyJhsIPConfigurationTargetIP AccessRuleEditParamsConfigurationLegacyJhsIPConfigurationTarget = "ip"
)
func (r AccessRuleEditParamsConfigurationLegacyJhsIPConfigurationTarget) IsKnown() bool {
switch r {
case AccessRuleEditParamsConfigurationLegacyJhsIPConfigurationTargetIP:
return true
}
return false
}
type AccessRuleEditParamsConfigurationLegacyJhsIPV6Configuration struct {
// The configuration target. You must set the target to `ip6` when specifying an
// IPv6 address in the rule.
Target param.Field[AccessRuleEditParamsConfigurationLegacyJhsIPV6ConfigurationTarget] `json:"target"`
// The IPv6 address to match.
Value param.Field[string] `json:"value"`
}
func (r AccessRuleEditParamsConfigurationLegacyJhsIPV6Configuration) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r AccessRuleEditParamsConfigurationLegacyJhsIPV6Configuration) implementsFirewallAccessRuleEditParamsConfiguration() {
}
// The configuration target. You must set the target to `ip6` when specifying an
// IPv6 address in the rule.
type AccessRuleEditParamsConfigurationLegacyJhsIPV6ConfigurationTarget string
const (
AccessRuleEditParamsConfigurationLegacyJhsIPV6ConfigurationTargetIp6 AccessRuleEditParamsConfigurationLegacyJhsIPV6ConfigurationTarget = "ip6"
)
func (r AccessRuleEditParamsConfigurationLegacyJhsIPV6ConfigurationTarget) IsKnown() bool {
switch r {
case AccessRuleEditParamsConfigurationLegacyJhsIPV6ConfigurationTargetIp6:
return true
}
return false
}
type AccessRuleEditParamsConfigurationLegacyJhsCIDRConfiguration struct {
// The configuration target. You must set the target to `ip_range` when specifying
// an IP address range in the rule.
Target param.Field[AccessRuleEditParamsConfigurationLegacyJhsCIDRConfigurationTarget] `json:"target"`
// The IP address range to match. You can only use prefix lengths `/16` and `/24`
// for IPv4 ranges, and prefix lengths `/32`, `/48`, and `/64` for IPv6 ranges.
Value param.Field[string] `json:"value"`
}
func (r AccessRuleEditParamsConfigurationLegacyJhsCIDRConfiguration) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r AccessRuleEditParamsConfigurationLegacyJhsCIDRConfiguration) implementsFirewallAccessRuleEditParamsConfiguration() {
}
// The configuration target. You must set the target to `ip_range` when specifying
// an IP address range in the rule.
type AccessRuleEditParamsConfigurationLegacyJhsCIDRConfigurationTarget string
const (
AccessRuleEditParamsConfigurationLegacyJhsCIDRConfigurationTargetIPRange AccessRuleEditParamsConfigurationLegacyJhsCIDRConfigurationTarget = "ip_range"
)
func (r AccessRuleEditParamsConfigurationLegacyJhsCIDRConfigurationTarget) IsKnown() bool {
switch r {
case AccessRuleEditParamsConfigurationLegacyJhsCIDRConfigurationTargetIPRange:
return true
}
return false
}
type AccessRuleEditParamsConfigurationLegacyJhsASNConfiguration struct {
// The configuration target. You must set the target to `asn` when specifying an
// Autonomous System Number (ASN) in the rule.
Target param.Field[AccessRuleEditParamsConfigurationLegacyJhsASNConfigurationTarget] `json:"target"`
// The AS number to match.
Value param.Field[string] `json:"value"`
}
func (r AccessRuleEditParamsConfigurationLegacyJhsASNConfiguration) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r AccessRuleEditParamsConfigurationLegacyJhsASNConfiguration) implementsFirewallAccessRuleEditParamsConfiguration() {
}
// The configuration target. You must set the target to `asn` when specifying an
// Autonomous System Number (ASN) in the rule.
type AccessRuleEditParamsConfigurationLegacyJhsASNConfigurationTarget string
const (
AccessRuleEditParamsConfigurationLegacyJhsASNConfigurationTargetASN AccessRuleEditParamsConfigurationLegacyJhsASNConfigurationTarget = "asn"
)
func (r AccessRuleEditParamsConfigurationLegacyJhsASNConfigurationTarget) IsKnown() bool {
switch r {
case AccessRuleEditParamsConfigurationLegacyJhsASNConfigurationTargetASN:
return true
}
return false
}
type AccessRuleEditParamsConfigurationLegacyJhsCountryConfiguration struct {
// The configuration target. You must set the target to `country` when specifying a
// country code in the rule.
Target param.Field[AccessRuleEditParamsConfigurationLegacyJhsCountryConfigurationTarget] `json:"target"`
// The two-letter ISO-3166-1 alpha-2 code to match. For more information, refer to
// [IP Access rules: Parameters](https://developers.cloudflare.com/waf/tools/ip-access-rules/parameters/#country).
Value param.Field[string] `json:"value"`
}
func (r AccessRuleEditParamsConfigurationLegacyJhsCountryConfiguration) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r AccessRuleEditParamsConfigurationLegacyJhsCountryConfiguration) implementsFirewallAccessRuleEditParamsConfiguration() {
}
// The configuration target. You must set the target to `country` when specifying a
// country code in the rule.
type AccessRuleEditParamsConfigurationLegacyJhsCountryConfigurationTarget string
const (
AccessRuleEditParamsConfigurationLegacyJhsCountryConfigurationTargetCountry AccessRuleEditParamsConfigurationLegacyJhsCountryConfigurationTarget = "country"
)
func (r AccessRuleEditParamsConfigurationLegacyJhsCountryConfigurationTarget) IsKnown() bool {
switch r {
case AccessRuleEditParamsConfigurationLegacyJhsCountryConfigurationTargetCountry:
return true
}
return false
}
// The action to apply to a matched request.
type AccessRuleEditParamsMode string
const (
AccessRuleEditParamsModeBlock AccessRuleEditParamsMode = "block"
AccessRuleEditParamsModeChallenge AccessRuleEditParamsMode = "challenge"
AccessRuleEditParamsModeWhitelist AccessRuleEditParamsMode = "whitelist"
AccessRuleEditParamsModeJsChallenge AccessRuleEditParamsMode = "js_challenge"