github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf-premium/v1/rules/UpdateGeoIp.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 UpdateGeoIpOpts struct {
    10  	// Applicable regions.
    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  	// Name of the masked field
    18  	Name string `json:"name"`
    19  	// Rule description
    20  	Description string `json:"description"`
    21  }
    22  
    23  // UpdateGeoIp is used to update a geolocation access control rule.
    24  func UpdateGeoIp(client *golangsdk.ServiceClient, policyId, ruleId string, opts UpdateGeoIpOpts) (*GeoIpRule, error) {
    25  	b, err := build.RequestBody(opts, "")
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	// PUT /v1/{project_id}/waf/policy/{policy_id}/geoip/{rule_id}
    31  	raw, err := client.Put(client.ServiceURL("waf", "policy", policyId, "geoip", ruleId), b, nil, &golangsdk.RequestOpts{
    32  		OkCodes:     []int{200},
    33  		MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"},
    34  	})
    35  	if err != nil {
    36  		return nil, err
    37  	}
    38  	var res GeoIpRule
    39  	return &res, extract.Into(raw.Body, &res)
    40  }