mirror of
https://github.com/fastogt/pyfastogt
synced 2025-02-12 14:41:52 +00:00
Request key input
This commit is contained in:
parent
a7134cade5
commit
71e49ca006
1 changed files with 64 additions and 0 deletions
64
pyfastogt/exe/request_fastogt_license_key_input
Executable file
64
pyfastogt/exe/request_fastogt_license_key_input
Executable file
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env python3
|
||||
import subprocess
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
|
||||
from pyfastogt.utils import is_valid_email
|
||||
|
||||
PROJECT_NAME = 'request_license'
|
||||
|
||||
LICENSE_SERVER_URL = 'https://license.fastogt.com/v1/license'
|
||||
EXP_DAYS = 30
|
||||
|
||||
|
||||
def print_usage():
|
||||
print("Usage:\n"
|
||||
"[required] --email email_address (email for verification)\n"
|
||||
"[required] --license_key hardware_license_key (license_gen output)\n"
|
||||
"[required] --project project (Project for expire license)\n"
|
||||
"[optional] --expired_days days (License lifetime in days)\n")
|
||||
|
||||
|
||||
PROJECTS = ['fastocloud', 'fastocloud_pro', 'fastocloud_pro_ml', 'fastocloud_load_balance', 'fastocloud_epg']
|
||||
|
||||
if __name__ == "__main__":
|
||||
project_line = 'Please select project number: \n'
|
||||
for i, proj in enumerate(PROJECTS):
|
||||
project_line += '{0} ({1})\n'.format(proj, i)
|
||||
|
||||
while True:
|
||||
email = input('Please input your email: ')
|
||||
if not is_valid_email(email):
|
||||
print("Error! Invalid email. Try again.")
|
||||
continue
|
||||
|
||||
try:
|
||||
project_num = int(input(project_line))
|
||||
project = PROJECTS[project_num]
|
||||
except ValueError:
|
||||
print("Error! This is not a valid number. Try again.")
|
||||
except IndexError:
|
||||
print("Error! This is not a valid number. Try again.")
|
||||
else:
|
||||
break
|
||||
|
||||
now = datetime.now()
|
||||
expired_time = int(now.timestamp() + EXP_DAYS * 24 * 3600) * 1000
|
||||
license_key = subprocess.getoutput('license_gen')
|
||||
|
||||
r = requests.post(url=LICENSE_SERVER_URL,
|
||||
json={'email': email, 'license': license_key, 'project': project, 'exp_time': expired_time})
|
||||
|
||||
try:
|
||||
response = r.json()
|
||||
except:
|
||||
response = {'error': 'Invalid response'}
|
||||
|
||||
if r.status_code == 200 or r.status_code == 201:
|
||||
print(response['exp_license'])
|
||||
sys.exit(0)
|
||||
|
||||
print('Request failed, status code: {0}, error: {1}'.format(r.status_code, response['error']))
|
||||
sys.exit(1)
|
Loading…
Reference in a new issue