github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/waf_hw/v1/policies/results.go (about) 1 package policies 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 // Policy contains the infomateion of the policy. 9 type Policy struct { 10 Id string `json:"id"` 11 Name string `json:"name"` 12 Action Action `json:"action"` 13 RobotAction Action `json:"robot_action"` 14 Options PolicyOption `json:"options"` 15 Level int `json:"level"` 16 FullDetection bool `json:"full_detection"` 17 Hosts []string `json:"hosts"` 18 BindHosts []BindHost `json:"bind_host"` 19 Extend map[string]string `json:"extend"` 20 } 21 22 //Action contains actions after the attack is detected 23 type Action struct { 24 Category string `json:"category,omitempty"` 25 FollowedActionId string `json:"followed_action_id,omitempty"` 26 } 27 28 // PolicyOption contains the protection rule of a policy 29 type PolicyOption struct { 30 Webattack *bool `json:"webattack,omitempty"` 31 Common *bool `json:"common,omitempty"` 32 Crawler *bool `json:"crawler,omitempty"` 33 CrawlerEngine *bool `json:"crawler_engine,omitempty"` 34 CrawlerScanner *bool `json:"crawler_scanner,omitempty"` 35 CrawlerScript *bool `json:"crawler_script,omitempty"` 36 CrawlerOther *bool `json:"crawler_other,omitempty"` 37 Webshell *bool `json:"webshell,omitempty"` 38 Cc *bool `json:"cc,omitempty"` 39 Custom *bool `json:"custom,omitempty"` 40 Whiteblackip *bool `json:"whiteblackip,omitempty"` 41 Ignore *bool `json:"ignore,omitempty"` 42 Privacy *bool `json:"privacy,omitempty"` 43 Antitamper *bool `json:"antitamper,omitempty"` 44 GeoIP *bool `json:"geoip,omitempty"` 45 Antileakage *bool `json:"antileakage,omitempty"` 46 BotEnable *bool `json:"bot_enable,omitempty"` 47 FollowedAction *bool `json:"followed_action,omitempty"` 48 Anticrawler *bool `json:"anticrawler,omitempty"` 49 } 50 51 // BindHost the hosts bound to this policy. 52 type BindHost struct { 53 Id string `json:"id"` 54 Hostname string `json:"hostname"` 55 WafType string `json:"waf_type"` 56 Mode string `json:"mode"` 57 } 58 59 type commonResult struct { 60 golangsdk.Result 61 } 62 63 // Extract is a function that accepts a result and extracts a policy. 64 func (r commonResult) Extract() (*Policy, error) { 65 var response Policy 66 err := r.ExtractInto(&response) 67 return &response, err 68 } 69 70 // CreateResult represents the result of a create operation. Call its Extract 71 // method to interpret it as a Policy. 72 type CreateResult struct { 73 commonResult 74 } 75 76 // UpdateResult represents the result of a update operation. Call its Extract 77 // method to interpret it as a Policy. 78 type UpdateResult struct { 79 commonResult 80 } 81 82 // GetResult represents the result of a get operation. Call its Extract 83 // method to interpret it as a Policy. 84 type GetResult struct { 85 commonResult 86 } 87 88 // DeleteResult represents the result of a delete operation. Call its ExtractErr 89 // method to determine if the request succeeded or failed. 90 type DeleteResult struct { 91 golangsdk.ErrResult 92 } 93 94 // ListPolicyRst 95 type ListPolicyRst struct { 96 // total policy count. 97 Total int `json:"total"` 98 // the policy list 99 Items []Policy `json:"items"` 100 } 101 102 type PolicyPage struct { 103 pagination.PageSizeBase 104 } 105 106 func (r PolicyPage) IsEmpty() (bool, error) { 107 arr, err := ExtractPolicies(r) 108 return len(arr) == 0, err 109 } 110 111 func ExtractPolicies(r pagination.Page) ([]Policy, error) { 112 var s ListPolicyRst 113 err := (r.(PolicyPage)).ExtractInto(&s) 114 return s.Items, err 115 }