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