github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/waf/v1/falsealarmmasking_rules/requests.go (about)

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