Commit d2d4b6c7 authored by Manuel's avatar Manuel

changed add_users.py s.t. it consumes a json file instead of hardcoded values

parent 9c1ccb14
...@@ -13,3 +13,5 @@ src/modules/certificate/articonf1.crt ...@@ -13,3 +13,5 @@ src/modules/certificate/articonf1.crt
src/modules/certificate/articonf1-chain.crt src/modules/certificate/articonf1-chain.crt
src/modules/security/regular_user_credentials.json src/modules/security/regular_user_credentials.json
src/modules/security/default_users.json
# add modules folder to interpreter path # add modules folder to interpreter path
import sys import sys
import os import os
import json
import prance import prance
from pathlib import Path from pathlib import Path
from typing import Dict, Any from typing import Dict, Any
...@@ -10,7 +11,20 @@ if os.path.exists(modules_path): ...@@ -10,7 +11,20 @@ if os.path.exists(modules_path):
sys.path.insert(1, modules_path) sys.path.insert(1, modules_path)
from services.user_service import UserService from services.user_service import UserService
from env_info import is_running_locally
if __name__ == "__main__": if __name__ == "__main__":
UserService.add("regular@articonf1.itec.aau.at", "GBILLjaZE0Wyea9Y9ByS", role="u") if is_running_locally():
UserService.add("root@articonf1.itec.aau.at", "CJG6zD0mAjvo5zdVBftY", role="a") path = f'{modules_path}/security/default_users.json'
\ No newline at end of file else:
path = '/srv/articonf/default_users.json'
with open(path, "r") as file_handler:
content = file_handler.read()
users = json.loads(content)
for user in users:
if "username" in user and "password" in user and "role" in user:
UserService.add(user["username"], user["password"], role=user["role"])
else:
print(f"Missing field in user object, required=(username, password, role), given=({user.keys()})")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment