Skip to content

Commit 0595156

Browse files
committed
Add "AddFeature" and "RemoveFeature"
1 parent 568dac4 commit 0595156

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

licensing/methods.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,74 @@ def create_key_from_template(token, license_template_id):
546546
return (False, "Could not contact the server.")
547547

548548
return (jobj["key"], jobj["rawResponse"], jobj["message"])
549+
550+
def add_feature(token, product_id, key, feature):
551+
"""
552+
This method will set a certain feature (F1..F8) to true.
553+
If the key algorithm in the product is SKGL, the key string will be
554+
changed if necessary. Otherwise, if SKM15 is used, the key will stay
555+
the same. To do the reverse, please see RemoveFeature.
556+
557+
More docs: https://app.cryptolens.io/docs/api/v3/AddFeature
558+
"""
559+
560+
response = ""
561+
562+
try:
563+
response = HelperMethods.send_request("/key/AddFeature", {"token":token,\
564+
"ProductId":product_id,\
565+
"Key" : key,\
566+
"Feature" : feature})
567+
except HTTPError as e:
568+
response = e.read()
569+
except URLError as e:
570+
return (None, "Could not contact the server. Error message: " + str(e))
571+
except Exception:
572+
return (None, "Could not contact the server.")
573+
574+
jobj = json.loads(response)
575+
576+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
577+
if jobj != None:
578+
return (False, jobj["message"])
579+
else:
580+
return (False, "Could not contact the server.")
581+
582+
return (True, jobj["message"])
583+
584+
def remove_feature(token, product_id, key, feature):
585+
"""
586+
This method will set a certain feature (F1..F8) to false. If the key
587+
algorithm in the product is SKGL, the key string will be changed if
588+
necessary. Otherwise, if SKM15 is used, the key will stay the same.
589+
To do the reverse, please see AddFeature.
590+
591+
More docs: https://app.cryptolens.io/docs/api/v3/RemoveFeature
592+
"""
593+
594+
response = ""
595+
596+
try:
597+
response = HelperMethods.send_request("/key/RemoveFeature", {"token":token,\
598+
"ProductId":product_id,\
599+
"Key" : key,\
600+
"Feature" : feature})
601+
except HTTPError as e:
602+
response = e.read()
603+
except URLError as e:
604+
return (None, "Could not contact the server. Error message: " + str(e))
605+
except Exception:
606+
return (None, "Could not contact the server.")
607+
608+
jobj = json.loads(response)
609+
610+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
611+
if jobj != None:
612+
return (False, jobj["message"])
613+
else:
614+
return (False, "Could not contact the server.")
615+
616+
return (True, jobj["message"])
549617

550618
class AI:
551619

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
setup(
33
name = 'licensing', # How you named your package folder (MyLib)
44
packages = ['licensing'], # Chose the same as "name"
5-
version = '0.43', # Start with a small number and increase it with every change you make
5+
version = '0.44', # Start with a small number and increase it with every change you make
66
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
77
description = 'Client library for Cryptolens licensing Web API.', # Give a short description about your library
88
author = 'Cryptolens AB', # Type in your name
99
author_email = '[email protected]', # Type in your E-Mail
1010
url = 'https://cryptolens.io', # Provide either the link to your github or to your website
11-
download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/v_42.tar.gz', # I explain this later on
11+
download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/v_44.tar.gz', # I explain this later on
1212
keywords = ['software licensing', 'licensing library', 'cryptolens'], # Keywords that define your package best
1313
classifiers=[
1414
#'Development Status :: 5 - Stable', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package

0 commit comments

Comments
 (0)