1
1
import ctypes
2
+ import json
2
3
from cryptlex .lexfloatclient import lexfloatclient_native as LexFloatClientNative
3
4
from cryptlex .lexfloatclient .lexfloatstatus_codes import LexFloatStatusCodes
4
5
from cryptlex .lexfloatclient .lexfloatclient_exception import LexFloatClientException
5
6
6
7
callback_list = []
7
8
9
+ class PermissionFlags :
10
+ LF_USER = 10
11
+ LF_ALL_USERS = 11
8
12
9
13
class HostLicenseMeterAttribute (object ):
10
14
def __init__ (self , name , allowed_uses , total_uses , gross_uses ):
@@ -19,6 +23,11 @@ def __init__(self, name, enabled, data):
19
23
self .enabled = enabled
20
24
self .data = data
21
25
26
+ class HostConfig (object ):
27
+ def __init__ (self , max_offline_lease_duration ):
28
+ self .max_offline_lease_duration = max_offline_lease_duration
29
+
30
+
22
31
class LexFloatClient :
23
32
@staticmethod
24
33
def SetHostProductId (product_id ):
@@ -100,6 +109,30 @@ def SetFloatingClientMetadata(key, value):
100
109
cstring_key , cstring_value )
101
110
if LexFloatStatusCodes .LF_OK != status :
102
111
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 )
103
136
104
137
@staticmethod
105
138
def GetFloatingClientLibraryVersion ():
@@ -117,7 +150,30 @@ def GetFloatingClientLibraryVersion():
117
150
status = LexFloatClientNative .GetFloatingClientLibraryVersion (buffer ,buffer_size )
118
151
if status != LexFloatStatusCodes .LF_OK :
119
152
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 )
121
177
122
178
@staticmethod
123
179
def GetHostProductVersionName ():
@@ -244,6 +300,24 @@ def GetHostLicenseExpiryDate():
244
300
return expiry_date .value
245
301
else :
246
302
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 )
247
321
248
322
@staticmethod
249
323
def GetFloatingClientMeterAttributeUses (name ):
@@ -267,6 +341,28 @@ def GetFloatingClientMeterAttributeUses(name):
267
341
else :
268
342
raise LexFloatClientException (status )
269
343
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
+
270
366
@staticmethod
271
367
def RequestFloatingLicense ():
272
368
"""Sends the request to lease the license from the LexFloatServer.
@@ -291,7 +387,7 @@ def RequestOfflineFloatingLicense(lease_duration):
291
387
status = LexFloatClientNative .RequestOfflineFloatingLicense (lease_duration )
292
388
if LexFloatStatusCodes .LF_OK != status :
293
389
raise LexFloatClientException (status )
294
-
390
+
295
391
@staticmethod
296
392
def DropFloatingLicense ():
297
393
"""Sends the request to the LexFloatServer to free the license.
@@ -320,6 +416,8 @@ def HasFloatingLicense():
320
416
return True
321
417
elif LexFloatStatusCodes .LF_E_NO_LICENSE == status :
322
418
return False
419
+ elif LexFloatStatusCodes .LF_FAIL == status :
420
+ return False
323
421
else :
324
422
raise LexFloatClientException (status )
325
423
0 commit comments