forked from akshaykarle/go-mongodbatlas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
whitelist.go
55 lines (48 loc) · 1.18 KB
/
whitelist.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
package main
import (
"fmt"
"log"
"net/http"
"os"
dac "github.com/akshaykarle/go-http-digest-auth-client"
ma "github.com/akshaykarle/go-mongodbatlas/mongodbatlas"
)
func main() {
username := os.Args[1]
password := os.Args[2]
gid := os.Args[3]
t := dac.NewTransport(username, password)
httpClient := &http.Client{Transport: &t}
client := ma.NewClient(httpClient)
// Whitelist.List example
whitelists, _, err := client.Whitelist.List(gid)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Whitelist list: %v\n", whitelists)
// Whitelist.Get example
whitelist, _, err := client.Whitelist.Get(gid, whitelists[0].CidrBlock)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Whitelist get: %v\n", whitelist)
// Whitelist.Create example
params := []ma.Whitelist{
ma.Whitelist{
Comment: "test",
GroupID: gid,
IPAddress: "179.154.224.127",
},
}
whitelists, _, err = client.Whitelist.Create(gid, params)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Whitelist created: %v\n", whitelists)
// Whitelist.Delete example
_, err = client.Whitelist.Delete(gid, whitelists[0].IPAddress)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Whitelist deleted: %v\n", whitelist)
}