Skip to content

Commit

Permalink
feat(lbaas): add support for lb redirect rule status (#351)
Browse files Browse the repository at this point in the history
* feat(lbaas): add support for lb redirect rule status

* chore: update version in `User-Agent`

* Update CHANGELOG.md

Co-authored-by: Ville Välimäki <[email protected]>

* chore: no need to update user agent version

---------

Co-authored-by: paketeserrano <[email protected]>
Co-authored-by: Ville Välimäki <[email protected]>
  • Loading branch information
3 people authored Jan 30, 2025
1 parent bbf5644 commit ebdb329
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Added
- managed load balancer: support for redirect rule HTTP status

## [8.14.0]

### Added
Expand Down
1 change: 1 addition & 0 deletions upcloud/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ type LoadBalancerActionHTTPReturn struct {
type LoadBalancerActionHTTPRedirect struct {
Location string `json:"location,omitempty"`
Scheme LoadBalancerActionHTTPRedirectScheme `json:"scheme,omitempty"`
Status int `json:"status,omitempty"`
}

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

func NewLoadBalancerHTTPRedirectActionWithStatus(location string, status int) upcloud.LoadBalancerAction {
return upcloud.LoadBalancerAction{
Type: upcloud.LoadBalancerActionTypeHTTPRedirect,
HTTPRedirect: &upcloud.LoadBalancerActionHTTPRedirect{
Location: location,
Status: status,
},
}
}

func NewLoadBalancerHTTPRedirectSchemeAction(scheme upcloud.LoadBalancerActionHTTPRedirectScheme) upcloud.LoadBalancerAction {
return upcloud.LoadBalancerAction{
Type: upcloud.LoadBalancerActionTypeHTTPRedirect,
Expand All @@ -40,6 +50,16 @@ func NewLoadBalancerHTTPRedirectSchemeAction(scheme upcloud.LoadBalancerActionHT
}
}

func NewLoadBalancerHTTPRedirectSchemeActionWithStatus(scheme upcloud.LoadBalancerActionHTTPRedirectScheme, status int) upcloud.LoadBalancerAction {
return upcloud.LoadBalancerAction{
Type: upcloud.LoadBalancerActionTypeHTTPRedirect,
HTTPRedirect: &upcloud.LoadBalancerActionHTTPRedirect{
Scheme: scheme,
Status: status,
},
}
}

func NewLoadBalancerUseBackendAction(name string) upcloud.LoadBalancerAction {
return upcloud.LoadBalancerAction{
Type: upcloud.LoadBalancerActionTypeUseBackend,
Expand Down
18 changes: 17 additions & 1 deletion upcloud/request/load_balancer_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,21 @@ func TestMatcheresAndActionsHelper(t *testing.T) {
"action_http_redirect": {
"scheme": "https"
}
}
},
{
"type": "http_redirect",
"action_http_redirect": {
"location": "https://internal.example.com",
"status": 301
}
},
{
"type": "http_redirect",
"action_http_redirect": {
"scheme": "https",
"status": 302
}
}
]
}
`
Expand Down Expand Up @@ -185,6 +199,8 @@ func TestMatcheresAndActionsHelper(t *testing.T) {
NewLoadBalancerHTTPReturnAction(200, "text/html", "PGgxPmFwcGxlYmVlPC9oMT4K"),
NewLoadBalancerHTTPRedirectAction("https://internal.example.com"),
NewLoadBalancerHTTPRedirectSchemeAction(upcloud.LoadBalancerActionHTTPRedirectSchemeHTTPS),
NewLoadBalancerHTTPRedirectActionWithStatus("https://internal.example.com", 301),
NewLoadBalancerHTTPRedirectSchemeActionWithStatus(upcloud.LoadBalancerActionHTTPRedirectSchemeHTTPS, 302),
},
}
actual, err := json.Marshal(&r)
Expand Down

0 comments on commit ebdb329

Please sign in to comment.