github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf/v1/policies/requests.go (about) 1 package policies 2 3 import ( 4 "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/openstack" 6 ) 7 8 // CreateOptsBuilder allows extensions to add additional parameters to the 9 // Create request. 10 type CreateOptsBuilder interface { 11 ToPolicyCreateMap() (map[string]interface{}, error) 12 } 13 14 // CreateOpts contains all the values needed to create a new policy. 15 type CreateOpts struct { 16 // Policy name 17 Name string `json:"name" required:"true"` 18 } 19 20 // ToPolicyCreateMap builds a create request body from CreateOpts. 21 func (opts CreateOpts) ToPolicyCreateMap() (map[string]interface{}, error) { 22 return golangsdk.BuildRequestBody(opts, "") 23 } 24 25 // Create will create a new policy based on the values in CreateOpts. 26 func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 27 b, err := opts.ToPolicyCreateMap() 28 if err != nil { 29 r.Err = err 30 return 31 } 32 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 33 _, r.Err = c.Post(rootURL(c), b, &r.Body, reqOpt) 34 return 35 } 36 37 // UpdateOptsBuilder allows extensions to add additional parameters to the 38 // Update request. 39 type UpdateOptsBuilder interface { 40 ToPolicyUpdateMap() (map[string]interface{}, error) 41 } 42 43 // UpdateOpts contains all the values needed to update a policy. 44 type UpdateOpts struct { 45 // Policy name 46 Name string `json:"name,omitempty"` 47 // Protective Action 48 Action *Action `json:"action,omitempty"` 49 // Protection Switches 50 Options *Options `json:"options,omitempty"` 51 // Protection Level 52 Level int `json:"level,omitempty"` 53 // Detection Mode 54 FullDetection *bool `json:"full_detection,omitempty"` 55 } 56 57 // ToPolicyUpdateMap builds a update request body from UpdateOpts. 58 func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) { 59 return golangsdk.BuildRequestBody(opts, "") 60 } 61 62 // Update accepts a UpdateOpts struct and uses the values to update a policy.The response code from api is 200 63 func Update(c *golangsdk.ServiceClient, policyID string, opts UpdateOptsBuilder) (r UpdateResult) { 64 b, err := opts.ToPolicyUpdateMap() 65 if err != nil { 66 r.Err = err 67 return 68 } 69 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 70 _, r.Err = c.Put(resourceURL(c, policyID), b, nil, reqOpt) 71 return 72 } 73 74 // UpdateHostsOptsBuilder allows extensions to add additional parameters to the 75 // Update request. 76 type UpdateHostsOptsBuilder interface { 77 ToPolicyHostsUpdateMap() (map[string]interface{}, error) 78 } 79 80 // UpdateHostsOpts contains all the values needed to update a policy hosts. 81 type UpdateHostsOpts struct { 82 // Domain IDs 83 Hosts []string `json:"hosts" required:"true"` 84 } 85 86 // ToPolicyHostsUpdateMap builds a update request body from UpdateHostsOpts. 87 func (opts UpdateHostsOpts) ToPolicyHostsUpdateMap() (map[string]interface{}, error) { 88 return golangsdk.BuildRequestBody(opts, "") 89 } 90 91 // Update accepts a UpdateHostsOpts struct and uses the values to update a policy hosts.The response code from api is 200 92 func UpdateHosts(c *golangsdk.ServiceClient, policyID string, opts UpdateHostsOptsBuilder) (r UpdateResult) { 93 b, err := opts.ToPolicyHostsUpdateMap() 94 if err != nil { 95 r.Err = err 96 return 97 } 98 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 99 _, r.Err = c.Put(hostsURL(c, policyID), b, nil, reqOpt) 100 return 101 } 102 103 // Get retrieves a particular policy based on its unique ID. 104 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 105 _, r.Err = c.Get(resourceURL(c, id), &r.Body, openstack.StdRequestOpts()) 106 return 107 } 108 109 // Delete will permanently delete a particular policy based on its unique ID. 110 func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) { 111 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{204}, 112 MoreHeaders: openstack.StdRequestOpts().MoreHeaders} 113 _, r.Err = c.Delete(resourceURL(c, id), reqOpt) 114 return 115 }