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

     1  package preciseprotection_rules
     2  
     3  import (
     4  	golangsdk "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  	ToPreciseCreateMap() (map[string]interface{}, error)
    12  }
    13  
    14  // CreateOpts contains all the values needed to create a new precise protection rule.
    15  type CreateOpts struct {
    16  	Name       string      `json:"name" required:"true"`
    17  	Time       bool        `json:"time"`
    18  	Start      int64       `json:"start,omitempty"`
    19  	End        int64       `json:"end,omitempty"`
    20  	Conditions []Condition `json:"conditions" required:"true"`
    21  	Action     Action      `json:"action" required:"true"`
    22  	Priority   *int        `json:"priority,omitempty"`
    23  }
    24  
    25  type Condition struct {
    26  	Category string   `json:"category" required:"true"`
    27  	Index    string   `json:"index,omitempty"`
    28  	Logic    string   `json:"logic" required:"true"`
    29  	Contents []string `json:"contents" required:"true"`
    30  }
    31  
    32  type Action struct {
    33  	Category string `json:"category" required:"true"`
    34  }
    35  
    36  // ToPreciseCreateMap builds a create request body from CreateOpts.
    37  func (opts CreateOpts) ToPreciseCreateMap() (map[string]interface{}, error) {
    38  	return golangsdk.BuildRequestBody(opts, "")
    39  }
    40  
    41  // Create will create a new precise protection rule based on the values in CreateOpts.
    42  func Create(c *golangsdk.ServiceClient, policyID string, opts CreateOptsBuilder) (r CreateResult) {
    43  	b, err := opts.ToPreciseCreateMap()
    44  	if err != nil {
    45  		r.Err = err
    46  		return
    47  	}
    48  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
    49  	_, r.Err = c.Post(rootURL(c, policyID), b, &r.Body, reqOpt)
    50  	return
    51  }
    52  
    53  // Update will update a precise protection rule based on the values in CreateOpts.
    54  // The response code from api is 200
    55  func Update(c *golangsdk.ServiceClient, policyID, ruleID string, opts CreateOptsBuilder) (r UpdateResult) {
    56  	b, err := opts.ToPreciseCreateMap()
    57  	if err != nil {
    58  		r.Err = err
    59  		return
    60  	}
    61  	reqOpt := &golangsdk.RequestOpts{
    62  		OkCodes:     []int{200},
    63  		MoreHeaders: openstack.StdRequestOpts().MoreHeaders,
    64  	}
    65  	_, r.Err = c.Put(resourceURL(c, policyID, ruleID), b, &r.Body, reqOpt)
    66  	return
    67  }
    68  
    69  // Get retrieves a particular precise rule based on its unique ID.
    70  func Get(c *golangsdk.ServiceClient, policyID, ruleID string) (r GetResult) {
    71  	_, r.Err = c.Get(resourceURL(c, policyID, ruleID), &r.Body, openstack.StdRequestOpts())
    72  	return
    73  }
    74  
    75  // Delete will permanently delete a particular precise rule based on its unique ID.
    76  func Delete(c *golangsdk.ServiceClient, policyID, ruleID string) (r DeleteResult) {
    77  	_, r.Err = c.Delete(resourceURL(c, policyID, ruleID), openstack.StdRequestOpts())
    78  	return
    79  }