Skip to content

Commit c8003a2

Browse files
perf: Enviroment config
1 parent 4542774 commit c8003a2

File tree

3 files changed

+1
-73
lines changed

3 files changed

+1
-73
lines changed

.env.example

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
2-
# Before running, please copy .env.example to .env
3-
DOMAIN=localhost
4-
FRONTEND_HOST=http://localhost:5173
5-
ENVIRONMENT=local
61
PROJECT_NAME="SQLBot"
7-
STACK_NAME=SQLBot
8-
92
# Backend
103
BACKEND_CORS_ORIGINS="http://localhost,http://localhost:5173,https://localhost,https://localhost:5173"
114
SECRET_KEY=y5txe1mRmS_JpOrUzFzHEu-kIQn3lf7ll0AOv9DQh0s
12-
FIRST_SUPERUSER=[email protected]
13-
FIRST_SUPERUSER_PASSWORD=123456 # Change this to your pwd
145

156
TOKEN_KEY="X-SQLBOT-TOKEN"
167
DEFAULT_PWD="SQLBot@123456"
@@ -31,12 +22,6 @@ POSTGRES_DB=sqlbot
3122
POSTGRES_USER=root
3223
POSTGRES_PASSWORD=132456 # Change this to your pwd
3324

34-
SENTRY_DSN=
35-
36-
# Configure these with your own Docker registry images
37-
DOCKER_IMAGE_BACKEND=backend
38-
DOCKER_IMAGE_FRONTEND=frontend
39-
4025
MCP_IMAGE_PATH=/opt/sqlbot/images
4126
MCP_IMAGE_HOST=http://localhost:3000
4227
SERVER_IMAGE_HOST=https://sqlbot.fit2cloud.cn/images/

backend/common/core/config.py

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import secrets
2-
import warnings
32
from typing import Annotated, Any, Literal
43

54
from pydantic import (
65
AnyUrl,
76
BeforeValidator,
8-
EmailStr,
9-
HttpUrl,
107
PostgresDsn,
118
computed_field,
12-
model_validator,
139
)
1410
from pydantic_core import MultiHostUrl
1511
from pydantic_settings import BaseSettings, SettingsConfigDict
@@ -31,12 +27,12 @@ class Settings(BaseSettings):
3127
env_ignore_empty=True,
3228
extra="ignore",
3329
)
30+
PROJECT_NAME: str = "SQLBot"
3431
API_V1_STR: str = "/api/v1"
3532
SECRET_KEY: str = secrets.token_urlsafe(32)
3633
# 60 minutes * 24 hours * 8 days = 8 days
3734
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 8
3835
FRONTEND_HOST: str = "http://localhost:5173"
39-
ENVIRONMENT: Literal["local", "staging", "production"] = "local"
4036

4137
BACKEND_CORS_ORIGINS: Annotated[
4238
list[AnyUrl] | str, BeforeValidator(parse_cors)
@@ -49,8 +45,6 @@ def all_cors_origins(self) -> list[str]:
4945
self.FRONTEND_HOST
5046
]
5147

52-
PROJECT_NAME: str
53-
SENTRY_DSN: HttpUrl | None = None
5448
POSTGRES_SERVER: str
5549
POSTGRES_PORT: int = 5432
5650
POSTGRES_USER: str
@@ -81,55 +75,8 @@ def SQLALCHEMY_DATABASE_URI(self) -> PostgresDsn:
8175
path=self.POSTGRES_DB,
8276
)
8377

84-
SMTP_TLS: bool = True
85-
SMTP_SSL: bool = False
86-
SMTP_PORT: int = 587
87-
SMTP_HOST: str | None = None
88-
SMTP_USER: str | None = None
89-
SMTP_PASSWORD: str | None = None
90-
EMAILS_FROM_EMAIL: EmailStr | None = None
91-
EMAILS_FROM_NAME: EmailStr | None = None
9278
MCP_IMAGE_PATH: str
9379
MCP_IMAGE_HOST: str
9480
SERVER_IMAGE_HOST: str
9581

96-
@model_validator(mode="after")
97-
def _set_default_emails_from(self) -> Self:
98-
if not self.EMAILS_FROM_NAME:
99-
self.EMAILS_FROM_NAME = self.PROJECT_NAME
100-
return self
101-
102-
EMAIL_RESET_TOKEN_EXPIRE_HOURS: int = 48
103-
104-
@computed_field # type: ignore[prop-decorator]
105-
@property
106-
def emails_enabled(self) -> bool:
107-
return bool(self.SMTP_HOST and self.EMAILS_FROM_EMAIL)
108-
109-
EMAIL_TEST_USER: EmailStr = "[email protected]"
110-
FIRST_SUPERUSER: EmailStr
111-
FIRST_SUPERUSER_PASSWORD: str
112-
113-
def _check_default_secret(self, var_name: str, value: str | None) -> None:
114-
if value == "changethis":
115-
message = (
116-
f'The value of {var_name} is "changethis", '
117-
"for security, please change it, at least for deployments."
118-
)
119-
if self.ENVIRONMENT == "local":
120-
warnings.warn(message, stacklevel=1)
121-
else:
122-
raise ValueError(message)
123-
124-
@model_validator(mode="after")
125-
def _enforce_non_default_secrets(self) -> Self:
126-
self._check_default_secret("SECRET_KEY", self.SECRET_KEY)
127-
self._check_default_secret("POSTGRES_PASSWORD", self.POSTGRES_PASSWORD)
128-
self._check_default_secret(
129-
"FIRST_SUPERUSER_PASSWORD", self.FIRST_SUPERUSER_PASSWORD
130-
)
131-
132-
return self
133-
134-
13582
settings = Settings() # type: ignore

backend/main.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from fastapi.concurrency import asynccontextmanager
2-
import sentry_sdk
32
from fastapi import FastAPI
43
from fastapi.routing import APIRoute
54
from starlette.middleware.cors import CORSMiddleware
@@ -38,9 +37,6 @@ def custom_generate_unique_id(route: APIRoute) -> str:
3837
return f"{tag}-{route.name}"
3938

4039

41-
if settings.SENTRY_DSN and settings.ENVIRONMENT != "local":
42-
sentry_sdk.init(dsn=str(settings.SENTRY_DSN), enable_tracing=True)
43-
4440
app = FastAPI(
4541
title=settings.PROJECT_NAME,
4642
openapi_url=f"{settings.API_V1_STR}/openapi.json",

0 commit comments

Comments
 (0)