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