Skip to content

Commit 27b4c75

Browse files
committed
Update loadbalancer/v2/l7policies create and update
Add REDIRECT_PREFIX and REDIRECT_HTTP_CODE to l7policy CreateOpts and UpdateOpts. Docs: https://docs.openstack.org/api-ref/load-balancer/v2/?expanded=create-an-l7-policy-detail,update-a-l7-policy-detail#create-an-l7-policy For: #2322
1 parent 14140a8 commit 27b4c75

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

openstack/loadbalancer/v2/l7policies/requests.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type RuleType string
1616
type CompareType string
1717

1818
const (
19+
ActionRedirectPrefix Action = "REDIRECT_PREFIX"
1920
ActionRedirectToPool Action = "REDIRECT_TO_POOL"
2021
ActionRedirectToURL Action = "REDIRECT_TO_URL"
2122
ActionReject Action = "REJECT"
@@ -42,7 +43,7 @@ type CreateOpts struct {
4243
// The ID of the listener.
4344
ListenerID string `json:"listener_id,omitempty"`
4445

45-
// The L7 policy action. One of REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT.
46+
// The L7 policy action. One of REDIRECT_PREFIX, REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT.
4647
Action Action `json:"action" required:"true"`
4748

4849
// The position of this policy on the listener.
@@ -55,6 +56,10 @@ type CreateOpts struct {
5556
// Only administrative users can specify a project UUID other than their own.
5657
ProjectID string `json:"project_id,omitempty"`
5758

59+
// Requests matching this policy will be redirected to this Prefix URL.
60+
// Only valid if action is REDIRECT_PREFIX.
61+
RedirectPrefix string `json:"redirect_prefix,omitempty"`
62+
5863
// Requests matching this policy will be redirected to the pool with this ID.
5964
// Only valid if action is REDIRECT_TO_POOL.
6065
RedirectPoolID string `json:"redirect_pool_id,omitempty"`
@@ -63,6 +68,11 @@ type CreateOpts struct {
6368
// Only valid if action is REDIRECT_TO_URL.
6469
RedirectURL string `json:"redirect_url,omitempty"`
6570

71+
// Requests matching this policy will be redirected to the specified URL or Prefix URL
72+
// with the HTTP response code. Valid if action is REDIRECT_TO_URL or REDIRECT_PREFIX.
73+
// Valid options are: 301, 302, 303, 307, or 308. Default is 302. Requires version 2.9
74+
RedirectHttpCode int32 `json:"redirect_http_code,omitempty"`
75+
6676
// The administrative state of the Loadbalancer. A valid value is true (UP)
6777
// or false (DOWN).
6878
AdminStateUp *bool `json:"admin_state_up,omitempty"`
@@ -169,7 +179,7 @@ type UpdateOpts struct {
169179
// Name of the L7 policy, empty string is allowed.
170180
Name *string `json:"name,omitempty"`
171181

172-
// The L7 policy action. One of REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT.
182+
// The L7 policy action. One of REDIRECT_PREFIX, REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT.
173183
Action Action `json:"action,omitempty"`
174184

175185
// The position of this policy on the listener.
@@ -178,6 +188,10 @@ type UpdateOpts struct {
178188
// A human-readable description for the resource, empty string is allowed.
179189
Description *string `json:"description,omitempty"`
180190

191+
// Requests matching this policy will be redirected to this Prefix URL.
192+
// Only valid if action is REDIRECT_PREFIX.
193+
RedirectPrefix *string `json:"redirect_prefix,omitempty"`
194+
181195
// Requests matching this policy will be redirected to the pool with this ID.
182196
// Only valid if action is REDIRECT_TO_POOL.
183197
RedirectPoolID *string `json:"redirect_pool_id,omitempty"`
@@ -186,6 +200,11 @@ type UpdateOpts struct {
186200
// Only valid if action is REDIRECT_TO_URL.
187201
RedirectURL *string `json:"redirect_url,omitempty"`
188202

203+
// Requests matching this policy will be redirected to the specified URL or Prefix URL
204+
// with the HTTP response code. Valid if action is REDIRECT_TO_URL or REDIRECT_PREFIX.
205+
// Valid options are: 301, 302, 303, 307, or 308. Default is 302. Requires version 2.9
206+
RedirectHttpCode int32 `json:"redirect_http_code,omitempty"`
207+
189208
// The administrative state of the Loadbalancer. A valid value is true (UP)
190209
// or false (DOWN).
191210
AdminStateUp *bool `json:"admin_state_up,omitempty"`
@@ -208,6 +227,14 @@ func (opts UpdateOpts) ToL7PolicyUpdateMap() (map[string]interface{}, error) {
208227
m["redirect_url"] = nil
209228
}
210229

230+
if m["redirect_prefix"] == "" {
231+
m["redirect_prefix"] = nil
232+
}
233+
234+
if m["redirect_http_code"] == 0 {
235+
m["redirect_http_code"] = nil
236+
}
237+
211238
return b, nil
212239
}
213240

openstack/loadbalancer/v2/l7policies/results.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type L7Policy struct {
1717
// The ID of the listener.
1818
ListenerID string `json:"listener_id"`
1919

20-
// The L7 policy action. One of REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT.
20+
// The L7 policy action. One of REDIRECT_PREFIX, REDIRECT_TO_POOL, REDIRECT_TO_URL, or REJECT.
2121
Action string `json:"action"`
2222

2323
// The position of this policy on the listener.
@@ -34,10 +34,18 @@ type L7Policy struct {
3434
// Only valid if action is REDIRECT_TO_POOL.
3535
RedirectPoolID string `json:"redirect_pool_id"`
3636

37+
// Requests matching this policy will be redirected to this Prefix URL.
38+
// Only valid if action is REDIRECT_PREFIX.
39+
RedirectPrefix string `json:"redirect_prefix"`
40+
3741
// Requests matching this policy will be redirected to this URL.
3842
// Only valid if action is REDIRECT_TO_URL.
3943
RedirectURL string `json:"redirect_url"`
4044

45+
// Requests matching this policy will be redirected to the specified URL or Prefix URL
46+
// with the HTTP response code. Valid if action is REDIRECT_TO_URL or REDIRECT_PREFIX.
47+
RedirectHttpCode int32 `json:"redirect_http_code"`
48+
4149
// The administrative state of the L7 policy, which is up (true) or down (false).
4250
AdminStateUp bool `json:"admin_state_up"`
4351

0 commit comments

Comments
 (0)