github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/waf/v1/webtamperprotection_rules/requests.go (about) 1 package webtamperprotection_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 ToWebTamperCreateMap() (map[string]interface{}, error) 15 } 16 17 // CreateOpts contains all the values needed to create a new web tamper protection rule. 18 type CreateOpts struct { 19 Hostname string `json:"hostname" required:"true"` 20 Url string `json:"path" required:"true"` 21 } 22 23 // ToWebTamperCreateMap builds a create request body from CreateOpts. 24 func (opts CreateOpts) ToWebTamperCreateMap() (map[string]interface{}, error) { 25 return golangsdk.BuildRequestBody(opts, "") 26 } 27 28 // Create will create a new web tamper protection rule based on the values in CreateOpts. 29 func Create(c *golangsdk.ServiceClient, policyID string, opts CreateOptsBuilder) (r CreateResult) { 30 b, err := opts.ToWebTamperCreateMap() 31 if err != nil { 32 r.Err = err 33 return 34 } 35 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 36 _, r.Err = c.Post(rootURL(c, policyID), b, &r.Body, reqOpt) 37 return 38 } 39 40 // Get retrieves a particular web tamper protection rule based on its unique ID. 41 func Get(c *golangsdk.ServiceClient, policyID, ruleID string) (r GetResult) { 42 reqOpt := &golangsdk.RequestOpts{ 43 MoreHeaders: RequestOpts.MoreHeaders, 44 } 45 46 _, r.Err = c.Get(resourceURL(c, policyID, ruleID), &r.Body, reqOpt) 47 return 48 } 49 50 // Delete will permanently delete a particular web tamper protection rule based on its unique ID. 51 func Delete(c *golangsdk.ServiceClient, policyID, ruleID string) (r DeleteResult) { 52 reqOpt := &golangsdk.RequestOpts{ 53 MoreHeaders: RequestOpts.MoreHeaders, 54 } 55 56 _, r.Err = c.Delete(resourceURL(c, policyID, ruleID), reqOpt) 57 return 58 }