2019-05-08 12:58:41 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2019-06-20 12:47:59 +00:00
|
|
|
import redis
|
2019-11-05 14:18:03 +00:00
|
|
|
|
|
|
|
sys.path.append(os.path.join(os.environ['AIL_BIN'], 'lib/'))
|
|
|
|
import ConfigLoader
|
2019-06-20 12:47:59 +00:00
|
|
|
|
|
|
|
sys.path.append(os.path.join(os.environ['AIL_FLASK'], 'modules'))
|
|
|
|
|
2019-07-05 13:20:47 +00:00
|
|
|
from Role_Manager import create_user_db, edit_user_db, get_default_admin_token, gen_password
|
2019-05-08 12:58:41 +00:00
|
|
|
|
2019-11-05 14:18:03 +00:00
|
|
|
config_loader = ConfigLoader.ConfigLoader()
|
2019-05-08 12:58:41 +00:00
|
|
|
|
2019-11-05 14:18:03 +00:00
|
|
|
r_serv = config_loader.get_redis_conn("ARDB_DB")
|
|
|
|
config_loader = None
|
2019-05-08 12:58:41 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
2019-06-20 12:47:59 +00:00
|
|
|
# create role_list
|
|
|
|
if not r_serv.exists('ail:all_role'):
|
|
|
|
r_serv.zadd('ail:all_role', 1, 'admin')
|
|
|
|
r_serv.zadd('ail:all_role', 2, 'analyst')
|
2019-11-20 15:15:08 +00:00
|
|
|
r_serv.zadd('ail:all_role', 3, 'user')
|
|
|
|
r_serv.zadd('ail:all_role', 4, 'user_no_api')
|
|
|
|
r_serv.zadd('ail:all_role', 5, 'read_only')
|
2019-06-20 12:47:59 +00:00
|
|
|
|
2019-05-08 12:58:41 +00:00
|
|
|
username = 'admin@admin.test'
|
2019-07-05 13:20:47 +00:00
|
|
|
password = gen_password()
|
2019-06-20 12:47:59 +00:00
|
|
|
if r_serv.exists('user_metadata:admin@admin.test'):
|
|
|
|
edit_user_db(username, password=password, role='admin')
|
|
|
|
else:
|
|
|
|
create_user_db(username, password, role='admin', default=True)
|
2019-06-19 13:00:25 +00:00
|
|
|
token = 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='
|
2020-04-23 08:48:13 +00:00
|
|
|
to_write_str = 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)
|
|
|
|
|
2019-05-08 12:58:41 +00:00
|
|
|
print('new user created: {}'.format(username))
|
|
|
|
print('password: {}'.format(password))
|
2019-07-05 13:20:47 +00:00
|
|
|
print('token: {}'.format(token))
|