11import ctypes
22import json
3+ import functools
4+ import warnings
35from cryptlex .lexfloatclient import lexfloatclient_native as LexFloatClientNative
46from cryptlex .lexfloatclient .lexfloatstatus_codes import LexFloatStatusCodes
57from cryptlex .lexfloatclient .lexfloatclient_exception import LexFloatClientException
68
79callback_list = []
810
11+ def deprecated (alternative ):
12+ """This is a decorator which can be used to mark functions as deprecated.
13+ It will result in a warning being emitted when the function is used.
14+
15+ Args:
16+ alternative (str): Name of the alternative function to use
17+ """
18+ def decorator (func ):
19+ @functools .wraps (func )
20+ def wrapper (* args , ** kwargs ):
21+ warnings .warn (
22+ f"The function { func .__name__ } () is deprecated. Use { alternative } () instead." ,
23+ category = DeprecationWarning ,
24+ stacklevel = 2
25+ )
26+ return func (* args , ** kwargs )
27+ return wrapper
28+ return decorator
29+
930class PermissionFlags :
1031 LF_USER = 10
1132 LF_ALL_USERS = 11
@@ -23,6 +44,13 @@ def __init__(self, name, enabled, data):
2344 self .enabled = enabled
2445 self .data = data
2546
47+ class HostFeatureEntitlement (object ):
48+ def __init__ (self , host_feature_entitlement_dict ):
49+ self .feature_name = host_feature_entitlement_dict .get ("featureName" )
50+ self .feature_display_name = host_feature_entitlement_dict .get ("featureDisplayName" )
51+ self .value = host_feature_entitlement_dict .get ("value" )
52+
53+
2654class HostConfig (object ):
2755 def __init__ (self , max_offline_lease_duration ):
2856 self .max_offline_lease_duration = max_offline_lease_duration
@@ -176,6 +204,7 @@ def GetHostConfig():
176204 raise LexFloatClientException (status )
177205
178206 @staticmethod
207+ @deprecated ("GetHostLicenseEntitlementSetName" )
179208 def GetHostProductVersionName ():
180209 """Gets the product version name.
181210
@@ -194,6 +223,7 @@ def GetHostProductVersionName():
194223 return LexFloatClientNative .byte_to_string (buffer .value )
195224
196225 @staticmethod
226+ @deprecated ("GetHostLicenseEntitlementSetDisplayName" )
197227 def GetHostProductVersionDisplayName ():
198228 """Gets the product version display name.
199229
@@ -212,6 +242,7 @@ def GetHostProductVersionDisplayName():
212242 return LexFloatClientNative .byte_to_string (buffer .value )
213243
214244 @staticmethod
245+ @deprecated ("GetHostFeatureEntitlement" )
215246 def GetHostProductVersionFeatureFlag (name ):
216247 """Gets the product version feature flag.
217248
@@ -234,6 +265,93 @@ def GetHostProductVersionFeatureFlag(name):
234265 return HostProductVersionFeatureFlag (name , isEnabled , LexFloatClientNative .byte_to_string (buffer .value ))
235266 else :
236267 raise LexFloatClientException (status )
268+
269+ @staticmethod
270+ def GetHostLicenseEntitlementSetName ():
271+ """Gets the name of the entitlement set associated with the LexFloatServer license.
272+
273+ Raises:
274+ LexFloatClientException
275+
276+ Returns:
277+ str: host license entitlement set name
278+ """
279+ buffer_size = 256
280+ buffer = LexFloatClientNative .get_ctype_string_buffer (buffer_size )
281+ status = LexFloatClientNative .GetHostLicenseEntitlementSetName (buffer , buffer_size )
282+ if status != LexFloatStatusCodes .LF_OK :
283+ raise LexFloatClientException (status )
284+ return LexFloatClientNative .byte_to_string (buffer .value )
285+
286+ @staticmethod
287+ def GetHostLicenseEntitlementSetDisplayName ():
288+ """Gets the display name of the entitlement set associated with the LexFloatServer license.
289+
290+ Raises:
291+ LexFloatClientException
292+
293+ Returns:
294+ str: host license entitlement set display name
295+ """
296+ buffer_size = 256
297+ buffer = LexFloatClientNative .get_ctype_string_buffer (buffer_size )
298+ status = LexFloatClientNative .GetHostLicenseEntitlementSetDisplayName (buffer , buffer_size )
299+ if status != LexFloatStatusCodes .LF_OK :
300+ raise LexFloatClientException (status )
301+ return LexFloatClientNative .byte_to_string (buffer .value )
302+
303+ @staticmethod
304+ def GetHostFeatureEntitlements ():
305+ """Gets the feature entitlements associated with the LexFloatServer license.
306+
307+ Feature entitlements can be linked directly to a license (license feature entitlements)
308+ or via entitlement sets. If a feature entitlement is defined in both, the value from
309+ the license feature entitlement takes precedence, overriding the entitlement set value.
310+
311+ Raises:
312+ LexFloatClientException
313+
314+ Returns:
315+ HostFeatureEntitlements[]: list of host feature entitlements
316+ """
317+ buffer_size = 4096
318+ buffer = LexFloatClientNative .get_ctype_string_buffer (buffer_size )
319+ status = LexFloatClientNative .GetHostFeatureEntitlements (buffer , buffer_size )
320+ if status == LexFloatStatusCodes .LF_OK :
321+ host_feature_entitlements_json = LexFloatClientNative .byte_to_string (buffer .value )
322+ if not host_feature_entitlements_json .strip ():
323+ return []
324+ else :
325+ host_feature_entitlements = json .loads (host_feature_entitlements_json )
326+ host_feature_entitlements_list = [HostFeatureEntitlement (feature_detail ) for feature_detail in host_feature_entitlements ]
327+ return host_feature_entitlements_list
328+ else :
329+ raise LexFloatClientException (status )
330+
331+ @staticmethod
332+ def GetHostFeatureEntitlement (feature_name ):
333+ """Gets the feature entitlement associated with the LexFloatServer license.
334+
335+ Feature entitlements can be linked directly to a license (license feature entitlements)
336+ or via entitlement sets. If a feature entitlement is defined in both, the value from
337+ the license feature entitlement takes precedence, overriding the entitlement set value.
338+
339+ Raises:
340+ LexFloatClientException
341+
342+ Returns:
343+ HostFeatureEntitlement: host feature entitlement
344+ """
345+ cstring_feature_name = LexFloatClientNative .get_ctype_string (feature_name )
346+ buffer_size = 1024
347+ buffer = LexFloatClientNative .get_ctype_string_buffer (buffer_size )
348+ status = LexFloatClientNative .GetHostFeatureEntitlement (cstring_feature_name , buffer , buffer_size )
349+ if status == LexFloatStatusCodes .LF_OK :
350+ host_feature_entitlement_json = LexFloatClientNative .byte_to_string (buffer .value )
351+ host_feature_entitlement = json .loads (host_feature_entitlement_json )
352+ return HostFeatureEntitlement (host_feature_entitlement )
353+ else :
354+ raise LexFloatClientException (status )
237355
238356 @staticmethod
239357 def GetHostLicenseMetadata (key ):
0 commit comments