11import ctypes
2+ import json
23from cryptlex .lexfloatclient import lexfloatclient_native as LexFloatClientNative
34from cryptlex .lexfloatclient .lexfloatstatus_codes import LexFloatStatusCodes
45from cryptlex .lexfloatclient .lexfloatclient_exception import LexFloatClientException
56
67callback_list = []
78
9+ class PermissionFlags :
10+ LF_USER = 10
11+ LF_ALL_USERS = 11
812
913class HostLicenseMeterAttribute (object ):
1014 def __init__ (self , name , allowed_uses , total_uses , gross_uses ):
@@ -19,6 +23,11 @@ def __init__(self, name, enabled, data):
1923 self .enabled = enabled
2024 self .data = data
2125
26+ class HostConfig (object ):
27+ def __init__ (self , max_offline_lease_duration ):
28+ self .max_offline_lease_duration = max_offline_lease_duration
29+
30+
2231class LexFloatClient :
2332 @staticmethod
2433 def SetHostProductId (product_id ):
@@ -100,6 +109,30 @@ def SetFloatingClientMetadata(key, value):
100109 cstring_key , cstring_value )
101110 if LexFloatStatusCodes .LF_OK != status :
102111 raise LexFloatClientException (status )
112+
113+ @staticmethod
114+ def SetPermissionFlag (flag ):
115+ """Sets the permission flag.
116+
117+ This function must be called on every start of your program after SetHostProductId()
118+ function in case the application allows borrowing of licenses or system wide activation.
119+
120+ Args:
121+ flags : depending on your application's requirements, choose one of
122+ the following values: LF_USER, LF_ALL_USERS.
123+
124+ LF_USER: This flag indicates that the application does not require
125+ admin or root permissions to run.
126+
127+ LF_ALL_USERS: This flag is specifically designed for Windows and should be used
128+ for system-wide activations.
129+
130+ Raises:
131+ LexFloatClientException
132+ """
133+ status = LexFloatClientNative .SetPermissionFlag (flag )
134+ if LexFloatStatusCodes .LF_OK != status :
135+ raise LexFloatClientException (status )
103136
104137 @staticmethod
105138 def GetFloatingClientLibraryVersion ():
@@ -117,7 +150,30 @@ def GetFloatingClientLibraryVersion():
117150 status = LexFloatClientNative .GetFloatingClientLibraryVersion (buffer ,buffer_size )
118151 if status != LexFloatStatusCodes .LF_OK :
119152 raise LexFloatClientException (status )
120- return LexFloatClientNative .byte_to_string (buffer .value )
153+ return LexFloatClientNative .byte_to_string (buffer .value )
154+
155+ @staticmethod
156+ def GetHostConfig ():
157+ """This function sends a network request to LexFloatServer to get the configuration details.
158+
159+ Raises:
160+ LexFloatClientException
161+
162+ Returns:
163+ HostConfig: host configuration.
164+ """
165+ buffer_size = 1024
166+ buffer = LexFloatClientNative .get_ctype_string_buffer (buffer_size )
167+ status = LexFloatClientNative .GetHostConfig (buffer , buffer_size )
168+ if status == LexFloatStatusCodes .LF_OK :
169+ host_config_json = LexFloatClientNative .byte_to_string (buffer .value )
170+ if not host_config_json .strip ():
171+ return None
172+ else :
173+ host_config = json .loads (host_config_json )
174+ return HostConfig (host_config ["maxOfflineLeaseDuration" ])
175+ else :
176+ raise LexFloatClientException (status )
121177
122178 @staticmethod
123179 def GetHostProductVersionName ():
@@ -244,6 +300,24 @@ def GetHostLicenseExpiryDate():
244300 return expiry_date .value
245301 else :
246302 raise LexFloatClientException (status )
303+
304+ @staticmethod
305+ def GetFloatingClientLeaseExpiryDate ():
306+ """Gets the lease expiry date timestamp of the floating client.
307+
308+ Raises:
309+ LexFloatClientException
310+
311+ Returns:
312+ int: the timestamp
313+ """
314+ leaseExpiryDate = ctypes .c_uint ()
315+ status = LexFloatClientNative .GetFloatingClientLeaseExpiryDate (
316+ ctypes .byref (leaseExpiryDate ))
317+ if status == LexFloatStatusCodes .LF_OK :
318+ return leaseExpiryDate .value
319+ else :
320+ raise LexFloatClientException (status )
247321
248322 @staticmethod
249323 def GetFloatingClientMeterAttributeUses (name ):
@@ -267,6 +341,28 @@ def GetFloatingClientMeterAttributeUses(name):
267341 else :
268342 raise LexFloatClientException (status )
269343
344+ @staticmethod
345+ def GetFloatingClientMetadata (key ):
346+ """Gets the value of the floating client metadata.
347+
348+ Args:
349+ key (str): metadata key to retrieve the value
350+
351+ Raises:
352+ LexFloatClientException
353+
354+ Returns:
355+ str: value of the floating client metadata
356+ """
357+ cstring_key = LexFloatClientNative .get_ctype_string (key )
358+ buffer_size = 4096
359+ buffer = LexFloatClientNative .get_ctype_string_buffer (buffer_size )
360+ status = LexFloatClientNative .GetFloatingClientMetadata (
361+ cstring_key , buffer , buffer_size )
362+ if status != LexFloatStatusCodes .LF_OK :
363+ raise LexFloatClientException (status )
364+ return LexFloatClientNative .byte_to_string (buffer .value )
365+
270366 @staticmethod
271367 def RequestFloatingLicense ():
272368 """Sends the request to lease the license from the LexFloatServer.
@@ -291,7 +387,7 @@ def RequestOfflineFloatingLicense(lease_duration):
291387 status = LexFloatClientNative .RequestOfflineFloatingLicense (lease_duration )
292388 if LexFloatStatusCodes .LF_OK != status :
293389 raise LexFloatClientException (status )
294-
390+
295391 @staticmethod
296392 def DropFloatingLicense ():
297393 """Sends the request to the LexFloatServer to free the license.
@@ -320,6 +416,8 @@ def HasFloatingLicense():
320416 return True
321417 elif LexFloatStatusCodes .LF_E_NO_LICENSE == status :
322418 return False
419+ elif LexFloatStatusCodes .LF_FAIL == status :
420+ return False
323421 else :
324422 raise LexFloatClientException (status )
325423
0 commit comments