github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/vpnaas/ikepolicies/results.go (about) 1 package ikepolicies 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/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 gophercloud.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 []gophercloud.Link `json:"ikepolicies_links"` 78 } 79 err := r.ExtractInto(&s) 80 if err != nil { 81 return "", err 82 } 83 return gophercloud.ExtractNextURL(s.Links) 84 } 85 86 // IsEmpty checks whether a PolicyPage struct is empty. 87 func (r PolicyPage) IsEmpty() (bool, error) { 88 if r.StatusCode == 204 { 89 return true, nil 90 } 91 92 is, err := ExtractPolicies(r) 93 return len(is) == 0, err 94 } 95 96 // ExtractPolicies accepts a Page struct, specifically a Policy struct, 97 // and extracts the elements into a slice of Policy structs. In other words, 98 // a generic collection is mapped into a relevant slice. 99 func ExtractPolicies(r pagination.Page) ([]Policy, error) { 100 var s struct { 101 Policies []Policy `json:"ikepolicies"` 102 } 103 err := (r.(PolicyPage)).ExtractInto(&s) 104 return s.Policies, err 105 } 106 107 // CreateResult represents the result of a Create operation. Call its Extract method to 108 // interpret it as a Policy. 109 type CreateResult struct { 110 commonResult 111 } 112 113 // GetResult represents the result of a Get operation. Call its Extract method to 114 // interpret it as a Policy. 115 type GetResult struct { 116 commonResult 117 } 118 119 // DeleteResult represents the results of a Delete operation. Call its ExtractErr method 120 // to determine whether the operation succeeded or failed. 121 type DeleteResult struct { 122 gophercloud.ErrResult 123 } 124 125 // UpdateResult represents the result of an update operation. Call its Extract method 126 // to interpret it as a Policy. 127 type UpdateResult struct { 128 commonResult 129 }