github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf-premium/v1/rules/UpdateBlacklist.go (about)

     1  package rules
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type UpdateBlacklistOpts struct {
    10  	// Rule name.
    11  	Name string `json:"name,omitempty"`
    12  	// Rule description.
    13  	Description string `json:"description,omitempty"`
    14  	// IP addresses or an IP address range.
    15  	// IP addresses: IP addresses to be added to the blacklist or whitelist,
    16  	// for example, 192.x.x.3
    17  	// IP address range: IP address and subnet mask,
    18  	// for example, 10.x.x.0/24
    19  	Addresses string `json:"addr,omitempty" required:"true"`
    20  	// Protective action. The value can be:
    21  	// 0: WAF blocks the requests that hit the rule.
    22  	// 1: WAF allows the requests that hit the rule.
    23  	// 2: WAF only logs the requests that hit the rule.
    24  	Action *int `json:"white" required:"true"`
    25  	// ID of a known attack source rule. This parameter can be configured only when white is set to 0.
    26  	FollowedActionId string `json:"followed_action_id,omitempty"`
    27  }
    28  
    29  // UpdateBlacklist is used to update an IP address blacklist or whitelist rule.
    30  func UpdateBlacklist(client *golangsdk.ServiceClient, policyId, ruleId string, opts UpdateBlacklistOpts) (*BlacklistRule, error) {
    31  	b, err := build.RequestBody(opts, "")
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  
    36  	// PUT /v1/{project_id}/waf/policy/{policy_id}/whiteblackip/{rule_id}
    37  	raw, err := client.Put(client.ServiceURL("waf", "policy", policyId, "whiteblackip", ruleId), b, nil, &golangsdk.RequestOpts{
    38  		OkCodes:     []int{200},
    39  		MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"},
    40  	})
    41  	if err != nil {
    42  		return nil, err
    43  	}
    44  
    45  	var res BlacklistRule
    46  	return &res, extract.Into(raw.Body, &res)
    47  }