🐛 fix(manager.py): call set_ready() method on the created service to indicate it is ready
🐛 fix(auth.py): validate superuser and superuser_password fields if AUTO_LOGIN is true ✨ feat(utils.py): add initialize_database() function to initialize the database connection ✨ feat(utils.py): call initialize_database() before setting up the superuser if the database manager is ready
This commit is contained in:
parent
4bfbb8d3aa
commit
f5c20ac166
3 changed files with 29 additions and 8 deletions
|
|
@ -61,6 +61,7 @@ class ServiceManager:
|
|||
self.services[service_name] = self.factories[service_name].create(
|
||||
**dependent_services
|
||||
)
|
||||
self.services[service_name].set_ready()
|
||||
|
||||
def _validate_service_creation(self, service_name: ServiceType):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -49,6 +49,24 @@ class AuthSettings(BaseSettings):
|
|||
self.SUPERUSER = DEFAULT_SUPERUSER
|
||||
self.SUPERUSER_PASSWORD = DEFAULT_SUPERUSER_PASSWORD
|
||||
|
||||
# If autologin is true, then we need to set the credentials to
|
||||
# the default values
|
||||
# so we need to validate the superuser and superuser_password
|
||||
# fields
|
||||
@validator("SUPERUSER", "SUPERUSER_PASSWORD", pre=True)
|
||||
def validate_superuser(cls, value, values):
|
||||
if values.get("AUTO_LOGIN"):
|
||||
if value != DEFAULT_SUPERUSER:
|
||||
value = DEFAULT_SUPERUSER
|
||||
logger.debug("Resetting superuser to default value")
|
||||
if values.get("SUPERUSER_PASSWORD") != DEFAULT_SUPERUSER_PASSWORD:
|
||||
values["SUPERUSER_PASSWORD"] = DEFAULT_SUPERUSER_PASSWORD
|
||||
logger.debug("Resetting superuser password to default value")
|
||||
|
||||
return value
|
||||
|
||||
return value
|
||||
|
||||
@validator("SECRET_KEY", pre=True)
|
||||
def get_secret_key(cls, value, values):
|
||||
config_dir = values.get("CONFIG_DIR")
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from langflow.services.auth.utils import create_super_user
|
||||
from langflow.services.database.utils import initialize_database
|
||||
from langflow.services.manager import service_manager
|
||||
from langflow.services.schema import ServiceType
|
||||
from langflow.services.settings.constants import (
|
||||
|
|
@ -18,17 +19,16 @@ def setup_superuser():
|
|||
# if it does not exist.
|
||||
settings_manager = get_settings_manager()
|
||||
if settings_manager.auth_settings.AUTO_LOGIN:
|
||||
logger.debug("AUTO_LOGIN is set to True. Not creating superuser automatically.")
|
||||
return
|
||||
logger.debug("AUTO_LOGIN is set to True. Creating default superuser.")
|
||||
|
||||
session = next(get_session())
|
||||
username = settings_manager.auth_settings.SUPERUSER
|
||||
password = settings_manager.auth_settings.SUPERUSER_PASSWORD
|
||||
if username == DEFAULT_SUPERUSER and password == DEFAULT_SUPERUSER_PASSWORD:
|
||||
logger.debug(
|
||||
"Using default superuser credentials. Please change them in production."
|
||||
)
|
||||
return
|
||||
logger.debug("Default superuser credentials detected.")
|
||||
logger.debug("Creating default superuser.")
|
||||
else:
|
||||
logger.debug("Creating superuser.")
|
||||
|
||||
try:
|
||||
from langflow.services.database.models.user.user import User
|
||||
|
|
@ -136,6 +136,8 @@ def initialize_services():
|
|||
# Test cache connection
|
||||
service_manager.get(ServiceType.CACHE_MANAGER)
|
||||
# Test database connection
|
||||
service_manager.get(ServiceType.DATABASE_MANAGER)
|
||||
db_manager = service_manager.get(ServiceType.DATABASE_MANAGER)
|
||||
# Setup the superuser
|
||||
setup_superuser()
|
||||
initialize_database()
|
||||
if db_manager.ready:
|
||||
setup_superuser()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue