Пример #1
0
 def create():
     with Master.atomic() as txn:
         id = uuid4()
         date = datetime.utcnow()
         q = Master.insert(id=id, revoked=False, authoraize_date=date)
         q.execute()
         return id
Пример #2
0
 def is_master_mode():
     if not Master.table_exists():
         print("Master table does not exists!")
         return True
     master_mode = False
     with Master.atomic() as txn:
         now = datetime.utcnow()
         keys = Master.select().where(Master.revoked == False)
         for key in keys:
             if key.revoke_date and key.revoke_date < now:
                 key.revoked = True
                 key.revoke_date = datetime.utcnow()
                 key.save()
             else:
                 master_mode = True
     return master_mode
Пример #3
0
 def setup():
     if not MasterTable.table_exists():
         print("Master table does not exists!")
         return
     if not MasterHelper.has_keys():
         print("First start...")
         key = MasterHelper.create()
         print("Your key: \"" + str(key) + "\"")
Пример #4
0
 def revoke(id):
     with Master.atomic() as txn:
         try:
             key = Master[id]
             if not key:
                 return False
             key.revoked = True
             key.revoke_date = datetime.utcnow()
             key.save()
             return True
         except DoesNotExist as ex:
             return False
Пример #5
0
 def check(id):
     with Master.atomic() as txn:
         try:
             key = Master[id]
             if not key:
                 return False
             if key.revoked:
                 return False
             if key.revoke_date and key.revoke_date < datetime.utcnow():
                 key.revoked = True
                 key.save()
                 return False
             return True
         except DoesNotExist as ex:
             return False
Пример #6
0
 def is_startup():
     with Master.atomic() as txn:
         return Master.select().count() == 1
Пример #7
0
 def has_keys():
     with Master.atomic() as txn:
         return Master.select().count() > 0
Пример #8
0
 def table_exists():
     return Master.table_exists()
Пример #9
0
 def is_master_mode():
     if not MasterTable.table_exists():
         print("Master table does not exists!")
         return True
     return MasterHelper.is_master_mode()