Eliminate a lot of the if cases in create_user by separating them out. Add a limit to the number of users which can be created based on the license. Add support for creating and loading licenses.
This commit is contained in:
parent
0ef1902957
commit
33b43b75c0
9 changed files with 103 additions and 26 deletions
38
tools/createlicense.py
Normal file
38
tools/createlicense.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
import argparse
|
||||
import pickle
|
||||
|
||||
from Crypto.PublicKey import RSA
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
def encrypt(message, output_filename):
|
||||
private_key_file = 'conf/stack/license_key'
|
||||
with open(private_key_file, 'r') as private_key:
|
||||
encryptor = RSA.importKey(private_key)
|
||||
|
||||
encrypted_data = encryptor.decrypt(message)
|
||||
|
||||
with open(output_filename, 'wb') as encrypted_file:
|
||||
encrypted_file.write(encrypted_data)
|
||||
|
||||
parser = argparse.ArgumentParser(description='Create a license file.')
|
||||
parser.add_argument('--users', type=int, default=20,
|
||||
help='Number of users allowed by the license')
|
||||
parser.add_argument('--days', type=int, default=30,
|
||||
help='Number of days for which the license is valid')
|
||||
parser.add_argument('--warn', type=int, default=7,
|
||||
help='Number of days prior to expiration to warn users')
|
||||
parser.add_argument('--output', type=str, required=True,
|
||||
help='File in which to store the license')
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = parser.parse_args()
|
||||
print ('Creating license for %s users for %s days in file: %s' %
|
||||
(args.users, args.days, args.output))
|
||||
|
||||
license_data = {
|
||||
'LICENSE_EXPIRATION': datetime.utcnow() + timedelta(days=args.days),
|
||||
'LICENSE_USER_LIMIT': args.users,
|
||||
'LICENSE_EXPIRATION_WARNING': datetime.utcnow() + timedelta(days=(args.days - args.warn)),
|
||||
}
|
||||
|
||||
encrypt(pickle.dumps(license_data, 2), args.output)
|
Reference in a new issue