Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/api/v1/endpoints/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app.core.grpc_clients import get_artifact_storage_client
from app.grpc.clients.artifact_storage_client import ArtifactStorageClient
from app.api import deps
from app.models.user import User
from app.models.base import User

router = APIRouter()

Expand Down
42 changes: 29 additions & 13 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class Settings(BaseSettings):
refresh_token_expire_days: int = Field(default=7, alias="REFRESH_TOKEN_EXPIRE_DAYS")

# CORS
# Comma-separated list of allowed origins
# Handles both JSON lists and comma-separated strings
cors_origins: Any = Field(
default=["http://localhost:3000", "http://localhost:8000"],
default="http://localhost:3000,http://localhost:8000",
alias="CORS_ORIGINS",
)
cors_allow_credentials: bool = Field(default=True, alias="CORS_ALLOW_CREDENTIALS")
Expand All @@ -64,7 +64,7 @@ class Settings(BaseSettings):

# NATS Message Bus
nats_servers: Any = Field(
default=["nats://localhost:4222"],
default="nats://localhost:4222",
alias="NATS_SERVERS",
)
nats_cluster_id: str = Field(default="xether-cluster", alias="NATS_CLUSTER_ID")
Expand All @@ -74,23 +74,38 @@ class Settings(BaseSettings):
artifact_storage_grpc_port: int = Field(default=50051, alias="ARTIFACT_STORAGE_GRPC_PORT")
artifact_storage_http_port: int = Field(default=8080, alias="ARTIFACT_STORAGE_HTTP_PORT")

@field_validator("cors_origins", mode="before")
@field_validator("cors_origins", mode="plain")
@classmethod
def parse_cors_origins(cls, v: Any) -> list[str]:
"""Parse CORS origins from comma-separated string or list."""
def parse_cors_origins(cls, v: Any) -> Any:
"""Parse CORS origins with robustness against pydantic-settings parsing."""
if isinstance(v, str):
return [origin.strip() for origin in v.split(",")]
elif isinstance(v, list):
# Clean up potential shell quotes
v = v.strip("'").strip('"')
if v.startswith("[") and v.endswith("]"):
try:
import json
return json.loads(v)
except Exception:
pass
return [origin.strip() for origin in v.split(",") if origin.strip()]
if isinstance(v, list):
return v
return ["http://localhost:3000", "http://localhost:8000"]

@field_validator("nats_servers", mode="before")
@field_validator("nats_servers", mode="plain")
@classmethod
def parse_nats_servers(cls, v: Any) -> list[str]:
"""Parse NATS servers from comma-separated string or list."""
def parse_nats_servers(cls, v: Any) -> Any:
"""Parse NATS servers with robustness."""
if isinstance(v, str):
return [server.strip() for server in v.split(",")]
elif isinstance(v, list):
v = v.strip("'").strip('"')
if v.startswith("[") and v.endswith("]"):
try:
import json
return json.loads(v)
except Exception:
pass
return [server.strip() for server in v.split(",") if server.strip()]
if isinstance(v, list):
return v
return ["nats://localhost:4222"]

Expand All @@ -108,4 +123,5 @@ def redis_url_str(self) -> str:
@lru_cache
def get_settings() -> Settings:
"""Get cached settings instance."""
# print("DEBUG: Loading settings...")
return Settings() # type: ignore[call-arg]
58 changes: 58 additions & 0 deletions app/grpc/generated/artifact_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading