github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf-premium/v1/rules/CreateBlacklist.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 BlacklistCreateOpts 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 -IP address range: IP address and subnet mask, for example, 10.x.x.0/24 17 Addresses string `json:"addr" required:"true"` 18 // Protective action. The value can be: 19 // 0: WAF blocks the requests that hit the rule. 20 // 1: WAF allows the requests that hit the rule. 21 // 2: WAF only logs the requests that hit the rule. 22 Action *int `json:"white" required:"true"` 23 // ID of a known attack source rule. This parameter can be configured only when white is set to 0. 24 FollowedActionId string `json:"followed_action_id,omitempty"` 25 } 26 27 // CreateBlacklist will create a blacklist or whitelist rule on the values in WhitelistCreateOpts. 28 func CreateBlacklist(client *golangsdk.ServiceClient, policyId string, opts BlacklistCreateOpts) (*BlacklistRule, error) { 29 b, err := build.RequestBody(opts, "") 30 if err != nil { 31 return nil, err 32 } 33 34 // POST /v1/{project_id}/waf/policy/{policy_id}/whiteblackip 35 raw, err := client.Post(client.ServiceURL("waf", "policy", policyId, "whiteblackip"), b, 36 nil, &golangsdk.RequestOpts{ 37 OkCodes: []int{200}, 38 MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"}, 39 }) 40 if err != nil { 41 return nil, err 42 } 43 44 var res BlacklistRule 45 err = extract.Into(raw.Body, &res) 46 return &res, err 47 } 48 49 type BlacklistRule struct { 50 // Rule ID. 51 ID string `json:"id"` 52 // Rule name. 53 Name string `json:"name"` 54 // Policy ID. 55 PolicyId string `json:"policyid"` 56 // Rule creation time. 57 CreatedAt int64 `json:"timestamp"` 58 // Rule description. 59 Description string `json:"description"` 60 // Rule status. The value can be: 61 // 0: The rule is disabled. 62 // 1: The rule is enabled. 63 Status *int `json:"status"` 64 // Blacklisted or whitelisted IP addresses 65 Addresses string `json:"addr"` 66 // Protective action. The value can be: 67 // 0: WAF blocks the requests that hit the rule. 68 // 1: WAF allows the requests that hit the rule. 69 // 2: WAF only logs the requests that hit the rule. 70 Action *int `json:"white"` 71 // ID of the known attack source rule. 72 FollowedActionId string `json:"followed_action_id"` 73 }