Skip to content

Commit 467d968

Browse files
authored
Merge pull request #9 from cryptlex/muneeb/get-host-config
Add get-host-config function
2 parents a48b5f1 + 096c864 commit 467d968

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
@@ -22,6 +23,11 @@ def __init__(self, name, enabled, data):
2223
self.enabled = enabled
2324
self.data = data
2425

26+
class HostConfig(object):
27+
def __init__(self, max_offline_lease_duration):
28+
self.max_offline_lease_duration = max_offline_lease_duration
29+
30+
2531
class LexFloatClient:
2632
@staticmethod
2733
def SetHostProductId(product_id):
@@ -120,7 +126,30 @@ def GetFloatingClientLibraryVersion():
120126
status = LexFloatClientNative.GetFloatingClientLibraryVersion(buffer,buffer_size)
121127
if status != LexFloatStatusCodes.LF_OK:
122128
raise LexFloatClientException(status)
123-
return LexFloatClientNative.byte_to_string(buffer.value)
129+
return LexFloatClientNative.byte_to_string(buffer.value)
130+
131+
@staticmethod
132+
def GetHostConfig():
133+
"""This function sends a network request to LexFloatServer to get the configuration details.
134+
135+
Raises:
136+
LexFloatClientException
137+
138+
Returns:
139+
HostConfig: host configuration.
140+
"""
141+
buffer_size = 1024
142+
buffer = LexFloatClientNative.get_ctype_string_buffer(buffer_size)
143+
status = LexFloatClientNative.GetHostConfig(buffer, buffer_size)
144+
if status == LexFloatStatusCodes.LF_OK:
145+
host_config_json = LexFloatClientNative.byte_to_string(buffer.value)
146+
if not host_config_json.strip():
147+
return None
148+
else:
149+
host_config = json.loads(host_config_json)
150+
return HostConfig(host_config["maxOfflineLeaseDuration"])
151+
else:
152+
raise LexFloatClientException(status)
124153

125154
@staticmethod
126155
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)