github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf/v1/ccattackprotection_rules/requests.go (about)

     1  package ccattackprotection_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  	ToCcAttackCreateMap() (map[string]interface{}, error)
    12  }
    13  
    14  // CreateOpts contains all the values needed to create a new cc attack protection rule.
    15  type CreateOpts struct {
    16  	Path         string       `json:"path" required:"true"`
    17  	LimitNum     *int         `json:"limit_num" required:"true"`
    18  	LimitPeriod  *int         `json:"limit_period" required:"true"`
    19  	LockTime     *int         `json:"lock_time,omitempty"`
    20  	TagType      string       `json:"tag_type" required:"true"`
    21  	TagIndex     string       `json:"tag_index,omitempty"`
    22  	TagCondition TagCondition `json:"tag_condition,omitempty"`
    23  	Action       Action       `json:"action" required:"true"`
    24  }
    25  
    26  type TagCondition struct {
    27  	Category string   `json:"category" required:"true"`
    28  	Contents []string `json:"contents" required:"true"`
    29  }
    30  
    31  type Action struct {
    32  	Category string `json:"category" required:"true"`
    33  	Detail   Detail `json:"detail,omitempty"`
    34  }
    35  
    36  type Detail struct {
    37  	Response Response `json:"response" required:"true"`
    38  }
    39  
    40  type Response struct {
    41  	ContentType string `json:"content_type" required:"true"`
    42  	Content     string `json:"content" required:"true"`
    43  }
    44  
    45  // ToCcAttackCreateMap builds a create request body from CreateOpts.
    46  func (opts CreateOpts) ToCcAttackCreateMap() (map[string]interface{}, error) {
    47  	return golangsdk.BuildRequestBody(opts, "")
    48  }
    49  
    50  // Create will create a new cc attack protection rule based on the values in CreateOpts.
    51  func Create(c *golangsdk.ServiceClient, policyID string, opts CreateOptsBuilder) (r CreateResult) {
    52  	b, err := opts.ToCcAttackCreateMap()
    53  	if err != nil {
    54  		r.Err = err
    55  		return
    56  	}
    57  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
    58  	_, r.Err = c.Post(rootURL(c, policyID), b, &r.Body, reqOpt)
    59  	return
    60  }
    61  
    62  // Get retrieves a particular cc attack rule based on its unique ID.
    63  func Get(c *golangsdk.ServiceClient, policyID, ruleID string) (r GetResult) {
    64  	_, r.Err = c.Get(resourceURL(c, policyID, ruleID), &r.Body, openstack.StdRequestOpts())
    65  	return
    66  }
    67  
    68  // Delete will permanently delete a particular cc attack rule based on its unique ID.
    69  func Delete(c *golangsdk.ServiceClient, policyID, ruleID string) (r DeleteResult) {
    70  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{204},
    71  		MoreHeaders: openstack.StdRequestOpts().MoreHeaders}
    72  	_, r.Err = c.Delete(resourceURL(c, policyID, ruleID), reqOpt)
    73  	return
    74  }