github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/fwaas_v2/rules/results.go (about) 1 package rules 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // Rule represents a firewall rule 9 type Rule struct { 10 ID string `json:"id"` 11 Name string `json:"name,omitempty"` 12 Description string `json:"description,omitempty"` 13 Protocol string `json:"protocol"` 14 Action string `json:"action"` 15 IPVersion int `json:"ip_version,omitempty"` 16 SourceIPAddress string `json:"source_ip_address,omitempty"` 17 DestinationIPAddress string `json:"destination_ip_address,omitempty"` 18 SourcePort string `json:"source_port,omitempty"` 19 DestinationPort string `json:"destination_port,omitempty"` 20 Shared bool `json:"shared,omitempty"` 21 Enabled bool `json:"enabled,omitempty"` 22 PolicyID string `json:"firewall_policy_id"` 23 Position int `json:"position"` 24 TenantID string `json:"tenant_id"` 25 } 26 27 // RulePage is the page returned by a pager when traversing over a 28 // collection of firewall rules. 29 type RulePage struct { 30 pagination.LinkedPageBase 31 } 32 33 // NextPageURL is invoked when a paginated collection of firewall rules has 34 // reached the end of a page and the pager seeks to traverse over a new one. 35 // In order to do this, it needs to construct the next page's URL. 36 func (r RulePage) NextPageURL() (string, error) { 37 var s struct { 38 Links []golangsdk.Link `json:"firewall_rules_links"` 39 } 40 err := r.ExtractInto(&s) 41 if err != nil { 42 return "", err 43 } 44 return golangsdk.ExtractNextURL(s.Links) 45 } 46 47 // IsEmpty checks whether a RulePage struct is empty. 48 func (r RulePage) IsEmpty() (bool, error) { 49 is, err := ExtractRules(r) 50 return len(is) == 0, err 51 } 52 53 // ExtractRules accepts a Page struct, specifically a RouterPage struct, 54 // and extracts the elements into a slice of Router structs. In other words, 55 // a generic collection is mapped into a relevant slice. 56 func ExtractRules(r pagination.Page) ([]Rule, error) { 57 var s struct { 58 Rules []Rule `json:"firewall_rules"` 59 } 60 err := (r.(RulePage)).ExtractInto(&s) 61 return s.Rules, err 62 } 63 64 type commonResult struct { 65 golangsdk.Result 66 } 67 68 // Extract is a function that accepts a result and extracts a firewall rule. 69 func (r commonResult) Extract() (*Rule, error) { 70 var s struct { 71 Rule *Rule `json:"firewall_rule"` 72 } 73 err := r.ExtractInto(&s) 74 return s.Rule, err 75 } 76 77 // GetResult represents the result of a get operation. 78 type GetResult struct { 79 commonResult 80 } 81 82 // UpdateResult represents the result of an update operation. 83 type UpdateResult struct { 84 commonResult 85 } 86 87 // DeleteResult represents the result of a delete operation. 88 type DeleteResult struct { 89 golangsdk.ErrResult 90 } 91 92 // CreateResult represents the result of a create operation. 93 type CreateResult struct { 94 commonResult 95 }