feat: enhance environment variable support and update settings configuration (#5766)

*  (langflow/__main__.py): Add logic to dynamically update auth settings based on environment variables prefixed with "LANGFLOW_"
♻️ (auth.py): Refactor AuthSettings class to use model_config attribute for configuration settings instead of Config class

*  (langflow/__main__.py): dynamically load environment variables prefixed with "LANGFLOW_" into settings_service.settings for improved configuration flexibility

* [autofix.ci] apply automated fixes

* formatting code

* [autofix.ci] apply automated fixes

* ♻️ (langflow/__main__.py): refactor code to remove redundant loop that sets settings from environment variables

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Ítalo Johnny <italojohnnydosanjos@gmail.com>
This commit is contained in:
Cristhian Zanforlin Lousa 2025-01-20 03:03:29 -03:00 committed by GitHub
commit 6ac45a8638
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 5 deletions

View file

@ -1,5 +1,6 @@
import asyncio
import inspect
import os
import platform
import signal
import socket
@ -167,6 +168,11 @@ def run(
set_var_for_macos_issue()
settings_service = get_settings_service()
for key, value in os.environ.items():
new_key = key.replace("LANGFLOW_", "")
if hasattr(settings_service.auth_settings, new_key):
setattr(settings_service.auth_settings, new_key, value)
frame = inspect.currentframe()
valid_args: list = []
values: dict = {}
@ -179,6 +185,8 @@ def run(
settings_service.settings.update_settings(components_path=components_path)
elif hasattr(settings_service.settings, arg):
settings_service.set(arg, values[arg])
elif hasattr(settings_service.auth_settings, arg):
settings_service.auth_settings.set(arg, values[arg])
logger.debug(f"Loading config from cli parameter '{arg}': '{values[arg]}'")
host = settings_service.settings.host

View file

@ -5,7 +5,7 @@ from typing import Literal
from loguru import logger
from passlib.context import CryptContext
from pydantic import Field, SecretStr, field_validator
from pydantic_settings import BaseSettings
from pydantic_settings import BaseSettings, SettingsConfigDict
from langflow.services.settings.constants import DEFAULT_SUPERUSER, DEFAULT_SUPERUSER_PASSWORD
from langflow.services.settings.utils import read_secret_from_file, write_secret_to_file
@ -52,10 +52,7 @@ class AuthSettings(BaseSettings):
pwd_context: CryptContext = CryptContext(schemes=["bcrypt"], deprecated="auto")
class Config:
validate_assignment = True
extra = "ignore"
env_prefix = "LANGFLOW_"
model_config = SettingsConfigDict(validate_assignment=True, extra="ignore", env_prefix="LANGFLOW_")
def reset_credentials(self) -> None:
self.SUPERUSER = DEFAULT_SUPERUSER