Skip to content

Commit b315219

Browse files
authored
Allow unsetting certain parameters
1 parent 2765b1f commit b315219

2 files changed

Lines changed: 61 additions & 6 deletions

File tree

openstack/loadbalancer/v2/listeners/requests.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ const (
3737
TLSVersionTLSv1_3 TLSVersion = "TLSv1.3"
3838
)
3939

40+
// ClientAuthentication represents the TLS client authentication mode.
41+
type ClientAuthentication string
42+
43+
const (
44+
ClientAuthenticationNone ClientAuthentication = "NONE"
45+
ClientAuthenticationOptional ClientAuthentication = "OPTIONAL"
46+
ClientAuthenticationMandatory ClientAuthentication = "MANDATORY"
47+
)
48+
4049
// ListOptsBuilder allows extensions to add additional parameters to the
4150
// List request.
4251
type ListOptsBuilder interface {
@@ -176,7 +185,7 @@ type CreateOpts struct {
176185

177186
// The TLS client authentication mode. One of the options NONE,
178187
// OPTIONAL or MANDATORY. Available from microversion 2.8.
179-
ClientAuthentication string `json:"client_authentication,omitempty"`
188+
ClientAuthentication ClientAuthentication `json:"client_authentication,omitempty"`
180189

181190
// The ref of the key manager service secret containing a PEM format
182191
// client CA certificate bundle for TERMINATED_HTTPS listeners.
@@ -301,7 +310,7 @@ type UpdateOpts struct {
301310

302311
// The TLS client authentication mode. One of the options NONE,
303312
// OPTIONAL or MANDATORY. Available from microversion 2.8.
304-
ClientAuthentication *string `json:"client_authentication,omitempty"`
313+
ClientAuthentication *ClientAuthentication `json:"client_authentication,omitempty"`
305314

306315
// The ref of the key manager service secret containing a PEM format
307316
// client CA certificate bundle for TERMINATED_HTTPS listeners.
@@ -349,10 +358,23 @@ func (opts UpdateOpts) ToListenerUpdateMap() (map[string]any, error) {
349358
return nil, err
350359
}
351360

352-
if m := b["listener"].(map[string]any); m["default_pool_id"] == "" {
361+
m := b["listener"].(map[string]any)
362+
363+
// allow to unset default_pool_id on empty string
364+
if m["default_pool_id"] == "" {
353365
m["default_pool_id"] = nil
354366
}
355367

368+
// allow to unset alpn_protocols on empty slice
369+
if opts.ALPNProtocols != nil && len(*opts.ALPNProtocols) == 0 {
370+
m["alpn_protocols"] = nil
371+
}
372+
373+
// allow to unset tls_versions on empty slice
374+
if opts.TLSVersions != nil && len(*opts.TLSVersions) == 0 {
375+
m["tls_versions"] = nil
376+
}
377+
356378
return b, nil
357379
}
358380

openstack/loadbalancer/v2/pools/requests.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ import (
88
"github.com/gophercloud/gophercloud/v2/pagination"
99
)
1010

11+
// Type TLSVersion represents a tls version
12+
type TLSVersion string
13+
14+
const (
15+
TLSVersionSSLv3 TLSVersion = "SSLv3"
16+
TLSVersionTLSv1 TLSVersion = "TLSv1"
17+
TLSVersionTLSv1_1 TLSVersion = "TLSv1.1"
18+
TLSVersionTLSv1_2 TLSVersion = "TLSv1.2"
19+
TLSVersionTLSv1_3 TLSVersion = "TLSv1.3"
20+
)
21+
1122
// ListOptsBuilder allows extensions to add additional parameters to the
1223
// List request.
1324
type ListOptsBuilder interface {
@@ -151,7 +162,7 @@ type CreateOpts struct {
151162

152163
// A list of TLS protocol versions. Available versions: SSLv3, TLSv1,
153164
// TLSv1.1, TLSv1.2, TLSv1.3. Available from microversion 2.17.
154-
TLSVersions []string `json:"tls_versions,omitempty"`
165+
TLSVersions []TLSVersion `json:"tls_versions,omitempty"`
155166

156167
// The administrative state of the Pool. A valid value is true (UP)
157168
// or false (DOWN).
@@ -256,15 +267,37 @@ type UpdateOpts struct {
256267

257268
// A list of TLS protocol versions. Available versions: SSLv3, TLSv1,
258269
// TLSv1.1, TLSv1.2, TLSv1.3. Available from microversion 2.17.
259-
TLSVersions *[]string `json:"tls_versions,omitempty"`
270+
TLSVersions *[]TLSVersion `json:"tls_versions,omitempty"`
260271

261272
// Tags is a set of resource tags. New in version 2.5
262273
Tags *[]string `json:"tags,omitempty"`
263274
}
264275

265276
// ToPoolUpdateMap builds a request body from UpdateOpts.
266277
func (opts UpdateOpts) ToPoolUpdateMap() (map[string]any, error) {
267-
return gophercloud.BuildRequestBody(opts, "pool")
278+
b, err := gophercloud.BuildRequestBody(opts, "pool")
279+
if err != nil {
280+
return nil, err
281+
}
282+
283+
m := b["pool"].(map[string]any)
284+
285+
// allow to unset session_persistence on empty SessionPersistence struct
286+
if opts.Persistence != nil && *opts.Persistence == (SessionPersistence{}) {
287+
m["session_persistence"] = nil
288+
}
289+
290+
// allow to unset alpn_protocols on empty slice
291+
if opts.ALPNProtocols != nil && len(*opts.ALPNProtocols) == 0 {
292+
m["alpn_protocols"] = nil
293+
}
294+
295+
// allow to unset tls_versions on empty slice
296+
if opts.TLSVersions != nil && len(*opts.TLSVersions) == 0 {
297+
m["tls_versions"] = nil
298+
}
299+
300+
return b, nil
268301
}
269302

270303
// Update allows pools to be updated.

0 commit comments

Comments
 (0)