Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get-host-config function #9

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion cryptlex/lexfloatclient/lexfloatclient.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muneebkq In Python, the snake case is commonly followed. Please update the above.


class LexFloatClient:
@staticmethod
def SetHostProductId(product_id):
Expand Down Expand Up @@ -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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muneebkq This line in docs is missing:

This function sends a network request to LexFloatServer to get the configuration details.

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():
Expand Down
4 changes: 4 additions & 0 deletions cryptlex/lexfloatclient/lexfloatclient_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down