Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hcloud/load_balancers/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def _load_balancer_target(
redirect_http=service["http"]["redirect_http"],
cookie_name=service["http"]["cookie_name"],
cookie_lifetime=service["http"]["cookie_lifetime"],
timeout_idle=service["http"]["timeout_idle"],
)
tmp_service.http.certificates = [
BoundCertificate(
Expand Down
7 changes: 7 additions & 0 deletions hcloud/load_balancers/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ def to_payload(self) -> dict[str, Any]:
http["redirect_http"] = self.http.redirect_http
if self.http.sticky_sessions is not None:
http["sticky_sessions"] = self.http.sticky_sessions
if self.http.timeout_idle is not None:
http["timeout_idle"] = self.http.timeout_idle

http["certificates"] = [
certificate.id for certificate in self.http.certificates or []
Expand Down Expand Up @@ -272,6 +274,8 @@ class LoadBalancerServiceHttp(BaseDomain):
Redirect traffic from http port 80 to port 443
:param sticky_sessions: bool
Use sticky sessions. Only available if protocol is "http" or "https".
:param timeout_idle: int
Idle timeout in seconds for HTTP connections. Must be between 30 and 300 seconds.
"""

__api_properties__ = (
Expand All @@ -280,6 +284,7 @@ class LoadBalancerServiceHttp(BaseDomain):
"certificates",
"redirect_http",
"sticky_sessions",
"timeout_idle",
)
__slots__ = __api_properties__

Expand All @@ -290,12 +295,14 @@ def __init__(
certificates: list[BoundCertificate] | None = None,
redirect_http: bool | None = None,
sticky_sessions: bool | None = None,
timeout_idle: int | None = None,
):
self.cookie_name = cookie_name
self.cookie_lifetime = cookie_lifetime
self.certificates = certificates
self.redirect_http = redirect_http
self.sticky_sessions = sticky_sessions
self.timeout_idle = timeout_idle


class LoadBalancerHealthCheck(BaseDomain):
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/load_balancers/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def response_load_balancer():
"certificates": [897],
"redirect_http": True,
"sticky_sessions": True,
"timeout_idle": 60,
},
"health_check": {
"protocol": "http",
Expand Down Expand Up @@ -155,6 +156,7 @@ def response_create_load_balancer():
"certificates": [897],
"redirect_http": True,
"sticky_sessions": True,
"timeout_idle": 60,
},
"health_check": {
"protocol": "http",
Expand Down Expand Up @@ -253,6 +255,7 @@ def response_update_load_balancer():
"certificates": [897],
"redirect_http": True,
"sticky_sessions": True,
"timeout_idle": 60,
},
"health_check": {
"protocol": "http",
Expand Down Expand Up @@ -344,6 +347,7 @@ def response_simple_load_balancers():
"cookie_lifetime": 300,
"certificates": [897],
"redirect_http": True,
"timeout_idle": 60,
},
"health_check": {
"protocol": "http",
Expand Down Expand Up @@ -428,6 +432,7 @@ def response_simple_load_balancers():
"cookie_lifetime": 300,
"certificates": [897],
"redirect_http": True,
"timeout_idle": 60,
},
"health_check": {
"protocol": "http",
Expand Down
30 changes: 28 additions & 2 deletions tests/unit/load_balancers/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
LoadBalancerHealthCheck,
LoadBalancersClient,
LoadBalancerService,
LoadBalancerServiceHttp,
LoadBalancerTarget,
LoadBalancerTargetIP,
LoadBalancerTargetLabelSelector,
Expand Down Expand Up @@ -383,13 +384,38 @@ def test_add_service(
):
request_mock.return_value = response_add_service

service = LoadBalancerService(listen_port=80, protocol="http")
service = LoadBalancerService(
listen_port=80,
protocol="http",
destination_port=8080,
proxyprotocol=False,
http=LoadBalancerServiceHttp(
cookie_name="HCLBSTICKY",
cookie_lifetime=300,
redirect_http=True,
sticky_sessions=True,
timeout_idle=60,
),
)
action = resource_client.add_service(load_balancer, service)

request_mock.assert_called_with(
method="POST",
url="/load_balancers/1/actions/add_service",
json={"protocol": "http", "listen_port": 80},
json={
"protocol": "http",
"listen_port": 80,
"destination_port": 8080,
"proxyprotocol": False,
"http": {
"cookie_name": "HCLBSTICKY",
"cookie_lifetime": 300,
"redirect_http": True,
"sticky_sessions": True,
"timeout_idle": 60,
"certificates": [],
},
},
)

assert action.id == 13
Expand Down
Loading