forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lockdown_example_test.go
64 lines (54 loc) · 1.24 KB
/
lockdown_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
package cloudflare_test
import (
"fmt"
"log"
"strings"
cloudflare "github.com/cloudflare/cloudflare-go"
)
func ExampleAPI_ListZoneLockdowns_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 Zone Lockdown rules for a zone, by page.
rules, err := api.ListZoneLockdowns(zoneID, 1)
if err != nil {
log.Fatal(err)
}
for _, r := range rules.Result {
fmt.Printf("%s: %s\n", strings.Join(r.URLs, ", "), r.Configurations)
}
}
func ExampleAPI_CreateZoneLockdown() {
api, err := cloudflare.New("deadbeef", "[email protected]")
if err != nil {
log.Fatal(err)
}
zoneID, err := api.ZoneIDByName("example.org")
if err != nil {
log.Fatal(err)
}
newZoneLockdown := cloudflare.ZoneLockdown{
Description: "Test Zone Lockdown Rule",
URLs: []string{
"*.example.org/test",
},
Configurations: []cloudflare.ZoneLockdownConfig{
cloudflare.ZoneLockdownConfig{
Target: "ip",
Value: "127.0.0.1",
},
},
Paused: false,
Priority: 1,
}
response, err := api.CreateZoneLockdown(zoneID, newZoneLockdown)
if err != nil {
log.Fatal(err)
}
fmt.Println("Response: ", response)
}