def init_mongo_data(): try: _apply_migrations(log) _ensure_uuid() company_id = _ensure_company(get_default_company(), "clearml", log) _ensure_default_queue(company_id) fixed_mode = FixedUser.enabled() for user, credentials in config.get("secure.credentials", {}).items(): user_data = { "name": user, "role": credentials.role, "email": f"{user}@example.com", "key": credentials.user_key, "secret": credentials.user_secret, } revoke = fixed_mode and credentials.get("revoke_in_fixed_mode", False) user_id = _ensure_auth_user(user_data, company_id, log=log, revoke=revoke) if credentials.role == Role.user: _ensure_backend_user(user_id, company_id, credentials.display_name) if fixed_mode: log.info("Fixed users mode is enabled") FixedUser.validate() if FixedUser.guest_enabled(): _ensure_company(FixedUser.get_guest_user().company, "guests", log) for user in FixedUser.from_config(): try: ensure_fixed_user(user, log=log) except Exception as ex: log.error(f"Failed creating fixed user {user.name}: {ex}") except Exception as ex: log.exception("Failed initializing mongodb")
def fixed_users_mode(call: APICall, *_, **__): server_errors = { name: error for name, error in zip( ("missed_es_upgrade", "es_connection_error"), (info.missed_es_upgrade, info.es_connection_error), ) if error } data = { "enabled": FixedUser.enabled(), "guest": {"enabled": FixedUser.guest_enabled()}, "server_errors": server_errors, } guest_user = FixedUser.get_guest_user() if guest_user: data["guest"]["name"] = guest_user.name data["guest"]["username"] = guest_user.username data["guest"]["password"] = guest_user.password call.result.data = data