Skip to content

Commit

Permalink
feat(lbaas): add Scheme property to http_redirect action (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta authored Dec 16, 2022
1 parent 61669a1 commit e05b2f1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)

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

## [5.1.0]

Expand Down
9 changes: 7 additions & 2 deletions upcloud/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type (
LoadBalancerMode string
LoadBalancerMatcherType string
LoadBalancerActionType string
LoadBalancerActionHTTPRedirectScheme string
LoadBalancerStringMatcherMethod string
LoadBalancerHTTPMatcherMethod string
LoadBalancerIntegerMatcherMethod string
Expand Down Expand Up @@ -73,6 +74,9 @@ const (
LoadBalancerActionTypeHTTPRedirect LoadBalancerActionType = "http_redirect"
LoadBalancerActionTypeSetForwardedHeaders LoadBalancerActionType = "set_forwarded_headers"

LoadBalancerActionHTTPRedirectSchemeHTTP LoadBalancerActionHTTPRedirectScheme = "http"
LoadBalancerActionHTTPRedirectSchemeHTTPS LoadBalancerActionHTTPRedirectScheme = "https"

LoadBalancerStringMatcherMethodExact LoadBalancerStringMatcherMethod = "exact"
LoadBalancerStringMatcherMethodSubstring LoadBalancerStringMatcherMethod = "substring"
LoadBalancerStringMatcherMethodRegexp LoadBalancerStringMatcherMethod = "regexp"
Expand Down Expand Up @@ -323,9 +327,10 @@ type LoadBalancerActionHTTPReturn struct {
Payload string `json:"payload,omitempty"`
}

// LoadBalancerActionHTTPRedirect represents 'http_redirect' action
// LoadBalancerActionHTTPRedirect represents 'http_redirect' action. Only either Location or Scheme should be defined.
type LoadBalancerActionHTTPRedirect struct {
Location string `json:"location,omitempty"`
Location string `json:"location,omitempty"`
Scheme LoadBalancerActionHTTPRedirectScheme `json:"scheme,omitempty"`
}

// LoadBalancerActionSetForwardedHeaders represents 'set_forwarded_headers' action
Expand Down
9 changes: 9 additions & 0 deletions upcloud/request/load_balancer_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ func NewLoadBalancerHTTPRedirectAction(location string) upcloud.LoadBalancerActi
}
}

func NewLoadBalancerHTTPRedirectSchemeAction(scheme upcloud.LoadBalancerActionHTTPRedirectScheme) upcloud.LoadBalancerAction {
return upcloud.LoadBalancerAction{
Type: upcloud.LoadBalancerActionTypeHTTPRedirect,
HTTPRedirect: &upcloud.LoadBalancerActionHTTPRedirect{
Scheme: scheme,
},
}
}

func NewLoadBalancerUseBackendAction(name string) upcloud.LoadBalancerAction {
return upcloud.LoadBalancerAction{
Type: upcloud.LoadBalancerActionTypeUseBackend,
Expand Down
7 changes: 7 additions & 0 deletions upcloud/request/load_balancer_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ func TestMatcheresAndActionsHelper(t *testing.T) {
"action_http_redirect": {
"location": "https://internal.example.com"
}
},
{
"type": "http_redirect",
"action_http_redirect": {
"scheme": "https"
}
}
]
}
Expand Down Expand Up @@ -169,6 +175,7 @@ func TestMatcheresAndActionsHelper(t *testing.T) {
NewLoadBalancerTCPRejectAction(),
NewLoadBalancerHTTPReturnAction(200, "text/html", "PGgxPmFwcGxlYmVlPC9oMT4K"),
NewLoadBalancerHTTPRedirectAction("https://internal.example.com"),
NewLoadBalancerHTTPRedirectSchemeAction(upcloud.LoadBalancerActionHTTPRedirectSchemeHTTPS),
},
}
actual, err := json.Marshal(&r)
Expand Down

0 comments on commit e05b2f1

Please sign in to comment.