-
Notifications
You must be signed in to change notification settings - Fork 33
/
bootstrap_admin.py
executable file
·53 lines (46 loc) · 1.7 KB
/
bootstrap_admin.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
from datetime import datetime
from kqueen.models import Organization, User
from kqueen.server import create_app
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("organization", help="Organization name")
parser.add_argument("namespace", help="Organization namespace")
parser.add_argument("username", help="Admin username")
parser.add_argument("password", help="Admin password")
organization_id = '22d8df64-4ac9-4be0-89a7-c45ea0fc85da'
user_id = '09587e34-812d-4efc-af17-fbfd7315674c'
def main():
args = parser.parse_args()
app = create_app()
with app.app_context():
# Organization and user
try:
organization = Organization(
id=organization_id,
name=args.organization,
namespace=args.namespace,
created_at=datetime.utcnow()
)
organization.save()
print('Organization {} successfully created!'.format(organization.name))
except Exception:
raise Exception('Adding {} organization failed'.format(args.organization))
try:
user = User.create(
None,
id=user_id,
username=args.username,
password=args.password,
email='[email protected]',
organization=organization,
created_at=datetime.utcnow(),
role='superadmin',
active=True
)
user.save()
print('User {} successfully created!'.format(user.username))
except Exception:
raise Exception('Adding {} user failed'.format(args.username))
if __name__ == "__main__":
main()