github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf/v1/datamasking_rules/requests.go (about) 1 package datamasking_rules 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 ToDataMaskingCreateMap() (map[string]interface{}, error) 12 } 13 14 // CreateOpts contains all the values needed to create a new datamasking rule. 15 type CreateOpts struct { 16 Path string `json:"path" required:"true"` 17 Category string `json:"category" required:"true"` 18 Index string `json:"index" required:"true"` 19 } 20 21 // ToDataMaskingCreateMap builds a create request body from CreateOpts. 22 func (opts CreateOpts) ToDataMaskingCreateMap() (map[string]interface{}, error) { 23 return golangsdk.BuildRequestBody(opts, "") 24 } 25 26 // Create will create a new datamasking rule based on the values in CreateOpts. 27 func Create(c *golangsdk.ServiceClient, policyID string, opts CreateOptsBuilder) (r CreateResult) { 28 b, err := opts.ToDataMaskingCreateMap() 29 if err != nil { 30 r.Err = err 31 return 32 } 33 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 34 _, r.Err = c.Post(rootURL(c, policyID), b, &r.Body, reqOpt) 35 return 36 } 37 38 // UpdateOptsBuilder allows extensions to add additional parameters to the 39 // Update request. 40 type UpdateOptsBuilder interface { 41 ToDataMaskingUpdateMap() (map[string]interface{}, error) 42 } 43 44 // UpdateOpts contains all the values needed to update a datamasking rule. 45 type UpdateOpts struct { 46 Path string `json:"path" required:"true"` 47 Category string `json:"category" required:"true"` 48 Index string `json:"index" required:"true"` 49 } 50 51 // ToDataMaskingUpdateMap builds a update request body from UpdateOpts. 52 func (opts UpdateOpts) ToDataMaskingUpdateMap() (map[string]interface{}, error) { 53 return golangsdk.BuildRequestBody(opts, "") 54 } 55 56 // Update accepts a UpdateOpts struct and uses the values to update a rule.The response code from api is 200 57 func Update(c *golangsdk.ServiceClient, policyID, ruleID string, opts UpdateOptsBuilder) (r UpdateResult) { 58 b, err := opts.ToDataMaskingUpdateMap() 59 if err != nil { 60 r.Err = err 61 return 62 } 63 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 64 _, r.Err = c.Put(resourceURL(c, policyID, ruleID), b, nil, reqOpt) 65 return 66 } 67 68 // Get retrieves a particular datamasking rule based on its unique ID. 69 func Get(c *golangsdk.ServiceClient, policyID, ruleID string) (r GetResult) { 70 _, r.Err = c.Get(resourceURL(c, policyID, ruleID), &r.Body, openstack.StdRequestOpts()) 71 return 72 } 73 74 // Delete will permanently delete a particular datamasking rule based on its unique ID. 75 func Delete(c *golangsdk.ServiceClient, policyID, ruleID string) (r DeleteResult) { 76 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{204}, 77 MoreHeaders: openstack.StdRequestOpts().MoreHeaders} 78 _, r.Err = c.Delete(resourceURL(c, policyID, ruleID), reqOpt) 79 return 80 }