github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/fwaas_v2/rules/results.go (about) 1 package rules 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/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 FirewallPolicyID []string `json:"firewall_policy_id"` 23 TenantID string `json:"tenant_id"` 24 ProjectID string `json:"project_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 []gophercloud.Link `json:"firewall_rules_links"` 39 } 40 err := r.ExtractInto(&s) 41 if err != nil { 42 return "", err 43 } 44 return gophercloud.ExtractNextURL(s.Links) 45 } 46 47 // IsEmpty checks whether a RulePage struct is empty. 48 func (r RulePage) IsEmpty() (bool, error) { 49 if r.StatusCode == 204 { 50 return true, nil 51 } 52 53 is, err := ExtractRules(r) 54 return len(is) == 0, err 55 } 56 57 // ExtractRules accepts a Page struct, specifically a RouterPage struct, 58 // and extracts the elements into a slice of Router structs. In other words, 59 // a generic collection is mapped into a relevant slice. 60 func ExtractRules(r pagination.Page) ([]Rule, error) { 61 var s struct { 62 Rules []Rule `json:"firewall_rules"` 63 } 64 err := (r.(RulePage)).ExtractInto(&s) 65 return s.Rules, err 66 } 67 68 type commonResult struct { 69 gophercloud.Result 70 } 71 72 // Extract is a function that accepts a result and extracts a firewall rule. 73 func (r commonResult) Extract() (*Rule, error) { 74 var s struct { 75 Rule *Rule `json:"firewall_rule"` 76 } 77 err := r.ExtractInto(&s) 78 return s.Rule, err 79 } 80 81 // GetResult represents the result of a get operation. 82 type GetResult struct { 83 commonResult 84 } 85 86 // UpdateResult represents the result of an update operation. 87 type UpdateResult struct { 88 commonResult 89 } 90 91 // DeleteResult represents the result of a delete operation. 92 type DeleteResult struct { 93 gophercloud.ErrResult 94 } 95 96 // CreateResult represents the result of a create operation. 97 type CreateResult struct { 98 commonResult 99 }