github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/waf_hw/v1/webtamperprotection_rules/requests.go (about) 1 /* 2 Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 3 */ 4 5 package webtamperprotection_rules 6 7 import ( 8 "github.com/huaweicloud/golangsdk" 9 ) 10 11 var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{ 12 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 13 } 14 15 // CreateOptsBuilder allows extensions to add additional parameters to the 16 // Create request. 17 type CreateOptsBuilder interface { 18 ToWebTamperCreateMap() (map[string]interface{}, error) 19 } 20 21 // CreateOpts contains all the values needed to create a new web tamper protection rule. 22 type CreateOpts struct { 23 Hostname string `json:"hostname" required:"true"` 24 Url string `json:"url" required:"true"` 25 Description string `json:"description,omitempty"` 26 } 27 28 // ToWebTamperCreateMap builds a create request body from CreateOpts. 29 func (opts CreateOpts) ToWebTamperCreateMap() (map[string]interface{}, error) { 30 return golangsdk.BuildRequestBody(opts, "") 31 } 32 33 // Create will create a new web tamper protection rule based on the values in CreateOpts. 34 func Create(c *golangsdk.ServiceClient, policyID string, opts CreateOptsBuilder) (r CreateResult) { 35 b, err := opts.ToWebTamperCreateMap() 36 if err != nil { 37 r.Err = err 38 return 39 } 40 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 41 _, r.Err = c.Post(rootURL(c, policyID), b, &r.Body, reqOpt) 42 return 43 } 44 45 // Get retrieves a particular web tamper protection rule based on its unique ID. 46 func Get(c *golangsdk.ServiceClient, policyID, ruleID string) (r GetResult) { 47 reqOpt := &golangsdk.RequestOpts{ 48 MoreHeaders: RequestOpts.MoreHeaders, 49 } 50 51 _, r.Err = c.Get(resourceURL(c, policyID, ruleID), &r.Body, reqOpt) 52 return 53 } 54 55 // Delete will permanently delete a particular web tamper protection rule based on its unique ID. 56 func Delete(c *golangsdk.ServiceClient, policyID, ruleID string) (r DeleteResult) { 57 reqOpt := &golangsdk.RequestOpts{ 58 OkCodes: []int{200}, 59 MoreHeaders: RequestOpts.MoreHeaders, 60 } 61 62 _, r.Err = c.Delete(resourceURL(c, policyID, ruleID), reqOpt) 63 return 64 }