Skip to content

Commit ad13cd7

Browse files
committed
feat: add get-host-config function
1 parent 6f28501 commit ad13cd7

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

cryptlex/lexfloatclient/lexfloatclient.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ctypes
2+
import json
23
from cryptlex.lexfloatclient import lexfloatclient_native as LexFloatClientNative
34
from cryptlex.lexfloatclient.lexfloatstatus_codes import LexFloatStatusCodes
45
from cryptlex.lexfloatclient.lexfloatclient_exception import LexFloatClientException
@@ -19,6 +20,11 @@ def __init__(self, name, enabled, data):
1920
self.enabled = enabled
2021
self.data = data
2122

23+
class HostConfig(object):
24+
def __init__(self, hostConfig):
25+
self.maxOfflineLeaseDuration = hostConfig.get("maxOfflineLeaseDuration")
26+
27+
2228
class LexFloatClient:
2329
@staticmethod
2430
def SetHostProductId(product_id):
@@ -117,7 +123,30 @@ def GetFloatingClientLibraryVersion():
117123
status = LexFloatClientNative.GetFloatingClientLibraryVersion(buffer,buffer_size)
118124
if status != LexFloatStatusCodes.LF_OK:
119125
raise LexFloatClientException(status)
120-
return LexFloatClientNative.byte_to_string(buffer.value)
126+
return LexFloatClientNative.byte_to_string(buffer.value)
127+
128+
@staticmethod
129+
def GetHostConfig():
130+
"""Gets the host configuration.
131+
132+
Raises:
133+
LexFloatClientException
134+
135+
Returns:
136+
str: host configuration.
137+
"""
138+
buffer_size = 4096
139+
buffer = LexFloatClientNative.get_ctype_string_buffer(buffer_size)
140+
status = LexFloatClientNative.GetHostConfig(buffer, buffer_size)
141+
if status == LexFloatStatusCodes.LF_OK:
142+
host_config_json = LexFloatClientNative.byte_to_string(buffer.value)
143+
if not host_config_json.strip():
144+
return []
145+
else:
146+
host_config = json.loads(host_config_json)
147+
return [HostConfig(host_config_details) for host_config_details in host_config]
148+
else:
149+
raise LexFloatClientException(status)
121150

122151
@staticmethod
123152
def GetHostProductVersionName():

cryptlex/lexfloatclient/lexfloatclient_native.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ def byte_to_string(input):
143143
GetHostProductVersionFeatureFlag.argtypes = [CSTRTYPE, POINTER(c_uint32), STRTYPE, c_uint32]
144144
GetHostProductVersionFeatureFlag.restype = c_int
145145

146+
GetHostConfig = library.GetHostConfigInternal
147+
GetHostConfig.argtypes = [STRTYPE, c_uint32]
148+
GetHostConfig.restype = c_int
149+
146150
GetHostLicenseMetadata = library.GetHostLicenseMetadata
147151
GetHostLicenseMetadata.argtypes = [CSTRTYPE, STRTYPE, c_uint32]
148152
GetHostLicenseMetadata.restype = c_int

0 commit comments

Comments
 (0)