github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v2/extensions/vpnaas/ikepolicies/results.go (about)

     1  package ikepolicies
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/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  
    48  type Lifetime struct {
    49  	// Units is the unit for the lifetime
    50  	// Default is seconds
    51  	Units string `json:"units"`
    52  
    53  	// Value is the lifetime
    54  	// Default is 3600
    55  	Value int `json:"value"`
    56  }
    57  
    58  // Extract is a function that accepts a result and extracts an IKE Policy.
    59  func (r commonResult) Extract() (*Policy, error) {
    60  	var s struct {
    61  		Policy *Policy `json:"ikepolicy"`
    62  	}
    63  	err := r.ExtractInto(&s)
    64  	return s.Policy, err
    65  }
    66  
    67  // PolicyPage is the page returned by a pager when traversing over a
    68  // collection of Policies.
    69  type PolicyPage struct {
    70  	pagination.LinkedPageBase
    71  }
    72  
    73  // NextPageURL is invoked when a paginated collection of IKE policies has
    74  // reached the end of a page and the pager seeks to traverse over a new one.
    75  // In order to do this, it needs to construct the next page's URL.
    76  func (r PolicyPage) NextPageURL() (string, error) {
    77  	var s struct {
    78  		Links []golangsdk.Link `json:"ikepolicies_links"`
    79  	}
    80  	err := r.ExtractInto(&s)
    81  	if err != nil {
    82  		return "", err
    83  	}
    84  	return golangsdk.ExtractNextURL(s.Links)
    85  }
    86  
    87  // IsEmpty checks whether a PolicyPage struct is empty.
    88  func (r PolicyPage) IsEmpty() (bool, error) {
    89  	is, err := ExtractPolicies(r)
    90  	return len(is) == 0, err
    91  }
    92  
    93  // ExtractPolicies accepts a Page struct, specifically a Policy struct,
    94  // and extracts the elements into a slice of Policy structs. In other words,
    95  // a generic collection is mapped into a relevant slice.
    96  func ExtractPolicies(r pagination.Page) ([]Policy, error) {
    97  	var s struct {
    98  		Policies []Policy `json:"ikepolicies"`
    99  	}
   100  	err := (r.(PolicyPage)).ExtractInto(&s)
   101  	return s.Policies, err
   102  }
   103  
   104  // CreateResult represents the result of a Create operation. Call its Extract method to
   105  // interpret it as a Policy.
   106  type CreateResult struct {
   107  	commonResult
   108  }
   109  
   110  // GetResult represents the result of a Get operation. Call its Extract method to
   111  // interpret it as a Policy.
   112  type GetResult struct {
   113  	commonResult
   114  }
   115  
   116  // DeleteResult represents the results of a Delete operation. Call its ExtractErr method
   117  // to determine whether the operation succeeded or failed.
   118  type DeleteResult struct {
   119  	golangsdk.ErrResult
   120  }
   121  
   122  // UpdateResult represents the result of an update operation. Call its Extract method
   123  // to interpret it as a Policy.
   124  type UpdateResult struct {
   125  	commonResult
   126  }