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