forked from dilutedev/doppler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrustedips.go
More file actions
90 lines (79 loc) · 1.57 KB
/
Copy pathtrustedips.go
File metadata and controls
90 lines (79 loc) · 1.57 KB
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
package doppler
import (
"encoding/json"
"net/http"
"strings"
)
type IPs struct {
IPs []string `json:"ips"`
Success bool `json:"success"`
}
type IP struct {
IP string `json:"ip"`
}
/*
List trusted IPs
*/
func (dp *doppler) ListTrustedIPs(project, config string) (*IPs, error) {
request, err := http.NewRequest(
http.MethodGet,
"/v3/configs/config/trusted_ips?project="+project+"&config="+config,
nil,
)
if err != nil {
return nil, err
}
body, err := dp.makeApiRequest(request)
if err != nil {
return nil, err
}
data := &IPs{}
err = json.Unmarshal(body, data)
if err != nil {
return nil, err
}
return data, nil
}
/*
Add a trusted IP
*/
func (dp *doppler) AddIP(project, config, ip string) (*IP, error) {
payload := strings.NewReader("{\"ip\":\"" + ip + "\"}")
request, err := http.NewRequest(
http.MethodPost,
"/v3/configs/config/trusted_ips?project="+project+"&config="+config,
payload,
)
if err != nil {
return nil, err
}
body, err := dp.makeApiRequest(request)
if err != nil {
return nil, err
}
data := &IP{}
err = json.Unmarshal(body, data)
if err != nil {
return nil, err
}
return data, nil
}
/*
Delete a trusted IP
*/
func (dp *doppler) DeleteIP(project, config, ip string) (string, error) {
payload := strings.NewReader("{\"ip\":\"" + ip + "\"}")
request, err := http.NewRequest(
http.MethodDelete,
"/v3/configs/config/trusted_ips?project="+project+"&config="+config,
payload,
)
if err != nil {
return "", err
}
body, err := dp.makeApiRequest(request)
if err != nil {
return "", err
}
return string(body), nil
}