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

     1  package whiteblackip_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  	ToWhiteBlackIPCreateMap() (map[string]interface{}, error)
    12  }
    13  
    14  // CreateOpts contains all the values needed to create a new whiteblackip rule.
    15  type CreateOpts struct {
    16  	Addr  string `json:"addr" required:"true"`
    17  	White int    `json:"white,omitempty"`
    18  }
    19  
    20  // ToWhiteBlackIPCreateMap builds a create request body from CreateOpts.
    21  func (opts CreateOpts) ToWhiteBlackIPCreateMap() (map[string]interface{}, error) {
    22  	return golangsdk.BuildRequestBody(opts, "")
    23  }
    24  
    25  // Create will create a new whiteblackip rule based on the values in CreateOpts.
    26  func Create(c *golangsdk.ServiceClient, policyID string, opts CreateOptsBuilder) (r CreateResult) {
    27  	b, err := opts.ToWhiteBlackIPCreateMap()
    28  	if err != nil {
    29  		r.Err = err
    30  		return
    31  	}
    32  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
    33  	_, r.Err = c.Post(rootURL(c, policyID), b, &r.Body, reqOpt)
    34  	return
    35  }
    36  
    37  // UpdateOptsBuilder allows extensions to add additional parameters to the
    38  // Update request.
    39  type UpdateOptsBuilder interface {
    40  	ToWhiteBlackIPUpdateMap() (map[string]interface{}, error)
    41  }
    42  
    43  // UpdateOpts contains all the values needed to update a whiteblackip rule.
    44  type UpdateOpts struct {
    45  	Addr  string `json:"addr" required:"true"`
    46  	White *int   `json:"white" required:"true"`
    47  }
    48  
    49  // ToWhiteBlackIPUpdateMap builds a update request body from UpdateOpts.
    50  func (opts UpdateOpts) ToWhiteBlackIPUpdateMap() (map[string]interface{}, error) {
    51  	return golangsdk.BuildRequestBody(opts, "")
    52  }
    53  
    54  // Update accepts a UpdateOpts struct and uses the values to update a rule.The response code from api is 200
    55  func Update(c *golangsdk.ServiceClient, policyID, ruleID string, opts UpdateOptsBuilder) (r UpdateResult) {
    56  	b, err := opts.ToWhiteBlackIPUpdateMap()
    57  	if err != nil {
    58  		r.Err = err
    59  		return
    60  	}
    61  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200}}
    62  	_, r.Err = c.Put(resourceURL(c, policyID, ruleID), b, nil, reqOpt)
    63  	return
    64  }
    65  
    66  // Get retrieves a particular whiteblackip rule based on its unique ID.
    67  func Get(c *golangsdk.ServiceClient, policyID, ruleID string) (r GetResult) {
    68  	_, r.Err = c.Get(resourceURL(c, policyID, ruleID), &r.Body, openstack.StdRequestOpts())
    69  	return
    70  }
    71  
    72  // Delete will permanently delete a particular whiteblackip rule based on its unique ID.
    73  func Delete(c *golangsdk.ServiceClient, policyID, ruleID string) (r DeleteResult) {
    74  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{204},
    75  		MoreHeaders: openstack.StdRequestOpts().MoreHeaders}
    76  	_, r.Err = c.Delete(resourceURL(c, policyID, ruleID), reqOpt)
    77  	return
    78  }