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