github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/waf/v1/ccattackprotection_rules/requests.go (about) 1 package ccattackprotection_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 ToCcAttackCreateMap() (map[string]interface{}, error) 15 } 16 17 // CreateOpts contains all the values needed to create a new cc attack protection rule. 18 type CreateOpts struct { 19 Url string `json:"path" required:"true"` 20 LimitNum *int `json:"limit_num" required:"true"` 21 LimitPeriod *int `json:"limit_period" required:"true"` 22 LockTime *int `json:"lock_time,omitempty"` 23 TagType string `json:"tag_type" required:"true"` 24 TagIndex string `json:"tag_index,omitempty"` 25 TagCondition *TagCondition `json:"tag_condition,omitempty"` 26 Action Action `json:"action" required:"true"` 27 } 28 29 type TagCondition struct { 30 Category string `json:"category" required:"true"` 31 Contents []string `json:"contents" required:"true"` 32 } 33 34 type Action struct { 35 Category string `json:"category" required:"true"` 36 Detail *Detail `json:"detail,omitempty"` 37 } 38 39 type Detail struct { 40 Response Response `json:"response" required:"true"` 41 } 42 43 type Response struct { 44 ContentType string `json:"content_type" required:"true"` 45 Content string `json:"content" required:"true"` 46 } 47 48 // ToCcAttackCreateMap builds a create request body from CreateOpts. 49 func (opts CreateOpts) ToCcAttackCreateMap() (map[string]interface{}, error) { 50 return golangsdk.BuildRequestBody(opts, "") 51 } 52 53 // Create will create a new cc attack protection rule based on the values in CreateOpts. 54 func Create(c *golangsdk.ServiceClient, policyID string, opts CreateOptsBuilder) (r CreateResult) { 55 b, err := opts.ToCcAttackCreateMap() 56 if err != nil { 57 r.Err = err 58 return 59 } 60 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 61 _, r.Err = c.Post(rootURL(c, policyID), b, &r.Body, reqOpt) 62 return 63 } 64 65 // Update will update a new cc attack protection rule based on the values in CreateOpts. 66 // The response code from api is 200 67 func Update(c *golangsdk.ServiceClient, policyID, ruleID string, opts CreateOptsBuilder) (r UpdateResult) { 68 b, err := opts.ToCcAttackCreateMap() 69 if err != nil { 70 r.Err = err 71 return 72 } 73 reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}} 74 _, r.Err = c.Put(resourceURL(c, policyID, ruleID), b, &r.Body, reqOpt) 75 return 76 } 77 78 // Get retrieves a particular cc attack rule based on its unique ID. 79 func Get(c *golangsdk.ServiceClient, policyID, ruleID string) (r GetResult) { 80 reqOpt := &golangsdk.RequestOpts{ 81 MoreHeaders: RequestOpts.MoreHeaders, 82 } 83 84 _, r.Err = c.Get(resourceURL(c, policyID, ruleID), &r.Body, reqOpt) 85 return 86 } 87 88 // Delete will permanently delete a particular cc attack rule based on its unique ID. 89 func Delete(c *golangsdk.ServiceClient, policyID, ruleID string) (r DeleteResult) { 90 reqOpt := &golangsdk.RequestOpts{ 91 MoreHeaders: RequestOpts.MoreHeaders, 92 } 93 94 _, r.Err = c.Delete(resourceURL(c, policyID, ruleID), reqOpt) 95 return 96 }