github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/results.go (about) 1 package ipsecpolicies 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // Policy is an IPSec 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 // EncapsulationMode is the encapsulation mode 26 EncapsulationMode string `json:"encapsulation_mode"` 27 28 // EncryptionAlgorithm is the encryption algorithm 29 EncryptionAlgorithm string `json:"encryption_algorithm"` 30 31 // PFS is the Perfect forward secrecy (PFS) mode 32 PFS string `json:"pfs"` 33 34 // TransformProtocol is the transform protocol 35 TransformProtocol string `json:"transform_protocol"` 36 37 // Lifetime is the lifetime of the security association 38 Lifetime Lifetime `json:"lifetime"` 39 40 // ID is the ID of the policy 41 ID string `json:"id"` 42 } 43 44 type Lifetime struct { 45 // Units is the unit for the lifetime 46 // Default is seconds 47 Units string `json:"units"` 48 49 // Value is the lifetime 50 // Default is 3600 51 Value int `json:"value"` 52 } 53 54 type commonResult struct { 55 golangsdk.Result 56 } 57 58 // Extract is a function that accepts a result and extracts an IPSec Policy. 59 func (r commonResult) Extract() (*Policy, error) { 60 var s struct { 61 Policy *Policy `json:"ipsecpolicy"` 62 } 63 err := r.ExtractInto(&s) 64 return s.Policy, err 65 } 66 67 // CreateResult represents the result of a create operation. Call its Extract 68 // method to interpret it as a Policy. 69 type CreateResult struct { 70 commonResult 71 } 72 73 // CreateResult represents the result of a delete operation. Call its ExtractErr method 74 // to determine if the operation succeeded or failed. 75 type DeleteResult struct { 76 golangsdk.ErrResult 77 } 78 79 // GetResult represents the result of a get operation. Call its Extract 80 // method to interpret it as a Policy. 81 type GetResult struct { 82 commonResult 83 } 84 85 // PolicyPage is the page returned by a pager when traversing over a 86 // collection of Policies. 87 type PolicyPage struct { 88 pagination.LinkedPageBase 89 } 90 91 // NextPageURL is invoked when a paginated collection of IPSec policies has 92 // reached the end of a page and the pager seeks to traverse over a new one. 93 // In order to do this, it needs to construct the next page's URL. 94 func (r PolicyPage) NextPageURL() (string, error) { 95 var s struct { 96 Links []golangsdk.Link `json:"ipsecpolicies_links"` 97 } 98 err := r.ExtractInto(&s) 99 if err != nil { 100 return "", err 101 } 102 return golangsdk.ExtractNextURL(s.Links) 103 } 104 105 // IsEmpty checks whether a PolicyPage struct is empty. 106 func (r PolicyPage) IsEmpty() (bool, error) { 107 is, err := ExtractPolicies(r) 108 return len(is) == 0, err 109 } 110 111 // ExtractPolicies accepts a Page struct, specifically a Policy struct, 112 // and extracts the elements into a slice of Policy structs. In other words, 113 // a generic collection is mapped into a relevant slice. 114 func ExtractPolicies(r pagination.Page) ([]Policy, error) { 115 var s struct { 116 Policies []Policy `json:"ipsecpolicies"` 117 } 118 err := (r.(PolicyPage)).ExtractInto(&s) 119 return s.Policies, err 120 } 121 122 // UpdateResult represents the result of an update operation. Call its Extract 123 // method to interpret it as a Policy. 124 type UpdateResult struct { 125 commonResult 126 }