forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firewall_example_test.go
105 lines (87 loc) · 2.21 KB
/
firewall_example_test.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
package cloudflare_test
import (
"fmt"
"log"
cloudflare "github.com/cloudflare/cloudflare-go"
)
func ExampleAPI_ListZoneAccessRules_all() {
api, err := cloudflare.New("deadbeef", "[email protected]")
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName("example.com")
if err != nil {
log.Fatal(err)
}
// Fetch all access rules for a zone
response, err := api.ListZoneAccessRules(zoneID, cloudflare.AccessRule{}, 1)
if err != nil {
log.Fatal(err)
}
for _, r := range response.Result {
fmt.Printf("%s: %s\n", r.Configuration.Value, r.Mode)
}
}
func ExampleAPI_ListZoneAccessRules_filterByIP() {
api, err := cloudflare.New("deadbeef", "[email protected]")
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName("example.com")
if err != nil {
log.Fatal(err)
}
// Fetch only access rules whose target is 127.0.0.1
localhost := cloudflare.AccessRule{
Configuration: cloudflare.AccessRuleConfiguration{Target: "127.0.0.1"},
}
response, err := api.ListZoneAccessRules(zoneID, localhost, 1)
if err != nil {
log.Fatal(err)
}
for _, r := range response.Result {
fmt.Printf("%s: %s\n", r.Configuration.Value, r.Mode)
}
}
func ExampleAPI_ListZoneAccessRules_filterByMode() {
api, err := cloudflare.New("deadbeef", "[email protected]")
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName("example.com")
if err != nil {
log.Fatal(err)
}
// Fetch access rules with an action of "block"
foo := cloudflare.AccessRule{
Mode: "block",
}
response, err := api.ListZoneAccessRules(zoneID, foo, 1)
if err != nil {
log.Fatal(err)
}
for _, r := range response.Result {
fmt.Printf("%s: %s\n", r.Configuration.Value, r.Mode)
}
}
func ExampleAPI_ListZoneAccessRules_filterByNote() {
api, err := cloudflare.New("deadbeef", "[email protected]")
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName("example.com")
if err != nil {
log.Fatal(err)
}
// Fetch only access rules with notes containing "example"
foo := cloudflare.AccessRule{
Notes: "example",
}
response, err := api.ListZoneAccessRules(zoneID, foo, 1)
if err != nil {
log.Fatal(err)
}
for _, r := range response.Result {
fmt.Printf("%s: %s\n", r.Configuration.Value, r.Mode)
}
}