github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/waf-premium/v1/rules/CreateAntiCrawler.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 CreateAntiCrawlerOpts struct { 10 // URL to which the rule applies. 11 Url string `json:"url" required:"true"` 12 // Rule matching logic 13 // 1: Include 14 // 2: Not include 15 // 3: Equal 16 // 4: Not equal 17 // 5: Prefix is 18 // 6: Prefix is not 19 // 7: Suffix is 20 // 8: Suffix is not 21 Logic int `json:"logic" required:"true"` 22 // Rule name. 23 Name string `json:"name" required:"true"` 24 // JavaScript anti-crawler rule type. 25 // anticrawler_specific_url: used to protect a specific path specified by the rule. 26 // anticrawler_except_url: used to protect all paths except the one specified by the rule. 27 Type string `json:"type" required:"true"` 28 } 29 30 // CreateAntiCrawler will create a JavaScript anti-crawler rule on the values in CreateOpts. 31 func CreateAntiCrawler(client *golangsdk.ServiceClient, policyId string, opts CreateAntiCrawlerOpts) (*AntiCrawlerRule, error) { 32 b, err := build.RequestBody(opts, "") 33 if err != nil { 34 return nil, err 35 } 36 37 // POST /v1/{project_id}/waf/policy/{policy_id}/anticrawler 38 raw, err := client.Post(client.ServiceURL("waf", "policy", policyId, "anticrawler"), b, 39 nil, &golangsdk.RequestOpts{ 40 OkCodes: []int{200}, 41 MoreHeaders: map[string]string{"Content-Type": "application/json;charset=utf8"}, 42 }) 43 if err != nil { 44 return nil, err 45 } 46 47 var res AntiCrawlerRule 48 err = extract.Into(raw.Body, &res) 49 return &res, err 50 } 51 52 type AntiCrawlerRule struct { 53 // Rule ID. 54 ID string `json:"id"` 55 // Policy ID. 56 PolicyId string `json:"policyid"` 57 // Timestamp the rule is created. 58 CreatedAt int64 `json:"timestamp"` 59 // URL to which the rule applies. 60 Url string `json:"url"` 61 // Rule matching logic 62 // 1: Include 63 // 2: Not include 64 // 3: Equal 65 // 4: Not equal 66 // 5: Prefix is 67 // 6: Prefix is not 68 // 7: Suffix is 69 // 8: Suffix is not 70 Logic int `json:"logic"` 71 // Rule name. 72 Name string `json:"name"` 73 // JavaScript anti-crawler rule type. 74 // anticrawler_specific_url: used to protect a specific path specified by the rule. 75 // anticrawler_except_url: used to protect all paths except the one specified by the rule. 76 Type string `json:"type"` 77 // Rule status. The value can be 0 or 1. 78 Status int `json:"status"` 79 }