-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
35 lines (30 loc) · 960 Bytes
/
setup.py
File metadata and controls
35 lines (30 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
Adds an api key to the database
"""
import argparse
from app import app, db
from app.models import ApiKey, ApiKeyPermission
from app.models.enums import ProductEnum
# Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument('name')
parser.add_argument('-p', '--permission', action='append')
args = parser.parse_args()
# Create API Key
print('Creating API Key...')
with app.app_context():
apikey = ApiKey()
apikey.name = args.name
for productLabel in args.permission:
print('permission: {}'.format(productLabel))
permission = ApiKeyPermission()
product = ProductEnum.from_str(productLabel)
if product == None:
continue
permission.product = product
apikey.permissions.append(permission)
db.session.add(permission)
token = apikey.token
db.session.add(apikey)
db.session.commit()
print('The generated token is:\n\n {}\n\n'.format(token))