github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/dcs/v2/whitelists/requests.go (about) 1 package whitelists 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 ) 6 7 // WhitelistOptsBuilder is used for creating, updating, deleting instance whitelists parameters. 8 // any struct providing the parameters should implement this interface 9 type WhitelistOptsBuilder interface { 10 ToInstanceWhitelistMap() (map[string]interface{}, error) 11 } 12 13 // WhitelistGroupOpts is a struct that contains all the whitelist parameters. 14 type WhitelistGroupOpts struct { 15 // the group name 16 GroupName string `json:"group_name" required:"true"` 17 // list of IP address or range 18 IPList []string `json:"ip_list" required:"true"` 19 } 20 21 // WhitelistOpts is a struct that contains all the parameters. 22 type WhitelistOpts struct { 23 // enable or disable the whitelists 24 Enable *bool `json:"enable_whitelist" required:"true"` 25 // list of whitelist groups 26 Groups []WhitelistGroupOpts `json:"whitelist" required:"true"` 27 } 28 29 // ToInstanceWhitelistMap is used for type convert 30 func (ops WhitelistOpts) ToInstanceWhitelistMap() (map[string]interface{}, error) { 31 return golangsdk.BuildRequestBody(ops, "") 32 } 33 34 // Put an instance whitelist with given parameters. 35 func Put(client *golangsdk.ServiceClient, id string, ops WhitelistOptsBuilder) (r PutResult) { 36 b, err := ops.ToInstanceWhitelistMap() 37 if err != nil { 38 r.Err = err 39 return 40 } 41 42 _, r.Err = client.Put(resourceURL(client, id), b, nil, &golangsdk.RequestOpts{ 43 OkCodes: []int{204}, 44 }) 45 return 46 } 47 48 // Get the instance whitelist groups by instance id 49 func Get(client *golangsdk.ServiceClient, id string) (r WhitelistResult) { 50 _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) 51 return 52 }