From 7d3a3db7e37aa3df48c532131da588a5def509ec Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Sun, 27 Aug 2023 19:55:09 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(=5F=5Fmain=5F=5F.py):=20re?= =?UTF-8?q?factor=20imports=20to=20improve=20readability=20and=20maintaina?= =?UTF-8?q?bility=20=E2=9C=A8=20feat(=5F=5Fmain=5F=5F.py):=20add=20'superu?= =?UTF-8?q?ser'=20command=20to=20create=20a=20superuser=20with=20provided?= =?UTF-8?q?=20username=20and=20password?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/__main__.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/backend/langflow/__main__.py b/src/backend/langflow/__main__.py index c86e9863f..b362d2fa9 100644 --- a/src/backend/langflow/__main__.py +++ b/src/backend/langflow/__main__.py @@ -1,8 +1,9 @@ import sys import time import httpx -from langflow.services.manager import initialize_settings_manager -from langflow.services.utils import get_settings_manager +from langflow.services.database.utils import session_getter +from langflow.services.manager import initialize_services, initialize_settings_manager +from langflow.services.utils import get_db_manager, get_settings_manager from langflow.utils.util import get_number_of_workers from multiprocess import Process # type: ignore import platform @@ -312,6 +313,24 @@ def run_langflow(host, port, log_level, options, app): sys.exit(1) +@app.command() +def superuser( + username: str = typer.Option(..., prompt=True, help="Username for the superuser."), + password: str = typer.Option( + ..., prompt=True, hide_input=True, help="Password for the superuser." + ), +): + initialize_services() + db_manager = get_db_manager() + with session_getter(db_manager) as session: + from langflow.services.auth.utils import create_super_user + + if create_super_user(session, username, password): + typer.echo("Superuser created successfully.") + else: + typer.echo("Superuser creation failed.") + + def main(): app()