github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf-premium/v1/rules/CreateKnownAttackSource.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 CreateKnownAttackSourceOpts struct {
    10  	// Type of the know attack source rule.
    11  	// Enumeration values:
    12  	// long_ip_block
    13  	// long_cookie_block
    14  	// long_params_block
    15  	// short_ip_block
    16  	// short_cookie_block
    17  	// short_params_block
    18  	Category string `json:"category" required:"true"`
    19  	// Block duration, in seconds. If prefix long is selected for the rule type,
    20  	// the value for block_time ranges from 301 to 1800.
    21  	// If prefix short is selected for the rule type,
    22  	// the value for block_time ranges from 0 to 300.
    23  	BlockTime *int `json:"block_time" required:"true"`
    24  	// Rule description.
    25  	Description string `json:"description"`
    26  }
    27  
    28  // CreateKnownAttackSource will create a known attack source rule on the values in CreateKnownAttackSourceOpts.
    29  func CreateKnownAttackSource(client *golangsdk.ServiceClient, policyId string, opts CreateKnownAttackSourceOpts) (*KnownAttackSourceRule, error) {
    30  	b, err := build.RequestBody(opts, "")
    31  	if err != nil {
    32  		return nil, err
    33  	}
    34  
    35  	// POST /v1/{project_id}/waf/policy/{policy_id}/punishment
    36  	raw, err := client.Post(client.ServiceURL("waf", "policy", policyId, "punishment"), b,
    37  		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 KnownAttackSourceRule
    46  	err = extract.Into(raw.Body, &res)
    47  	return &res, err
    48  }
    49  
    50  type KnownAttackSourceRule struct {
    51  	// Rule ID.
    52  	ID string `json:"id"`
    53  	// Policy ID.
    54  	PolicyId string `json:"policyid"`
    55  	// Time the rule is created. The value is a 13-digit timestamp in ms.
    56  	CreatedAt int64 `json:"timestamp"`
    57  	// Type of the know attack source rule.
    58  	Category string `json:"category"`
    59  	// Rule description.
    60  	Description string `json:"description"`
    61  	// Block duration, in seconds.
    62  	BlockTime int `json:"block_time"`
    63  }