def CheckForReleaseUpdate(platform, version, channel, release_callback): """Checks whether a new release is available for the product. This function should only be used if you manage your releases through Cryptlex release management API. Args: platform (str): release platform e.g. windows, macos, linux version (str): current release version channel (str): release channel e.g. stable release_callback (Callable[int]]): callback function Raises: LexActivatorException """ cstring_platform = LexActivatorNative.get_ctype_string(platform) cstring_version = LexActivatorNative.get_ctype_string(version) cstring_channel = LexActivatorNative.get_ctype_string(channel) release_callback_fn = LexActivatorNative.CallbackType(release_callback) callback_list.append(release_callback_fn) status = LexActivatorNative.CheckForReleaseUpdate( cstring_platform, cstring_version, cstring_channel, release_callback_fn) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def GenerateOfflineDeactivationRequest(file_path): """Generates the offline deactivation request needed for deactivation of the license in the dashboard and deactivates the license locally. A valid offline deactivation file confirms that the license has been successfully deactivated on the user's machine. Args: file_path (str): path of the file for the offline deactivation request Raises: LexActivatorException Returns: int: LA_OK, LA_FAIL """ cstring_file_path = LexActivatorNative.get_ctype_string(file_path) status = LexActivatorNative.GenerateOfflineDeactivationRequest( cstring_file_path) if LexStatusCodes.LA_OK == status: return LexStatusCodes.LA_OK elif LexStatusCodes.LA_FAIL == status: return LexStatusCodes.LA_FAIL else: raise LexActivatorException(status)
def ActivateLicense(): """Activates the license by contacting the Cryptlex servers. It validates the key and returns with encrypted and digitally signed token which it stores and uses to activate your application. This function should be executed at the time of registration, ideally on a button click. Raises: LexActivatorException Returns: int: LA_OK, LA_EXPIRED, LA_SUSPENDED, LA_FAIL """ status = LexActivatorNative.ActivateLicense() if LexStatusCodes.LA_OK == status: return LexStatusCodes.LA_OK elif LexStatusCodes.LA_EXPIRED == status: return LexStatusCodes.LA_EXPIRED elif LexStatusCodes.LA_SUSPENDED == status: return LexStatusCodes.LA_SUSPENDED elif LexStatusCodes.LA_FAIL == status: return LexStatusCodes.LA_FAIL else: raise LexActivatorException(status)
def IsLicenseValid(): """It verifies whether your app is genuinely activated or not. The verification is done locally by verifying the cryptographic digital signature fetched at the time of activation. This is just an auxiliary function which you may use in some specific cases, when you want to skip the server sync. Note: You may want to set grace period to 0 to ignore grace period. Raises: LexActivatorException Returns: int: LA_OK, LA_EXPIRED, LA_SUSPENDED, LA_GRACE_PERIOD_OVER, LA_FAIL """ status = LexActivatorNative.IsLicenseValid() if LexStatusCodes.LA_OK == status: return LexStatusCodes.LA_OK elif LexStatusCodes.LA_EXPIRED == status: return LexStatusCodes.LA_EXPIRED elif LexStatusCodes.LA_SUSPENDED == status: return LexStatusCodes.LA_SUSPENDED elif LexStatusCodes.LA_GRACE_PERIOD_OVER == status: return LexStatusCodes.LA_GRACE_PERIOD_OVER elif LexStatusCodes.LA_FAIL == status: return LexStatusCodes.LA_FAIL else: raise LexActivatorException(status)
def Reset(): """Resets the activation and trial data stored in the machine. This function is meant for developer testing only. Raises: LexActivatorException """ status = LexActivatorNative.Reset() if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def SetLicenseKey(license_key): """Sets the license key required to activate the license. Args: license_key (str): a valid license key Raises: LexActivatorException """ cstring_license_key = LexActivatorNative.get_ctype_string(license_key) status = LexActivatorNative.SetLicenseKey(cstring_license_key) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def ResetActivationMeterAttributeUses(name): """Resets the meter attribute uses of the activation. Args: name (str): name of the meter attribute Raises: LexActivatorException """ cstring_name = LexActivatorNative.get_ctype_string(name) status = LexActivatorNative.ResetActivationMeterAttributeUses( cstring_name) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def SetCryptlexHost(host): """In case you are running Cryptlex on-premise, you can set the host for your on-premise server. Args: host (str): the address of the Cryptlex on-premise server Raises: LexActivatorException """ cstring_host = LexActivatorNative.get_ctype_string(host) status = LexActivatorNative.SetCryptlexHost(cstring_host) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def GetLibraryVersion(): """Gets the version of this library. Raises: LexActivatorException Returns: str: the library version """ buffer_size = 256 buffer = LexActivatorNative.get_ctype_string_buffer(buffer_size) status = LexActivatorNative.GetLibraryVersion(buffer, buffer_size) if status != LexStatusCodes.LA_OK: raise LexActivatorException(status) return LexActivatorNative.byte_to_string(buffer.value)
def DecrementActivationMeterAttributeUses(name, decrement): """Decrements the meter attribute uses of the activation. Args: name (str): name of the meter attribute decrement (int): the decrement value Raises: LexActivatorException """ cstring_name = LexActivatorNative.get_ctype_string(name) status = LexActivatorNative.DecrementActivationMeterAttributeUses( cstring_name, decrement) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def SetActivationLeaseDuration(lease_duration): """Sets the lease duration for the activation. The activation lease duration is honoured when the allow client lease duration property is enabled. Args: lease_duration(int): value of the lease duration. Raises: LexActivatorException """ status = LexActivatorNative.SetActivationLeaseDuration(lease_duration) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def GetLicenseKey(): """Gets the license key used for activation. Raises: LexActivatorException Returns: str: the license key """ buffer_size = 256 buffer = LexActivatorNative.get_ctype_string_buffer(buffer_size) status = LexActivatorNative.GetLicenseKey(buffer, buffer_size) if status != LexStatusCodes.LA_OK: raise LexActivatorException(status) return LexActivatorNative.byte_to_string(buffer.value)
def GetTrialId(): """Gets the trial activation id. Used in case of trial extension. Raises: LexActivatorException Returns: str: the trial id """ buffer_size = 256 buffer = LexActivatorNative.get_ctype_string_buffer(buffer_size) status = LexActivatorNative.GetTrialId(buffer, buffer_size) if status != LexStatusCodes.LA_OK: raise LexActivatorException(status) return LexActivatorNative.byte_to_string(buffer.value)
def GetLicenseType(): """Gets the license type. Raises: LexActivatorException Returns: str: the license type - node-locked or hosted-floating """ buffer_size = 256 buffer = LexActivatorNative.get_ctype_string_buffer(buffer_size) status = LexActivatorNative.GetLicenseType(buffer, buffer_size) if status != LexStatusCodes.LA_OK: raise LexActivatorException(status) return LexActivatorNative.byte_to_string(buffer.value)
def GenerateOfflineTrialActivationRequest(file_path): """Generates the offline trial activation request needed for generating offline trial activation response in the dashboard. Args: file_path (str): path of the file for the offline request Raises: LexActivatorException """ cstring_file_path = LexActivatorNative.get_ctype_string(file_path) status = LexActivatorNative.GenerateOfflineTrialActivationRequest( cstring_file_path) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def GetLicenseUserCompany(): """Gets the company associated with the license user. Raises: LexActivatorException Returns: str: the license user company """ buffer_size = 256 buffer = LexActivatorNative.get_ctype_string_buffer(buffer_size) status = LexActivatorNative.GetLicenseUserCompany(buffer, buffer_size) if status != LexStatusCodes.LA_OK: raise LexActivatorException(status) return LexActivatorNative.byte_to_string(buffer.value)
def GetProductVersionDisplayName(): """Gets the product version display name. Raises: LexActivatorException Returns: str: display name of the product version. """ buffer_size = 256 buffer = LexActivatorNative.get_ctype_string_buffer(buffer_size) status = LexActivatorNative.GetProductVersionDisplayName(buffer,buffer_size) if status != LexStatusCodes.LA_OK: raise LexActivatorException(status) return LexActivatorNative.byte_to_string(buffer.value)
def SetProductFile(file_path): """Sets the absolute path of the Product.dat file. This function must be called on every start of your program before any other functions are called. Args: file_path (str): absolute path of the product file (Product.dat) Raises: LexActivatorException """ cstring = LexActivatorNative.get_ctype_string(file_path) status = LexActivatorNative.SetProductFile(cstring) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def SetAppVersion(app_version): """Sets the current app version of your application. The app version appears along with the activation details in dashboard. It is also used to generate app analytics. Args: app_version (str): string of maximum length 256 characters with utf-8 encoding. Raises: LexActivatorException """ cstring_app_version = LexActivatorNative.get_ctype_string(app_version) status = LexActivatorNative.SetAppVersion(cstring_app_version) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def DeactivateLicense(): """Deactivates the license activation and frees up the correponding activation slot by contacting the Cryptlex servers. Raises: LexActivatorException Returns: int: LA_OK, LA_FAIL """ status = LexActivatorNative.DeactivateLicense() if LexStatusCodes.LA_OK == status: return LexStatusCodes.LA_OK elif LexStatusCodes.LA_FAIL == status: return LexStatusCodes.LA_FAIL else: raise LexActivatorException(status)
def SetProductId(product_id, flags): """Sets the product id of your application. This function must be called on every start of your program before any other functions are called, with the exception of SetProductFile() or SetProductData() function. Args: product_id (str): the unique product id of your application as mentioned on the product page in the dashboard flags (str): depending upon whether your application requires admin/root permissions to run or not, this parameter can have one of the following values: LA_SYSTEM, LA_USER, LA_IN_MEMORY Raises: LexActivatorException """ cstring_product_id = LexActivatorNative.get_ctype_string(product_id) status = LexActivatorNative.SetProductId(cstring_product_id, flags) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def GetLocalTrialExpiryDate(): """Gets the local trial expiry date timestamp. Raises: LexActivatorException Returns: int: the timestamp """ expiry_date = ctypes.c_uint() status = LexActivatorNative.GetLocalTrialExpiryDate( ctypes.byref(expiry_date)) if status == LexStatusCodes.LA_OK: return expiry_date.value elif status == LexStatusCodes.LA_FAIL: return 0 else: raise LexActivatorException(status)
def GetServerSyncGracePeriodExpiryDate(): """Gets the server sync grace period expiry date timestamp. Raises: LexActivatorException Returns: int: the timestamp """ expiry_date = ctypes.c_uint() status = LexActivatorNative.GetServerSyncGracePeriodExpiryDate( ctypes.byref(expiry_date)) if status == LexStatusCodes.LA_OK: return expiry_date.value elif status == LexStatusCodes.LA_FAIL: return 0 else: raise LexActivatorException(status)
def SetOfflineActivationRequestMeterAttributeUses(name, uses): """Sets the meter attribute uses for the offline activation request. This function should only be called before GenerateOfflineActivationRequest() function to set the meter attributes in case of offline activation. Args: name (str): name of the meter attribute uses (int): the uses value Raises: LexActivatorException """ cstring_name = LexActivatorNative.get_ctype_string(name) status = LexActivatorNative.SetOfflineActivationRequestMeterAttributeUses( cstring_name, uses) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def GetLicenseAllowedActivations(): """Gets the allowed activations of the license. Raises: LexActivatorException Returns: int: the allowed activation """ allowed_activations = ctypes.c_uint() status = LexActivatorNative.GetLicenseAllowedActivations( ctypes.byref(allowed_activations)) if status == LexStatusCodes.LA_OK: return allowed_activations.value elif status == LexStatusCodes.LA_FAIL: return 0 else: raise LexActivatorException(status)
def GetLicenseTotalActivations(): """Gets the total activations of the license. Raises: LexActivatorException Returns: int: the total activations """ total_activations = ctypes.c_uint() status = LexActivatorNative.GetLicenseTotalActivations( ctypes.byref(total_activations)) if status == LexStatusCodes.LA_OK: return total_activations.value elif status == LexStatusCodes.LA_FAIL: return 0 else: raise LexActivatorException(status)
def SetTrialActivationMetadata(key, value): """Sets the trial activation metadata. The metadata appears along with the trial activation details of the product in dashboard. Args: key (str): string of maximum length 256 characters with utf-8 encoding value (str): string of maximum length 256 characters with utf-8 encoding Raises: LexActivatorException """ cstring_key = LexActivatorNative.get_ctype_string(key) cstring_value = LexActivatorNative.get_ctype_string(value) status = LexActivatorNative.SetTrialActivationMetadata( cstring_key, cstring_value) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def GetActivationMeterAttributeUses(name): """Gets the meter attribute uses consumed by the activation. Args: name (str): name of the meter attribute Raises: LexActivatorException Returns: int: value of meter attribute uses by the activation """ cstring_name = LexActivatorNative.get_ctype_string(name) uses = ctypes.c_uint() status = LexActivatorNative.GetActivationMeterAttributeUses( cstring_name, ctypes.byref(uses)) if status == LexStatusCodes.LA_OK: return uses.value else: raise LexActivatorException(status)
def SetLicenseUserCredential(email, password): """Sets the license user email and password for authentication. This function must be called before ActivateLicense() or IsLicenseGenuine() function if requireAuthentication property of the license is set to true. Args: email (str): user email address password (str): user password Raises: LexActivatorException """ cstring_email = LexActivatorNative.get_ctype_string(email) cstring_password = LexActivatorNative.get_ctype_string(password) status = LexActivatorNative.SetLicenseUserCredential( cstring_email, cstring_password) if LexStatusCodes.LA_OK != status: raise LexActivatorException(status)
def GetTrialActivationMetadata(key): """Gets the trial activation metadata. Args: key (str): metadata key to retrieve the value Raises: LexActivatorException Returns: str: value of metadata for the key """ cstring_key = LexActivatorNative.get_ctype_string(key) buffer_size = 256 buffer = LexActivatorNative.get_ctype_string_buffer(buffer_size) status = LexActivatorNative.GetTrialActivationMetadata( cstring_key, buffer, buffer_size) if status != LexStatusCodes.LA_OK: raise LexActivatorException(status) return LexActivatorNative.byte_to_string(buffer.value)