2019-05-08 14:58:41 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2019-11-05 15:18:03 +01:00
|
|
|
|
2022-07-08 09:47:47 +02:00
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
2024-09-03 15:49:09 +02:00
|
|
|
from lib import ail_orgs
|
2024-07-01 14:54:19 +02:00
|
|
|
from lib import ail_users
|
2019-05-08 14:58:41 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
2024-09-03 15:49:09 +02:00
|
|
|
user_id = 'admin@admin.test'
|
|
|
|
password = ail_users.gen_password()
|
|
|
|
|
2019-06-20 14:47:59 +02:00
|
|
|
# create role_list
|
2024-09-05 14:41:13 +02:00
|
|
|
ail_users._create_roles()
|
2022-07-08 09:47:47 +02:00
|
|
|
|
2024-09-03 15:49:09 +02:00
|
|
|
if not ail_users.exists_user(user_id):
|
|
|
|
# Create Default Org
|
|
|
|
org = ail_orgs.create_default_org()
|
|
|
|
ail_users.create_user(user_id, password=password, admin_id='admin@admin.test', org_uuid=org.get_uuid(), role='admin')
|
|
|
|
# EDIT Password
|
|
|
|
else:
|
|
|
|
ail_users.edit_user('admin@admin.test', user_id, password=password, chg_passwd=True)
|
2022-07-08 09:47:47 +02:00
|
|
|
|
2024-07-01 14:54:19 +02:00
|
|
|
token = ail_users.get_default_admin_token()
|
2019-05-08 14:58:41 +02:00
|
|
|
|
2019-06-06 21:27:13 +02:00
|
|
|
default_passwd_file = os.path.join(os.environ['AIL_HOME'], 'DEFAULT_PASSWORD')
|
|
|
|
to_write_str = '# Password Generated by default\n# This file is deleted after the first login\n#\nemail=admin@admin.test\npassword='
|
2022-07-08 09:47:47 +02:00
|
|
|
to_write_str = f'{to_write_str}{password}\nAPI_Key={token}\n'
|
2019-06-06 21:27:13 +02:00
|
|
|
with open(default_passwd_file, 'w') as f:
|
|
|
|
f.write(to_write_str)
|
|
|
|
|
2024-07-01 14:54:19 +02:00
|
|
|
print(f'new user created: {user_id}')
|
|
|
|
print(f'password: {password}')
|
|
|
|
print(f'token: {token}')
|