mirror of
https://github.com/ijaric/voice_assistant.git
synced 2025-05-24 14:33:26 +00:00
feat: [#38] add proxy settings
This commit is contained in:
parent
005dd3ce0e
commit
306ae27171
|
@ -5,6 +5,12 @@ POSTGRES_USER=user
|
|||
POSTGRES_PASSWORD=Qwe123
|
||||
POSTGRES_DB_NAME=api_db
|
||||
|
||||
PROXY_HOST=255.255.255.255
|
||||
PROXY_PORT=8888
|
||||
PROXY_USER=YOUR_USER
|
||||
PROXY_PASSWORD=YOUR_PASSWORD
|
||||
PROXY_ENABLE=False
|
||||
|
||||
NGINX_PORT=80
|
||||
API_HOST=0.0.0.0
|
||||
API_PORT=8000
|
||||
|
|
|
@ -16,3 +16,4 @@ class Settings(pydantic_settings.BaseSettings):
|
|||
project: app_split_settings.ProjectSettings = pydantic.Field(
|
||||
default_factory=lambda: app_split_settings.ProjectSettings()
|
||||
)
|
||||
proxy: app_split_settings.ProxySettings = pydantic.Field(default_factory=lambda: app_split_settings.ProxySettings())
|
||||
|
|
|
@ -3,6 +3,7 @@ from .app import *
|
|||
from .logger import *
|
||||
from .postgres import *
|
||||
from .project import *
|
||||
from .proxy import *
|
||||
|
||||
__all__ = [
|
||||
"ApiSettings",
|
||||
|
@ -10,5 +11,6 @@ __all__ = [
|
|||
"LoggingSettings",
|
||||
"PostgresSettings",
|
||||
"ProjectSettings",
|
||||
"ProxySettings",
|
||||
"get_logging_config",
|
||||
]
|
||||
|
|
40
src/assistant/lib/app/split_settings/proxy.py
Normal file
40
src/assistant/lib/app/split_settings/proxy.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
import pydantic
|
||||
import pydantic_settings
|
||||
|
||||
import lib.app.split_settings.utils as app_split_settings_utils
|
||||
|
||||
|
||||
class ProxySettings(pydantic_settings.BaseSettings):
|
||||
model_config = pydantic_settings.SettingsConfigDict(
|
||||
env_file=app_split_settings_utils.ENV_PATH,
|
||||
env_prefix="PROXY_",
|
||||
env_file_encoding="utf-8",
|
||||
extra="ignore",
|
||||
)
|
||||
user: str | None = None
|
||||
password: pydantic.SecretStr | None = None
|
||||
host: str | None = None
|
||||
port: int | None = None
|
||||
enable: bool = False
|
||||
|
||||
@property
|
||||
def dsn(self) -> str:
|
||||
if self.user and self.password:
|
||||
password = self.password.get_secret_value()
|
||||
return f"http://{self.user}:{password}@{self.host}:{self.port}"
|
||||
return f"http://{self.host}:{self.port}"
|
||||
|
||||
@pydantic.computed_field
|
||||
@property
|
||||
def dsn_as_safe_url(self) -> str:
|
||||
if self.user and self.password:
|
||||
return f"http://{self.user}:{self.password}@{self.host}:{self.port}"
|
||||
return f"http://{self.host}:{self.port}"
|
||||
|
||||
@pydantic.model_validator(mode="after")
|
||||
def check_proxy(self):
|
||||
if not self.enable:
|
||||
return self
|
||||
if self.host and self.port:
|
||||
return self
|
||||
raise ValueError("Proxy settings must be set if use_proxy is True")
|
Loading…
Reference in New Issue
Block a user