github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/vpnaas/ipsecpolicies/requests.go (about) 1 package ipsecpolicies 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 "github.com/gophercloud/gophercloud/pagination" 6 ) 7 8 type TransformProtocol string 9 type AuthAlgorithm string 10 type EncapsulationMode string 11 type EncryptionAlgorithm string 12 type PFS string 13 type Unit string 14 15 const ( 16 TransformProtocolESP TransformProtocol = "esp" 17 TransformProtocolAH TransformProtocol = "ah" 18 TransformProtocolAHESP TransformProtocol = "ah-esp" 19 AuthAlgorithmSHA1 AuthAlgorithm = "sha1" 20 AuthAlgorithmSHA256 AuthAlgorithm = "sha256" 21 AuthAlgorithmSHA384 AuthAlgorithm = "sha384" 22 AuthAlgorithmSHA512 AuthAlgorithm = "sha512" 23 EncryptionAlgorithm3DES EncryptionAlgorithm = "3des" 24 EncryptionAlgorithmAES128 EncryptionAlgorithm = "aes-128" 25 EncryptionAlgorithmAES256 EncryptionAlgorithm = "aes-256" 26 EncryptionAlgorithmAES192 EncryptionAlgorithm = "aes-192" 27 EncapsulationModeTunnel EncapsulationMode = "tunnel" 28 EncapsulationModeTransport EncapsulationMode = "transport" 29 UnitSeconds Unit = "seconds" 30 UnitKilobytes Unit = "kilobytes" 31 PFSGroup2 PFS = "group2" 32 PFSGroup5 PFS = "group5" 33 PFSGroup14 PFS = "group14" 34 ) 35 36 // CreateOptsBuilder allows extensions to add additional parameters to the 37 // Create request. 38 type CreateOptsBuilder interface { 39 ToPolicyCreateMap() (map[string]interface{}, error) 40 } 41 42 // CreateOpts contains all the values needed to create a new IPSec policy 43 type CreateOpts struct { 44 // TenantID specifies a tenant to own the IPSec policy. The caller must have 45 // an admin role in order to set this. Otherwise, this field is left unset 46 // and the caller will be the owner. 47 TenantID string `json:"tenant_id,omitempty"` 48 49 // Description is the human readable description of the policy. 50 Description string `json:"description,omitempty"` 51 52 // Name is the human readable name of the policy. 53 // Does not have to be unique. 54 Name string `json:"name,omitempty"` 55 56 // AuthAlgorithm is the authentication hash algorithm. 57 // Valid values are sha1, sha256, sha384, sha512. 58 // The default is sha1. 59 AuthAlgorithm AuthAlgorithm `json:"auth_algorithm,omitempty"` 60 61 // EncapsulationMode is the encapsulation mode. 62 // A valid value is tunnel or transport. 63 // Default is tunnel. 64 EncapsulationMode EncapsulationMode `json:"encapsulation_mode,omitempty"` 65 66 // EncryptionAlgorithm is the encryption algorithm. 67 // A valid value is 3des, aes-128, aes-192, aes-256, and so on. 68 // Default is aes-128. 69 EncryptionAlgorithm EncryptionAlgorithm `json:"encryption_algorithm,omitempty"` 70 71 // PFS is the Perfect forward secrecy mode. 72 // A valid value is Group2, Group5, Group14, and so on. 73 // Default is Group5. 74 PFS PFS `json:"pfs,omitempty"` 75 76 // TransformProtocol is the transform protocol. 77 // A valid value is ESP, AH, or AH- ESP. 78 // Default is ESP. 79 TransformProtocol TransformProtocol `json:"transform_protocol,omitempty"` 80 81 //Lifetime is the lifetime of the security association 82 Lifetime *LifetimeCreateOpts `json:"lifetime,omitempty"` 83 } 84 85 // The lifetime consists of a unit and integer value 86 // You can omit either the unit or value portion of the lifetime 87 type LifetimeCreateOpts struct { 88 // Units is the units for the lifetime of the security association 89 // Default unit is seconds 90 Units Unit `json:"units,omitempty"` 91 92 // The lifetime value. 93 // Must be a positive integer. 94 // Default value is 3600. 95 Value int `json:"value,omitempty"` 96 } 97 98 // ToPolicyCreateMap casts a CreateOpts struct to a map. 99 func (opts CreateOpts) ToPolicyCreateMap() (map[string]interface{}, error) { 100 return gophercloud.BuildRequestBody(opts, "ipsecpolicy") 101 } 102 103 // Create accepts a CreateOpts struct and uses the values to create a new 104 // IPSec policy 105 func Create(c *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 106 b, err := opts.ToPolicyCreateMap() 107 if err != nil { 108 r.Err = err 109 return 110 } 111 resp, err := c.Post(rootURL(c), b, &r.Body, nil) 112 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 113 return 114 } 115 116 // Delete will permanently delete a particular IPSec policy based on its 117 // unique ID. 118 func Delete(c *gophercloud.ServiceClient, id string) (r DeleteResult) { 119 resp, err := c.Delete(resourceURL(c, id), nil) 120 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 121 return 122 } 123 124 // Get retrieves a particular IPSec policy based on its unique ID. 125 func Get(c *gophercloud.ServiceClient, id string) (r GetResult) { 126 resp, err := c.Get(resourceURL(c, id), &r.Body, nil) 127 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 128 return 129 } 130 131 // ListOptsBuilder allows extensions to add additional parameters to the 132 // List request. 133 type ListOptsBuilder interface { 134 ToPolicyListQuery() (string, error) 135 } 136 137 // ListOpts allows the filtering of paginated collections through 138 // the API. Filtering is achieved by passing in struct field values that map to 139 // the IPSec policy attributes you want to see returned. 140 type ListOpts struct { 141 TenantID string `q:"tenant_id"` 142 Name string `q:"name"` 143 Description string `q:"description"` 144 ProjectID string `q:"project_id"` 145 AuthAlgorithm string `q:"auth_algorithm"` 146 EncapsulationMode string `q:"encapsulation_mode"` 147 EncryptionAlgorithm string `q:"encryption_algorithm"` 148 PFS string `q:"pfs"` 149 TransformProtocol string `q:"transform_protocol"` 150 } 151 152 // ToPolicyListQuery formats a ListOpts into a query string. 153 func (opts ListOpts) ToPolicyListQuery() (string, error) { 154 q, err := gophercloud.BuildQueryString(opts) 155 return q.String(), err 156 } 157 158 // List returns a Pager which allows you to iterate over a collection of 159 // IPSec policies. It accepts a ListOpts struct, which allows you to filter 160 // the returned collection for greater efficiency. 161 func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { 162 url := rootURL(c) 163 if opts != nil { 164 query, err := opts.ToPolicyListQuery() 165 if err != nil { 166 return pagination.Pager{Err: err} 167 } 168 url += query 169 } 170 return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { 171 return PolicyPage{pagination.LinkedPageBase{PageResult: r}} 172 }) 173 } 174 175 // UpdateOptsBuilder allows extensions to add additional parameters to the 176 // Update request. 177 type UpdateOptsBuilder interface { 178 ToPolicyUpdateMap() (map[string]interface{}, error) 179 } 180 181 type LifetimeUpdateOpts struct { 182 Units Unit `json:"units,omitempty"` 183 Value int `json:"value,omitempty"` 184 } 185 186 // UpdateOpts contains the values used when updating an IPSec policy 187 type UpdateOpts struct { 188 Description *string `json:"description,omitempty"` 189 Name *string `json:"name,omitempty"` 190 AuthAlgorithm AuthAlgorithm `json:"auth_algorithm,omitempty"` 191 EncapsulationMode EncapsulationMode `json:"encapsulation_mode,omitempty"` 192 EncryptionAlgorithm EncryptionAlgorithm `json:"encryption_algorithm,omitempty"` 193 PFS PFS `json:"pfs,omitempty"` 194 TransformProtocol TransformProtocol `json:"transform_protocol,omitempty"` 195 Lifetime *LifetimeUpdateOpts `json:"lifetime,omitempty"` 196 } 197 198 // ToPolicyUpdateMap casts an UpdateOpts struct to a map. 199 func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) { 200 return gophercloud.BuildRequestBody(opts, "ipsecpolicy") 201 } 202 203 // Update allows IPSec policies to be updated. 204 func Update(c *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 205 b, err := opts.ToPolicyUpdateMap() 206 if err != nil { 207 r.Err = err 208 return 209 } 210 resp, err := c.Put(resourceURL(c, id), b, &r.Body, &gophercloud.RequestOpts{ 211 OkCodes: []int{200}, 212 }) 213 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 214 return 215 }