github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/lbaas_v2/whitelists/requests.go (about) 1 package whitelists 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 ) 6 7 // CreateOptsBuilder is the interface options structs have to satisfy in order 8 // to be used in the main Create operation in this package. Since many 9 // extensions decorate or modify the common logic, it is useful for them to 10 // satisfy a basic interface in order for them to be used. 11 type CreateOptsBuilder interface { 12 ToWhitelistCreateMap() (map[string]interface{}, error) 13 } 14 15 // CreateOpts is the common options struct used in this package's Create 16 // operation. 17 type CreateOpts struct { 18 TenantId string `json:"tenant_id,omitempty"` 19 ListenerId string `json:"listener_id" required:"true"` 20 EnableWhitelist *bool `json:"enable_whitelist,omitempty"` 21 Whitelist string `json:"whitelist,omitempty"` 22 } 23 24 // ToWhitelistCreateMap casts a CreateOpts struct to a map. 25 func (opts CreateOpts) ToWhitelistCreateMap() (map[string]interface{}, error) { 26 return golangsdk.BuildRequestBody(opts, "whitelist") 27 } 28 29 // Create is an operation which provisions a new whitelist based on the 30 // configuration defined in the CreateOpts struct. Once the request is 31 // validated and progress has started on the provisioning process, a 32 // CreateResult will be returned. 33 // 34 // Users with an admin role can create loadbalancers on behalf of other tenants by 35 // specifying a TenantID attribute different than their own. 36 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 37 b, err := opts.ToWhitelistCreateMap() 38 if err != nil { 39 r.Err = err 40 return 41 } 42 _, r.Err = c.Post(rootURL(c), b, &r.Body, nil) 43 return 44 } 45 46 // Get retrieves a particular Whitelist based on its unique ID. 47 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 48 _, r.Err = c.Get(resourceURL(c, id), &r.Body, nil) 49 return 50 } 51 52 // UpdateOptsBuilder is the interface options structs have to satisfy in order 53 // to be used in the main Update operation in this package. Since many 54 // extensions decorate or modify the common logic, it is useful for them to 55 // satisfy a basic interface in order for them to be used. 56 type UpdateOptsBuilder interface { 57 ToWhitelistUpdateMap() (map[string]interface{}, error) 58 } 59 60 // UpdateOpts is the common options struct used in this package's Update 61 // operation. 62 type UpdateOpts struct { 63 EnableWhitelist *bool `json:"enable_whitelist,omitempty"` 64 Whitelist string `json:"whitelist,omitempty"` 65 } 66 67 // ToWhitelistUpdateMap casts a UpdateOpts struct to a map. 68 func (opts UpdateOpts) ToWhitelistUpdateMap() (map[string]interface{}, error) { 69 return golangsdk.BuildRequestBody(opts, "whitelist") 70 } 71 72 // Update is an operation which modifies the attributes of the specified Whitelist. 73 func Update(c *golangsdk.ServiceClient, id string, opts UpdateOpts) (r UpdateResult) { 74 b, err := opts.ToWhitelistUpdateMap() 75 if err != nil { 76 r.Err = err 77 return 78 } 79 _, r.Err = c.Put(resourceURL(c, id), b, &r.Body, &golangsdk.RequestOpts{ 80 OkCodes: []int{200}, 81 }) 82 return 83 } 84 85 // Delete will permanently delete a particular Whitelist based on its unique ID. 86 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 87 _, r.Err = c.Delete(resourceURL(c, id), nil) 88 return 89 }