This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
requests.go
52 lines (44 loc) · 1.58 KB
/
requests.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
package whitelists
import (
"github.com/huaweicloud/golangsdk"
)
// WhitelistOptsBuilder is used for creating, updating, deleting instance whitelists parameters.
// any struct providing the parameters should implement this interface
type WhitelistOptsBuilder interface {
ToInstanceWhitelistMap() (map[string]interface{}, error)
}
// WhitelistGroupOpts is a struct that contains all the whitelist parameters.
type WhitelistGroupOpts struct {
// the group name
GroupName string `json:"group_name" required:"true"`
// list of IP address or range
IPList []string `json:"ip_list" required:"true"`
}
// WhitelistOpts is a struct that contains all the parameters.
type WhitelistOpts struct {
// enable or disable the whitelists
Enable *bool `json:"enable_whitelist" required:"true"`
// list of whitelist groups
Groups []WhitelistGroupOpts `json:"whitelist" required:"true"`
}
// ToInstanceWhitelistMap is used for type convert
func (ops WhitelistOpts) ToInstanceWhitelistMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(ops, "")
}
// Put an instance whitelist with given parameters.
func Put(client *golangsdk.ServiceClient, id string, ops WhitelistOptsBuilder) (r PutResult) {
b, err := ops.ToInstanceWhitelistMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Put(resourceURL(client, id), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{204},
})
return
}
// Get the instance whitelist groups by instance id
func Get(client *golangsdk.ServiceClient, id string) (r WhitelistResult) {
_, r.Err = client.Get(resourceURL(client, id), &r.Body, nil)
return
}