github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/vpnaas/ikepolicies/results.go (about)

     1  package ikepolicies
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // Policy is an IKE Policy
     9  type Policy struct {
    10  	// TenantID is the ID of the project
    11  	TenantID string `json:"tenant_id"`
    12  
    13  	// ProjectID is the ID of the project
    14  	ProjectID string `json:"project_id"`
    15  
    16  	// Description is the human readable description of the policy
    17  	Description string `json:"description"`
    18  
    19  	// Name is the human readable name of the policy
    20  	Name string `json:"name"`
    21  
    22  	// AuthAlgorithm is the authentication hash algorithm
    23  	AuthAlgorithm string `json:"auth_algorithm"`
    24  
    25  	// EncryptionAlgorithm is the encryption algorithm
    26  	EncryptionAlgorithm string `json:"encryption_algorithm"`
    27  
    28  	// PFS is the Perfect forward secrecy (PFS) mode
    29  	PFS string `json:"pfs"`
    30  
    31  	// Lifetime is the lifetime of the security association
    32  	Lifetime Lifetime `json:"lifetime"`
    33  
    34  	// ID is the ID of the policy
    35  	ID string `json:"id"`
    36  
    37  	// Phase1NegotiationMode is the IKE mode
    38  	Phase1NegotiationMode string `json:"phase1_negotiation_mode"`
    39  
    40  	// IKEVersion is the IKE version.
    41  	IKEVersion string `json:"ike_version"`
    42  }
    43  
    44  type commonResult struct {
    45  	golangsdk.Result
    46  }
    47  type Lifetime struct {
    48  	// Units is the unit for the lifetime
    49  	// Default is seconds
    50  	Units string `json:"units"`
    51  
    52  	// Value is the lifetime
    53  	// Default is 3600
    54  	Value int `json:"value"`
    55  }
    56  
    57  // Extract is a function that accepts a result and extracts an IKE Policy.
    58  func (r commonResult) Extract() (*Policy, error) {
    59  	var s struct {
    60  		Policy *Policy `json:"ikepolicy"`
    61  	}
    62  	err := r.ExtractInto(&s)
    63  	return s.Policy, err
    64  }
    65  
    66  // PolicyPage is the page returned by a pager when traversing over a
    67  // collection of Policies.
    68  type PolicyPage struct {
    69  	pagination.LinkedPageBase
    70  }
    71  
    72  // NextPageURL is invoked when a paginated collection of IKE policies has
    73  // reached the end of a page and the pager seeks to traverse over a new one.
    74  // In order to do this, it needs to construct the next page's URL.
    75  func (r PolicyPage) NextPageURL() (string, error) {
    76  	var s struct {
    77  		Links []golangsdk.Link `json:"ikepolicies_links"`
    78  	}
    79  	err := r.ExtractInto(&s)
    80  	if err != nil {
    81  		return "", err
    82  	}
    83  	return golangsdk.ExtractNextURL(s.Links)
    84  }
    85  
    86  // IsEmpty checks whether a PolicyPage struct is empty.
    87  func (r PolicyPage) IsEmpty() (bool, error) {
    88  	is, err := ExtractPolicies(r)
    89  	return len(is) == 0, err
    90  }
    91  
    92  // ExtractPolicies accepts a Page struct, specifically a Policy struct,
    93  // and extracts the elements into a slice of Policy structs. In other words,
    94  // a generic collection is mapped into a relevant slice.
    95  func ExtractPolicies(r pagination.Page) ([]Policy, error) {
    96  	var s struct {
    97  		Policies []Policy `json:"ikepolicies"`
    98  	}
    99  	err := (r.(PolicyPage)).ExtractInto(&s)
   100  	return s.Policies, err
   101  }
   102  
   103  // CreateResult represents the result of a Create operation. Call its Extract method to
   104  // interpret it as a Policy.
   105  type CreateResult struct {
   106  	commonResult
   107  }
   108  
   109  // GetResult represents the result of a Get operation. Call its Extract method to
   110  // interpret it as a Policy.
   111  type GetResult struct {
   112  	commonResult
   113  }
   114  
   115  // DeleteResult represents the results of a Delete operation. Call its ExtractErr method
   116  // to determine whether the operation succeeded or failed.
   117  type DeleteResult struct {
   118  	golangsdk.ErrResult
   119  }
   120  
   121  // UpdateResult represents the result of an update operation. Call its Extract method
   122  // to interpret it as a Policy.
   123  type UpdateResult struct {
   124  	commonResult
   125  }