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

Borrowing develop #19

Merged
merged 30 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
decfe79
feat: add permission flag
muneebkq Jul 8, 2024
6999c07
feat: add function get-floating-license-mode
muneebkq Jul 8, 2024
3b9322f
feat: add floating client metadata
muneebkq Jul 12, 2024
ad13cd7
feat: add get-host-config function
muneebkq Jul 16, 2024
beb27fc
refactor: jsdoc
muneebkq Jul 16, 2024
c6b4865
feat: add get floating client lease expiry
muneebkq Jul 16, 2024
4d8aa69
feat: request-float-license
muneebkq Jul 16, 2024
8723c26
fix: change type defintion
muneebkq Jul 30, 2024
0a0b60d
feat: add status codes
muneebkq Jul 31, 2024
a7dc774
Merge pull request #13 from cryptlex/muneeb/get-floating-client-lease…
ahmad-kemsan Aug 1, 2024
fd79356
refacor: status code
muneebkq Aug 2, 2024
7e5f751
refactor: jsdoc
muneebkq Aug 2, 2024
e471bb9
refactor: arg name
muneebkq Aug 2, 2024
b9e508f
refactor: jsdoc
muneebkq Aug 2, 2024
ae91277
refactor: jsdoc
muneebkq Aug 2, 2024
4c7b0f4
refactor: remove extra line
muneebkq Aug 2, 2024
096c864
refactor: arg format chnaged to snakecase
muneebkq Aug 2, 2024
645282b
refactor: jsdoc
muneebkq Aug 2, 2024
0cb9609
add: error code 67
muneebkq Aug 6, 2024
8f456ca
Merge pull request #18 from cryptlex/muneeb/status-codes
ahmad-kemsan Aug 6, 2024
60a6b13
fix: buffer size ->4096
muneebkq Aug 6, 2024
a4e5a34
Merge pull request #10 from cryptlex/muneeb/floating-client-metadata
ahmad-kemsan Aug 6, 2024
a48b5f1
Merge pull request #12 from cryptlex/muneeb/set-permission-flag
ahmad-kemsan Aug 6, 2024
74bf813
refactor: jsdoc
muneebkq Aug 6, 2024
467d968
Merge pull request #9 from cryptlex/muneeb/get-host-config
ahmad-kemsan Aug 6, 2024
019af2b
refactor: jsdoc
muneebkq Aug 6, 2024
3d28f10
refactor: jsdoc
muneebkq Aug 6, 2024
d0b904d
Merge branch 'borrowing-develop' into muneeb/request-offline-floating…
ahmad-kemsan Aug 6, 2024
cc88fae
Merge pull request #14 from cryptlex/muneeb/request-offline-floating-…
ahmad-kemsan Aug 6, 2024
38924a9
Merge pull request #11 from cryptlex/muneeb/get-floating-license-mode
ahmad-kemsan Aug 6, 2024
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
2 changes: 1 addition & 1 deletion cryptlex/lexfloatclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from cryptlex.lexfloatclient.lexfloatclient import LexFloatClient, LexFloatStatusCodes, LexFloatClientException
from cryptlex.lexfloatclient.lexfloatclient import LexFloatClient, LexFloatStatusCodes, LexFloatClientException, PermissionFlags
129 changes: 128 additions & 1 deletion cryptlex/lexfloatclient/lexfloatclient.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
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

callback_list = []

class PermissionFlags:
LF_USER = 10
LF_ALL_USERS = 11

class HostLicenseMeterAttribute(object):
def __init__(self, name, allowed_uses, total_uses, gross_uses):
Expand All @@ -19,6 +23,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


class LexFloatClient:
@staticmethod
def SetHostProductId(product_id):
Expand Down Expand Up @@ -100,6 +109,30 @@ def SetFloatingClientMetadata(key, value):
cstring_key, cstring_value)
if LexFloatStatusCodes.LF_OK != status:
raise LexFloatClientException(status)

@staticmethod
def SetPermissionFlag(flag):
"""Sets the permission flag.

This function must be called on every start of your program after SetHostProductId()
function in case the application allows borrowing of licenses or system wide activation.

Args:
flags : depending on your application's requirements, choose one of
the following values: LF_USER, LF_ALL_USERS.

LF_USER: This flag indicates that the application does not require
admin or root permissions to run.

LF_ALL_USERS: This flag is specifically designed for Windows and should be used
for system-wide activations.

Raises:
LexFloatClientException
"""
status = LexFloatClientNative.SetPermissionFlag(flag)
if LexFloatStatusCodes.LF_OK != status:
raise LexFloatClientException(status)

@staticmethod
def GetFloatingClientLibraryVersion():
Expand All @@ -117,7 +150,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:
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 Expand Up @@ -244,6 +300,24 @@ def GetHostLicenseExpiryDate():
return expiry_date.value
else:
raise LexFloatClientException(status)

@staticmethod
def GetFloatingClientLeaseExpiryDate():
"""Gets the lease expiry date timestamp of the floating client.

Raises:
LexFloatClientException

Returns:
int: the timestamp
"""
leaseExpiryDate = ctypes.c_uint()
status = LexFloatClientNative.GetFloatingClientLeaseExpiryDate(
ctypes.byref(leaseExpiryDate))
if status == LexFloatStatusCodes.LF_OK:
return leaseExpiryDate.value
else:
raise LexFloatClientException(status)

@staticmethod
def GetFloatingClientMeterAttributeUses(name):
Expand All @@ -266,6 +340,45 @@ def GetFloatingClientMeterAttributeUses(name):
return uses.value
else:
raise LexFloatClientException(status)

@staticmethod
def GetFloatingLicenseMode():
"""Gets the mode of the floating license (online or offline).

Raises:
LexActivatorException

Returns:
ActivationMode: mode of floating license.
"""
buffer_size = 256
buffer = LexFloatClientNative.get_ctype_string_buffer(buffer_size)
status = LexFloatClientNative.GetFloatingLicenseMode(buffer,buffer_size)
if status != LexFloatStatusCodes.LF_OK:
raise LexFloatClientException(status)
return LexFloatClientNative.byte_to_string(buffer.value)

@staticmethod
def GetFloatingClientMetadata(key):
"""Gets the value of the floating client metadata.

Args:
key (str): metadata key to retrieve the value

Raises:
LexFloatClientException

Returns:
str: value of the floating client metadata
"""
cstring_key = LexFloatClientNative.get_ctype_string(key)
buffer_size = 4096
buffer = LexFloatClientNative.get_ctype_string_buffer(buffer_size)
status = LexFloatClientNative.GetFloatingClientMetadata(
cstring_key, buffer, buffer_size)
if status != LexFloatStatusCodes.LF_OK:
raise LexFloatClientException(status)
return LexFloatClientNative.byte_to_string(buffer.value)

@staticmethod
def RequestFloatingLicense():
Expand All @@ -278,6 +391,20 @@ def RequestFloatingLicense():
if LexFloatStatusCodes.LF_OK != status:
raise LexFloatClientException(status)

@staticmethod
def RequestOfflineFloatingLicense(lease_duration):
"""Sends the request to lease the license from the LexFloatServer for offline usage.

Args:
leaseDuration (int): seconds for which the lease should be obtained.

Raises:
LexFloatClientException
"""
status = LexFloatClientNative.RequestOfflineFloatingLicense(lease_duration)
if LexFloatStatusCodes.LF_OK != status:
raise LexFloatClientException(status)

@staticmethod
def DropFloatingLicense():
"""Sends the request to the LexFloatServer to free the license.
Expand Down
16 changes: 16 additions & 0 deletions cryptlex/lexfloatclient/lexfloatclient_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,20 @@ def get_error_message(code):
return 'The server license has been suspended.'
if code == LexFloatStatusCodes.LF_E_SERVER_LICENSE_GRACE_PERIOD_OVER:
return 'The grace period for server license is over.'
if code == LexFloatStatusCodes.LF_E_SYSTEM_PERMISSION:
return 'Insufficient system permissions.'
if code == LexFloatStatusCodes.LF_E_INVALID_PERMISSION_FLAG:
return 'Invalid permission flag.'
if code == LexFloatStatusCodes.LF_E_OFFLINE_FLOATING_LICENSE_NOT_ALLOWED:
return 'Offline floating license is not allowed for per-instance leasing strategy.'
if code == LexFloatStatusCodes.LF_E_MAX_OFFLINE_LEASE_DURATION_EXCEEDED:
return 'Maximum offline lease duration exceeded.'
if code == LexFloatStatusCodes.LF_E_ALLOWED_OFFLINE_FLOATING_CLIENTS_LIMIT_REACHED:
return 'Allowed offline floating clients limit reached.'
if code == LexFloatStatusCodes.LF_E_WMIC:
return "Fingerprint couldn't be generated because Windows Management Instrumentation (WMI) service has been disabled. This error is specific to Windows only."
if code == LexFloatStatusCodes.LF_E_MACHINE_FINGERPRINT:
return 'Machine fingerprint has changed since activation.'
if code == LexFloatStatusCodes.LF_E_PROXY_NOT_TRUSTED:
return 'Request blocked due to untrusted proxy.'
return 'Unknown error!'
24 changes: 24 additions & 0 deletions cryptlex/lexfloatclient/lexfloatclient_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ def byte_to_string(input):
SetFloatingClientMetadata.argtypes = [CSTRTYPE, CSTRTYPE]
SetFloatingClientMetadata.restype = c_int

SetPermissionFlag = library.SetPermissionFlag
SetPermissionFlag.argtypes = [c_uint32]
SetPermissionFlag.restype = c_int

GetFloatingClientLibraryVersion = library.GetFloatingClientLibraryVersion
GetFloatingClientLibraryVersion.argtypes = [STRTYPE, c_uint32]
GetFloatingClientLibraryVersion.restype = c_int
Expand All @@ -139,10 +143,18 @@ def byte_to_string(input):
GetHostProductVersionDisplayName.argtypes = [STRTYPE, c_uint32]
GetHostProductVersionDisplayName.restype = c_int

GetFloatingLicenseMode = library.GetFloatingLicenseMode
GetFloatingLicenseMode.argtypes = [STRTYPE, c_uint32]
GetFloatingLicenseMode.restype = c_int

GetHostProductVersionFeatureFlag = library.GetHostProductVersionFeatureFlag
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 All @@ -155,14 +167,26 @@ def byte_to_string(input):
GetHostLicenseExpiryDate.argtypes = [POINTER(c_uint32)]
GetHostLicenseExpiryDate.restype = c_int

GetFloatingClientLeaseExpiryDate = library.GetFloatingClientLeaseExpiryDate
GetFloatingClientLeaseExpiryDate.argtypes = [POINTER(c_uint32)]
GetFloatingClientLeaseExpiryDate.restype = c_int

GetFloatingClientMeterAttributeUses = library.GetFloatingClientMeterAttributeUses
GetFloatingClientMeterAttributeUses.argtypes = [CSTRTYPE, POINTER(c_uint32)]
GetFloatingClientMeterAttributeUses.restype = c_int

GetFloatingClientMetadata = library.GetFloatingClientMetadata
GetFloatingClientMetadata.argtypes = [CSTRTYPE, STRTYPE, c_uint32]
GetFloatingClientMetadata.restype = c_int

RequestFloatingLicense = library.RequestFloatingLicense
RequestFloatingLicense.argtypes = []
RequestFloatingLicense.restype = c_int

RequestOfflineFloatingLicense = library.RequestOfflineFloatingLicense
RequestOfflineFloatingLicense.argtypes = [c_uint32]
RequestOfflineFloatingLicense.restype = c_int

DropFloatingLicense = library.DropFloatingLicense
DropFloatingLicense.argtypes = []
DropFloatingLicense.restype = c_int
Expand Down
18 changes: 17 additions & 1 deletion cryptlex/lexfloatclient/lexfloatstatus_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,26 @@ class LexFloatStatusCodes:
LF_E_METER_ATTRIBUTE_USES_LIMIT_REACHED = 56

LF_E_PRODUCT_VERSION_NOT_LINKED = 57

LF_E_FEATURE_FLAG_NOT_FOUND = 58

LF_E_SYSTEM_PERMISSION = 59

LF_E_IP = 60

LF_E_INVALID_PERMISSION_FLAG = 61

LF_E_OFFLINE_FLOATING_LICENSE_NOT_ALLOWED = 62

LF_E_MAX_OFFLINE_LEASE_DURATION_EXCEEDED = 63

LF_E_ALLOWED_OFFLINE_FLOATING_CLIENTS_LIMIT_REACHED = 64

LF_E_WMIC = 65

LF_E_MACHINE_FINGERPRINT = 66

LF_E_PROXY_NOT_TRUSTED = 67

LF_E_CLIENT = 70

Expand Down