Skip to content

Commit a3ab01a

Browse files
committed
feat: add support for Hetzner API endpoint
Adds support for the new Hetzner API endpoint.
1 parent 8596737 commit a3ab01a

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

hcloud/_client.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,14 @@ def __init__(
129129
poll_interval: int | float | BackoffFunction = 1.0,
130130
poll_max_retries: int = 120,
131131
timeout: float | tuple[float, float] | None = None,
132+
*,
133+
api_endpoint_hetzner: str = "https://api.hetzner.com/v1",
132134
):
133135
"""Create a new Client instance
134136
135137
:param token: Hetzner Cloud API token
136138
:param api_endpoint: Hetzner Cloud API endpoint
139+
:param api_endpoint_hetzner: Hetzner API endpoint.
137140
:param application_name: Your application name
138141
:param application_version: Your application _version
139142
:param poll_interval:
@@ -145,6 +148,7 @@ def __init__(
145148
"""
146149
self.token = token
147150
self._api_endpoint = api_endpoint
151+
self._api_endpoint_hetzner = api_endpoint_hetzner
148152
self._application_name = application_name
149153
self._application_version = application_version
150154
self._requests_session = requests.Session()
@@ -276,14 +280,43 @@ def request( # type: ignore[no-untyped-def]
276280
) -> dict:
277281
"""Perform a request to the Hetzner Cloud API, wrapper around requests.request
278282
279-
:param method: HTTP Method to perform the Request
280-
:param url: URL of the Endpoint
283+
:param method: HTTP Method to perform the request
284+
:param url: URL of the endpoint
285+
:param timeout: Requests timeout in seconds
286+
:return: Response
287+
"""
288+
return self._request(method, self._api_endpoint + url, **kwargs)
289+
290+
def _request_hetzner( # type: ignore[no-untyped-def]
291+
self,
292+
method: str,
293+
url: str,
294+
**kwargs,
295+
) -> dict:
296+
"""Perform a request to the Hetzner API, wrapper around requests.request
297+
298+
:param method: HTTP Method to perform the request
299+
:param url: URL of the endpoint
300+
:param timeout: Requests timeout in seconds
301+
:return: Response
302+
"""
303+
return self._request(method, self._api_endpoint_hetzner + url, **kwargs)
304+
305+
def _request( # type: ignore[no-untyped-def]
306+
self,
307+
method: str,
308+
url: str,
309+
**kwargs,
310+
) -> dict:
311+
"""Perform a request to the provided URL, wrapper around requests.request
312+
313+
:param method: HTTP Method to perform the request
314+
:param url: URL to perform the request
281315
:param timeout: Requests timeout in seconds
282316
:return: Response
283317
"""
284318
kwargs.setdefault("timeout", self._requests_timeout)
285319

286-
url = self._api_endpoint + url
287320
headers = self._get_headers()
288321

289322
retries = 0

0 commit comments

Comments
 (0)