github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf-premium/v1/rules/CreateGeoIp.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 CreateGeoIpOpts struct {
    10  	// Applicable regions. The value can be the region code.
    11  	GeoIp string `json:"geoip" required:"true"`
    12  	// Protective action. The value can be:
    13  	// 0: WAF blocks the requests that hit the rule.
    14  	// 1: WAF allows the requests that hit the rule.
    15  	// 2: WAF only logs the requests that hit the rule.
    16  	Action *int `json:"white" required:"true"`
    17  	// Rule name. Currently, the console does not support configuring
    18  	// names for geolocation access control rule. Ignore this parameter.
    19  	Name string `json:"name" required:"true"`
    20  	// Rule description.
    21  	Description string `json:"description"`
    22  }
    23  
    24  // CreateGeoIp will create a geolocation access control rule on the values in CreateOpts.
    25  func CreateGeoIp(client *golangsdk.ServiceClient, policyId string, opts CreateGeoIpOpts) (*GeoIpRule, error) {
    26  	b, err := build.RequestBody(opts, "")
    27  	if err != nil {
    28  		return nil, err
    29  	}
    30  
    31  	// POST /v1/{project_id}/waf/policy/{policy_id}/geoip
    32  	raw, err := client.Post(client.ServiceURL("waf", "policy", policyId, "geoip"), b,
    33  		nil, &golangsdk.RequestOpts{
    34  			OkCodes:     []int{200},
    35  			MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"},
    36  		})
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  
    41  	var res GeoIpRule
    42  	err = extract.Into(raw.Body, &res)
    43  	return &res, err
    44  }
    45  
    46  type GeoIpRule struct {
    47  	// Rule ID.
    48  	ID string `json:"id"`
    49  	// Policy ID.
    50  	PolicyId string `json:"policyid"`
    51  	// Rule name.
    52  	Name string `json:"name"`
    53  	// List of geographical locations hit the geolocation access control rule.
    54  	GeoTagList []string `json:"geoTagList"`
    55  	// Applicable regions.
    56  	GeoIp string `json:"geoip"`
    57  	// Protective action.
    58  	Action int `json:"white"`
    59  	// Rule status.
    60  	Status *int `json:"status"`
    61  	// Time the rule is created. The value is a 13-digit timestamp in ms.
    62  	CreatedAt int64 `json:"timestamp"`
    63  	// Rule description.
    64  	Description string `json:"description"`
    65  }