From ad13cd76fa029bb3405dada618f0a0241dd4c1e6 Mon Sep 17 00:00:00 2001 From: muneebkq Date: Tue, 16 Jul 2024 10:45:49 +0530 Subject: [PATCH 1/3] feat: add get-host-config function --- cryptlex/lexfloatclient/lexfloatclient.py | 31 ++++++++++++++++++- .../lexfloatclient/lexfloatclient_native.py | 4 +++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cryptlex/lexfloatclient/lexfloatclient.py b/cryptlex/lexfloatclient/lexfloatclient.py index 13f2e2c..961ffb9 100644 --- a/cryptlex/lexfloatclient/lexfloatclient.py +++ b/cryptlex/lexfloatclient/lexfloatclient.py @@ -1,4 +1,5 @@ import ctypes +import json from cryptlex.lexfloatclient import lexfloatclient_native as LexFloatClientNative from cryptlex.lexfloatclient.lexfloatstatus_codes import LexFloatStatusCodes from cryptlex.lexfloatclient.lexfloatclient_exception import LexFloatClientException @@ -19,6 +20,11 @@ def __init__(self, name, enabled, data): self.enabled = enabled self.data = data +class HostConfig(object): + def __init__(self, hostConfig): + self.maxOfflineLeaseDuration = hostConfig.get("maxOfflineLeaseDuration") + + class LexFloatClient: @staticmethod def SetHostProductId(product_id): @@ -117,7 +123,30 @@ def GetFloatingClientLibraryVersion(): status = LexFloatClientNative.GetFloatingClientLibraryVersion(buffer,buffer_size) if status != LexFloatStatusCodes.LF_OK: raise LexFloatClientException(status) - return LexFloatClientNative.byte_to_string(buffer.value) + return LexFloatClientNative.byte_to_string(buffer.value) + + @staticmethod + def GetHostConfig(): + """Gets the host configuration. + + Raises: + LexFloatClientException + + Returns: + str: host configuration. + """ + buffer_size = 4096 + buffer = LexFloatClientNative.get_ctype_string_buffer(buffer_size) + status = LexFloatClientNative.GetHostConfig(buffer, buffer_size) + if status == LexFloatStatusCodes.LF_OK: + host_config_json = LexFloatClientNative.byte_to_string(buffer.value) + if not host_config_json.strip(): + return [] + else: + host_config = json.loads(host_config_json) + return [HostConfig(host_config_details) for host_config_details in host_config] + else: + raise LexFloatClientException(status) @staticmethod def GetHostProductVersionName(): diff --git a/cryptlex/lexfloatclient/lexfloatclient_native.py b/cryptlex/lexfloatclient/lexfloatclient_native.py index e116d62..5a0eed7 100644 --- a/cryptlex/lexfloatclient/lexfloatclient_native.py +++ b/cryptlex/lexfloatclient/lexfloatclient_native.py @@ -143,6 +143,10 @@ def byte_to_string(input): GetHostProductVersionFeatureFlag.argtypes = [CSTRTYPE, POINTER(c_uint32), STRTYPE, c_uint32] GetHostProductVersionFeatureFlag.restype = c_int +GetHostConfig = library.GetHostConfigInternal +GetHostConfig.argtypes = [STRTYPE, c_uint32] +GetHostConfig.restype = c_int + GetHostLicenseMetadata = library.GetHostLicenseMetadata GetHostLicenseMetadata.argtypes = [CSTRTYPE, STRTYPE, c_uint32] GetHostLicenseMetadata.restype = c_int From 8723c2619a2087e8178c6a2f2fa56a261c4fc9df Mon Sep 17 00:00:00 2001 From: muneebkq Date: Tue, 30 Jul 2024 14:42:16 +0530 Subject: [PATCH 2/3] fix: change type defintion --- cryptlex/lexfloatclient/lexfloatclient.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cryptlex/lexfloatclient/lexfloatclient.py b/cryptlex/lexfloatclient/lexfloatclient.py index 961ffb9..38c2a80 100644 --- a/cryptlex/lexfloatclient/lexfloatclient.py +++ b/cryptlex/lexfloatclient/lexfloatclient.py @@ -21,8 +21,8 @@ def __init__(self, name, enabled, data): self.data = data class HostConfig(object): - def __init__(self, hostConfig): - self.maxOfflineLeaseDuration = hostConfig.get("maxOfflineLeaseDuration") + def __init__(self, maxOfflineLeaseDuration): + self.maxOfflineLeaseDuration = maxOfflineLeaseDuration class LexFloatClient: @@ -133,18 +133,18 @@ def GetHostConfig(): LexFloatClientException Returns: - str: host configuration. + HostConfig: host configuration. """ - buffer_size = 4096 + buffer_size = 1024 buffer = LexFloatClientNative.get_ctype_string_buffer(buffer_size) status = LexFloatClientNative.GetHostConfig(buffer, buffer_size) if status == LexFloatStatusCodes.LF_OK: host_config_json = LexFloatClientNative.byte_to_string(buffer.value) if not host_config_json.strip(): - return [] + return None else: host_config = json.loads(host_config_json) - return [HostConfig(host_config_details) for host_config_details in host_config] + return HostConfig(host_config["maxOfflineLeaseDuration"]) else: raise LexFloatClientException(status) From 096c864663fea4f43cf02a92755ab0eacd0c00ca Mon Sep 17 00:00:00 2001 From: muneebkq Date: Fri, 2 Aug 2024 14:19:00 +0530 Subject: [PATCH 3/3] refactor: arg format chnaged to snakecase --- cryptlex/lexfloatclient/lexfloatclient.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cryptlex/lexfloatclient/lexfloatclient.py b/cryptlex/lexfloatclient/lexfloatclient.py index 38c2a80..12233b1 100644 --- a/cryptlex/lexfloatclient/lexfloatclient.py +++ b/cryptlex/lexfloatclient/lexfloatclient.py @@ -21,8 +21,8 @@ def __init__(self, name, enabled, data): self.data = data class HostConfig(object): - def __init__(self, maxOfflineLeaseDuration): - self.maxOfflineLeaseDuration = maxOfflineLeaseDuration + def __init__(self, max_offline_lease_duration): + self.max_offline_lease_duration = max_offline_lease_duration class LexFloatClient: @@ -127,7 +127,7 @@ def GetFloatingClientLibraryVersion(): @staticmethod def GetHostConfig(): - """Gets the host configuration. + """This function sends a network request to LexFloatServer to get the configuration details. Raises: LexFloatClientException