Skip to content

Commit e05b2f1

Browse files
authored
feat(lbaas): add Scheme property to http_redirect action (#193)
1 parent 61669a1 commit e05b2f1

4 files changed

Lines changed: 24 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)
77

88
### Added
99
- experimental support for Managed Redis Database
10+
- load-balancer: add `Scheme` property to front-end rule HTTP redirect action.
1011

1112
## [5.1.0]
1213

upcloud/load_balancer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type (
88
LoadBalancerMode string
99
LoadBalancerMatcherType string
1010
LoadBalancerActionType string
11+
LoadBalancerActionHTTPRedirectScheme string
1112
LoadBalancerStringMatcherMethod string
1213
LoadBalancerHTTPMatcherMethod string
1314
LoadBalancerIntegerMatcherMethod string
@@ -73,6 +74,9 @@ const (
7374
LoadBalancerActionTypeHTTPRedirect LoadBalancerActionType = "http_redirect"
7475
LoadBalancerActionTypeSetForwardedHeaders LoadBalancerActionType = "set_forwarded_headers"
7576

77+
LoadBalancerActionHTTPRedirectSchemeHTTP LoadBalancerActionHTTPRedirectScheme = "http"
78+
LoadBalancerActionHTTPRedirectSchemeHTTPS LoadBalancerActionHTTPRedirectScheme = "https"
79+
7680
LoadBalancerStringMatcherMethodExact LoadBalancerStringMatcherMethod = "exact"
7781
LoadBalancerStringMatcherMethodSubstring LoadBalancerStringMatcherMethod = "substring"
7882
LoadBalancerStringMatcherMethodRegexp LoadBalancerStringMatcherMethod = "regexp"
@@ -323,9 +327,10 @@ type LoadBalancerActionHTTPReturn struct {
323327
Payload string `json:"payload,omitempty"`
324328
}
325329

326-
// LoadBalancerActionHTTPRedirect represents 'http_redirect' action
330+
// LoadBalancerActionHTTPRedirect represents 'http_redirect' action. Only either Location or Scheme should be defined.
327331
type LoadBalancerActionHTTPRedirect struct {
328-
Location string `json:"location,omitempty"`
332+
Location string `json:"location,omitempty"`
333+
Scheme LoadBalancerActionHTTPRedirectScheme `json:"scheme,omitempty"`
329334
}
330335

331336
// LoadBalancerActionSetForwardedHeaders represents 'set_forwarded_headers' action

upcloud/request/load_balancer_helpers.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ func NewLoadBalancerHTTPRedirectAction(location string) upcloud.LoadBalancerActi
3131
}
3232
}
3333

34+
func NewLoadBalancerHTTPRedirectSchemeAction(scheme upcloud.LoadBalancerActionHTTPRedirectScheme) upcloud.LoadBalancerAction {
35+
return upcloud.LoadBalancerAction{
36+
Type: upcloud.LoadBalancerActionTypeHTTPRedirect,
37+
HTTPRedirect: &upcloud.LoadBalancerActionHTTPRedirect{
38+
Scheme: scheme,
39+
},
40+
}
41+
}
42+
3443
func NewLoadBalancerUseBackendAction(name string) upcloud.LoadBalancerAction {
3544
return upcloud.LoadBalancerAction{
3645
Type: upcloud.LoadBalancerActionTypeUseBackend,

upcloud/request/load_balancer_helpers_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ func TestMatcheresAndActionsHelper(t *testing.T) {
141141
"action_http_redirect": {
142142
"location": "https://internal.example.com"
143143
}
144+
},
145+
{
146+
"type": "http_redirect",
147+
"action_http_redirect": {
148+
"scheme": "https"
149+
}
144150
}
145151
]
146152
}
@@ -169,6 +175,7 @@ func TestMatcheresAndActionsHelper(t *testing.T) {
169175
NewLoadBalancerTCPRejectAction(),
170176
NewLoadBalancerHTTPReturnAction(200, "text/html", "PGgxPmFwcGxlYmVlPC9oMT4K"),
171177
NewLoadBalancerHTTPRedirectAction("https://internal.example.com"),
178+
NewLoadBalancerHTTPRedirectSchemeAction(upcloud.LoadBalancerActionHTTPRedirectSchemeHTTPS),
172179
},
173180
}
174181
actual, err := json.Marshal(&r)

0 commit comments

Comments
 (0)