diff --git a/cryptlex/lexfloatclient/lexfloatclient.py b/cryptlex/lexfloatclient/lexfloatclient.py index 13f2e2c..12233b1 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, max_offline_lease_duration): + self.max_offline_lease_duration = max_offline_lease_duration + + 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(): + """This function sends a network request to LexFloatServer to get the configuration details. + + Raises: + LexFloatClientException + + Returns: + HostConfig: host configuration. + """ + 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 None + else: + host_config = json.loads(host_config_json) + return HostConfig(host_config["maxOfflineLeaseDuration"]) + 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