1 """Elmax integration common classes and utilities."""
3 from __future__
import annotations
7 from elmax_api.model.panel
import PanelEntry
8 from packaging
import version
10 from .const
import ELMAX_LOCAL_API_PATH, MIN_APIV2_SUPPORTED_VERSION
14 """Return the direct API url given the base URI."""
15 schema =
"https" if use_ssl
else "http"
16 return f
"{schema}://{host}:{port}/{ELMAX_LOCAL_API_PATH}"
20 """Create a custom SSL context for direct-api verification."""
21 context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLS_CLIENT)
22 context.check_hostname =
False
23 context.verify_mode = ssl.CERT_REQUIRED
24 context.load_verify_locations(cadata=cadata)
29 """Check whether the given API version is supported."""
30 if api_version
is None:
32 return version.parse(api_version) >= version.parse(MIN_APIV2_SUPPORTED_VERSION)
36 """Helper class for wrapping a directly accessed Elmax Panel."""
39 """Construct the object."""
40 super().
__init__(panel_uri,
True, {})
43 """Return the panel name."""
44 return f
"Direct Panel {self.hash}"
None __init__(self, panel_uri)
str get_name_by_user(self, str username)
bool check_local_version_supported(str|None api_version)
ssl.SSLContext build_direct_ssl_context(str cadata)
str get_direct_api_url(str host, int port, bool use_ssl)