Skip to content

Commit

Permalink
Update to ModelVersion=3, closes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
artemlos committed Nov 30, 2020
1 parent 20a7621 commit 523cae2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion licensing/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def activate(token, rsa_pub_key, product_id, key, machine_code, fields_to_return
"FloatingTimeInterval": floating_time_interval,\
"MaxOverdraft": max_overdraft,\
"FriendlyName" : friendly_name,\
"ModelVersion": 2 ,\
"ModelVersion": 3 ,\
"Sign":"True",\
"SignMethod":1}))
except HTTPError as e:
Expand Down Expand Up @@ -89,6 +89,7 @@ def get_key(token, rsa_pub_key, product_id, key, fields_to_return = 0,\
"metadata":metadata,\
"FloatingTimeInterval": floating_time_interval,\
"Sign":"True",\
"ModelVersion": 3 ,\
"SignMethod":1}))
except HTTPError as e:
response = Response.from_string(e.read())
Expand Down
31 changes: 28 additions & 3 deletions licensing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,39 @@
from licensing.internal import HelperMethods

class ActivatedMachine:
def __init__(self, IP, Mid, Time, FriendlyName=""):
def __init__(self, IP, Mid, Time, FriendlyName="", FloatingExpires = ""):
self.IP = IP
self.Mid = Mid

# TODO: check if time is int, and convert to datetime in this case.
self.Time = Time
self.FriendlyName = FriendlyName
self.FloatingExpires = FloatingExpires

class Reseller:

"""
Information about the reseller.
"""

def __init__(self, Id, InviteId, ResellerUserId, Created, Name, Url, Email, Phone, Description):
self.Id = Id
self.InviteId = InviteId
self.ResellerUserId = ResellerUserId
self.Created = Created
self.Name = Name
self.Url = Url
self.Email = Email
self.Phone = Phone
self.Description = Description


class LicenseKey:

def __init__(self, ProductId, ID, Key, Created, Expires, Period, F1, F2,\
F3, F4, F5, F6, F7, F8, Notes, Block, GlobalId, Customer, \
ActivatedMachines, TrialActivation, MaxNoOfMachines, \
AllowedMachines, DataObjects, SignDate, RawResponse):
AllowedMachines, DataObjects, SignDate, Reseller, RawResponse):

self.product_id = ProductId
self.id = ID
Expand All @@ -53,6 +72,7 @@ def __init__(self, ProductId, ID, Key, Created, Expires, Period, F1, F2,\
self.allowed_machines = AllowedMachines
self.data_objects = DataObjects
self.sign_date = SignDate
self.reseller = Reseller
self.raw_response = RawResponse

@staticmethod
Expand All @@ -63,13 +83,18 @@ def from_response(response):

obj = json.loads(base64.b64decode(response.license_key).decode('utf-8'))

reseller = None

if "Reseller" in obj and obj["Reseller"] != None:
reseller = Reseller(**obj["Reseller"])

return LicenseKey(obj["ProductId"], obj["ID"], obj["Key"], datetime.datetime.fromtimestamp(obj["Created"]),\
datetime.datetime.fromtimestamp(obj["Expires"]), obj["Period"], obj["F1"], obj["F2"], \
obj["F3"], obj["F4"],obj["F5"],obj["F6"], obj["F7"], \
obj["F8"], obj["Notes"], obj["Block"], obj["GlobalId"],\
obj["Customer"], LicenseKey.__load_activated_machines(obj["ActivatedMachines"]), obj["TrialActivation"], \
obj["MaxNoOfMachines"], obj["AllowedMachines"], obj["DataObjects"], \
datetime.datetime.fromtimestamp(obj["SignDate"]), response)
datetime.datetime.fromtimestamp(obj["SignDate"]),reseller, response)

def save_as_string(self):
"""
Expand Down

0 comments on commit 523cae2

Please sign in to comment.