From 568dac4fd38b7b3483ba55f63557449b98164436 Mon Sep 17 00:00:00 2001 From: Artem Los Date: Tue, 20 Feb 2024 06:35:30 +1100 Subject: [PATCH] Add new methods related to a License Key (#68) * Update methods.py * Update methods.py * Update methods.py * Update setup.py --- licensing/methods.py | 132 +++++++++++++++++++++++++++++++++++++++++++ setup.py | 2 +- 2 files changed, 133 insertions(+), 1 deletion(-) diff --git a/licensing/methods.py b/licensing/methods.py index 72918d0..6844577 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -414,6 +414,138 @@ def block_key(token, product_id, key): return (False, "Could not contact the server.") return (True, jobj["message"]) + + def machine_lock_limit(token, product_id, key, number_of_machines): + """ + This method will change the maximum number of machine codes that + a license key can have. + + More docs: https://app.cryptolens.io/docs/api/v3/MachineLockLimit + """ + + response = "" + + try: + response = HelperMethods.send_request("/key/MachineLockLimit", {"token":token,\ + "ProductId":product_id,\ + "Key" : key,\ + "NumberOfMachines": number_of_machines}) + except HTTPError as e: + response = e.read() + except URLError as e: + return (None, "Could not contact the server. Error message: " + str(e)) + except Exception: + return (None, "Could not contact the server.") + + jobj = json.loads(response) + + if jobj == None or not("result" in jobj) or jobj["result"] == 1: + if jobj != None: + return (False, jobj["message"]) + else: + return (False, "Could not contact the server.") + + return (True, jobj["message"]) + + def change_notes(token, product_id, key, notes): + """ + This method will change the content of the notes field of + a given license key. + + More docs: https://app.cryptolens.io/docs/api/v3/ChangeNotes + """ + + response = "" + + try: + response = HelperMethods.send_request("/key/ChangeNotes", {"token":token,\ + "ProductId":product_id,\ + "Key" : key,\ + "Notes": notes}) + except HTTPError as e: + response = e.read() + except URLError as e: + return (None, "Could not contact the server. Error message: " + str(e)) + except Exception: + return (None, "Could not contact the server.") + + jobj = json.loads(response) + + if jobj == None or not("result" in jobj) or jobj["result"] == 1: + if jobj != None: + return (False, jobj["message"]) + else: + return (False, "Could not contact the server.") + + return (True, jobj["message"]) + + def change_reseller(token, product_id, key, reseller_id): + """ + This method will change the reseller of a license. If the reseller is + not specified (for example, if ResellerId=0) or the reseller with the + provided ID does not exist, any reseller that was previously associated + with the license will be dissociated. + + More docs: https://app.cryptolens.io/docs/api/v3/ChangeReseller + """ + + response = "" + + try: + response = HelperMethods.send_request("/key/ChangeReseller", {"token":token,\ + "ProductId":product_id,\ + "Key" : key,\ + "ResellerId": reseller_id}) + except HTTPError as e: + response = e.read() + except URLError as e: + return (None, "Could not contact the server. Error message: " + str(e)) + except Exception: + return (None, "Could not contact the server.") + + jobj = json.loads(response) + + if jobj == None or not("result" in jobj) or jobj["result"] == 1: + if jobj != None: + return (False, jobj["message"]) + else: + return (False, "Could not contact the server.") + + return (True, jobj["message"]) + + def create_key_from_template(token, license_template_id): + """ + This method will create a license key based on a License Template. + If you want to see all the defined license templates through the API, + this can be accomplished with Get License Templates. An alternative is + to call the Create Key method, which allows you to specify all the + parameters yourself. Note: the "feature lock" field in the access token + can be used to restrict which license tempalte id can be used. + + More docs: https://app.cryptolens.io/docs/api/v3/CreateKeyFromTemplate + """ + + response = "" + + try: + response = HelperMethods.send_request("/key/CreateKeyFromTemplate", {"token":token,\ + "LicenseTemplateId": license_template_id}) + except HTTPError as e: + response = e.read() + except URLError as e: + return (None, "Could not contact the server. Error message: " + str(e)) + except Exception: + return (None, "Could not contact the server.") + + jobj = json.loads(response) + + if jobj == None or not("result" in jobj) or jobj["result"] == 1: + if jobj != None: + return (False, jobj["message"]) + else: + return (False, "Could not contact the server.") + + return (jobj["key"], jobj["rawResponse"], jobj["message"]) class AI: diff --git a/setup.py b/setup.py index bf59adc..c314fc7 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name = 'licensing', # How you named your package folder (MyLib) packages = ['licensing'], # Chose the same as "name" - version = '0.42', # Start with a small number and increase it with every change you make + version = '0.43', # Start with a small number and increase it with every change you make license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository description = 'Client library for Cryptolens licensing Web API.', # Give a short description about your library author = 'Cryptolens AB', # Type in your name