2019-05-08 12:58:41 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2019-11-05 14:18:03 +00:00
|
|
|
|
2022-07-08 07:47:47 +00:00
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
2024-09-03 13:49:09 +00:00
|
|
|
from lib import ail_orgs
|
2024-07-01 12:54:19 +00:00
|
|
|
from lib import ail_users
|
2019-05-08 12:58:41 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
2024-09-03 13:49:09 +00:00
|
|
|
user_id = 'admin@admin.test'
|
|
|
|
password = ail_users.gen_password()
|
|
|
|
|
2019-06-20 12:47:59 +00:00
|
|
|
# create role_list
|
2024-09-05 12:41:13 +00:00
|
|
|
ail_users._create_roles()
|
2022-07-08 07:47:47 +00:00
|
|
|
|
2024-09-03 13:49:09 +00: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 07:47:47 +00:00
|
|
|
|
2024-07-01 12:54:19 +00:00
|
|
|
token = ail_users.get_default_admin_token()
|
2019-05-08 12:58:41 +00:00
|
|
|
|
2019-06-06 19:27:13 +00: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 07:47:47 +00:00
|
|
|
to_write_str = f'{to_write_str}{password}\nAPI_Key={token}\n'
|
2019-06-06 19:27:13 +00:00
|
|
|
with open(default_passwd_file, 'w') as f:
|
|
|
|
f.write(to_write_str)
|
|
|
|
|
2024-07-01 12:54:19 +00:00
|
|
|
print(f'new user created: {user_id}')
|
|
|
|
print(f'password: {password}')
|
|
|
|
print(f'token: {token}')
|