88
99import httpx
1010
11+ from ._api import OpenvasdAPI
1112
12- class HealthAPI :
13+
14+ class HealthAPI (OpenvasdAPI ):
1315 """
1416 Provides access to the openvasd /health endpoints, which expose the
1517 operational state of the scanner.
@@ -18,28 +20,16 @@ class HealthAPI:
1820 if the server returns an error response (4xx or 5xx).
1921 """
2022
21- def __init__ (self , client : httpx .Client ):
22- """
23- Create a new HealthAPI instance.
24-
25- Args:
26- client: An initialized `httpx.Client` configured for communicating
27- with the openvasd server.
28- """
29- self ._client = client
30-
31- def get_alive (self , safe : bool = False ) -> int :
23+ def get_alive (self ) -> int :
3224 """
3325 Check if the scanner process is alive.
3426
35- Args:
36- safe: If True, suppress exceptions and return structured error responses.
37-
3827 Returns:
3928 HTTP status code (e.g., 200 if alive).
4029
4130 Raises:
42- httpx.HTTPStatusError: If the server response indicates failure and safe is False.
31+ httpx.HTTPStatusError: If the server response indicates failure and
32+ exceptions are not suppressed.
4333
4434 See: GET /health/alive in the openvasd API documentation.
4535 """
@@ -48,22 +38,20 @@ def get_alive(self, safe: bool = False) -> int:
4838 response .raise_for_status ()
4939 return response .status_code
5040 except httpx .HTTPStatusError as e :
51- if safe :
41+ if self . _suppress_exceptions :
5242 return e .response .status_code
5343 raise
5444
55- def get_ready (self , safe : bool = False ) -> int :
45+ def get_ready (self ) -> int :
5646 """
5747 Check if the scanner is ready to accept requests (e.g., feed loaded).
5848
59- Args:
60- safe: If True, suppress exceptions and return structured error responses.
61-
6249 Returns:
6350 HTTP status code (e.g., 200 if ready).
6451
6552 Raises:
66- httpx.HTTPStatusError: If the server response indicates failure and safe is False.
53+ httpx.HTTPStatusError: If the server response indicates failure and
54+ exceptions are not suppressed.
6755
6856 See: GET /health/ready in the openvasd API documentation.
6957 """
@@ -72,22 +60,20 @@ def get_ready(self, safe: bool = False) -> int:
7260 response .raise_for_status ()
7361 return response .status_code
7462 except httpx .HTTPStatusError as e :
75- if safe :
63+ if self . _suppress_exceptions :
7664 return e .response .status_code
7765 raise
7866
79- def get_started (self , safe : bool = False ) -> int :
67+ def get_started (self ) -> int :
8068 """
8169 Check if the scanner has fully started.
8270
83- Args:
84- safe: If True, suppress exceptions and return structured error responses.
85-
8671 Returns:
8772 HTTP status code (e.g., 200 if started).
8873
8974 Raises:
90- httpx.HTTPStatusError: If the server response indicates failure and safe is False.
75+ httpx.HTTPStatusError: If the server response indicates failure and
76+ exceptions are not suppressed.
9177
9278 See: GET /health/started in the openvasd API documentation.
9379 """
@@ -96,6 +82,6 @@ def get_started(self, safe: bool = False) -> int:
9682 response .raise_for_status ()
9783 return response .status_code
9884 except httpx .HTTPStatusError as e :
99- if safe :
85+ if self . _suppress_exceptions :
10086 return e .response .status_code
10187 raise
0 commit comments