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