11import secrets
22import warnings
3- from typing import Annotated , Any , Literal
3+ from typing import Annotated , Any , Dict , Literal , Optional
44
55from pydantic import (
66 AnyUrl ,
77 BeforeValidator ,
88 EmailStr ,
9+ Field ,
910 HttpUrl ,
1011 PostgresDsn ,
1112 computed_field ,
@@ -71,6 +72,72 @@ def SQLALCHEMY_DATABASE_URI(self) -> PostgresDsn:
7172 path = self .POSTGRES_DB ,
7273 )
7374
75+ # MongoDB settings
76+ MONGODB_SERVER : str = "localhost"
77+ MONGODB_PORT : int = 27017
78+ MONGODB_USER : str = ""
79+ MONGODB_PASSWORD : str = ""
80+ MONGODB_DB : str = "political_social_media"
81+ MONGODB_AUTH_SOURCE : str = "admin"
82+
83+ @computed_field # type: ignore[prop-decorator]
84+ @property
85+ def MONGODB_URI (self ) -> str :
86+ auth_part = ""
87+ if self .MONGODB_USER and self .MONGODB_PASSWORD :
88+ auth_part = f"{ self .MONGODB_USER } :{ self .MONGODB_PASSWORD } @"
89+
90+ auth_source = f"?authSource={ self .MONGODB_AUTH_SOURCE } " if auth_part else ""
91+ return f"mongodb://{ auth_part } { self .MONGODB_SERVER } :{ self .MONGODB_PORT } /{ self .MONGODB_DB } { auth_source } "
92+
93+ # Redis settings
94+ REDIS_SERVER : str = "localhost"
95+ REDIS_PORT : int = 6379
96+ REDIS_PASSWORD : str = ""
97+ REDIS_DB : int = 0
98+
99+ @computed_field # type: ignore[prop-decorator]
100+ @property
101+ def REDIS_URI (self ) -> str :
102+ auth_part = f":{ self .REDIS_PASSWORD } @" if self .REDIS_PASSWORD else ""
103+ return f"redis://{ auth_part } { self .REDIS_SERVER } :{ self .REDIS_PORT } /{ self .REDIS_DB } "
104+
105+ # Pinecone (Vector Database) settings
106+ PINECONE_API_KEY : str = ""
107+ PINECONE_ENVIRONMENT : str = "us-west1-gcp"
108+ PINECONE_INDEX_NAME : str = "political-content"
109+
110+ # Celery settings
111+ CELERY_BROKER : str = "amqp://guest:guest@localhost:5672//"
112+ CELERY_RESULT_BACKEND : str = "" # Will default to Redis URI if not set
113+ CELERY_TASK_SERIALIZER : str = "json"
114+ CELERY_RESULT_SERIALIZER : str = "json"
115+ CELERY_ACCEPT_CONTENT : list [str ] = ["json" ]
116+ CELERY_TIMEZONE : str = "UTC"
117+ CELERY_TASK_ROUTES : Dict [str , Dict [str , str ]] = {
118+ "app.tasks.scraping.*" : {"queue" : "scraping" },
119+ "app.tasks.analysis.*" : {"queue" : "analysis" },
120+ "app.tasks.notifications.*" : {"queue" : "notifications" },
121+ }
122+
123+ @computed_field # type: ignore[prop-decorator]
124+ @property
125+ def celery_result_backend_uri (self ) -> str :
126+ """Return Redis URI as the default Celery result backend if none specified."""
127+ return self .CELERY_RESULT_BACKEND or self .REDIS_URI
128+
129+ # Kafka settings
130+ KAFKA_BOOTSTRAP_SERVERS : str = "localhost:9092"
131+ KAFKA_CONSUMER_GROUP_ID : str = "political-media-analysis"
132+ KAFKA_TOPIC_SOCIAL_MEDIA_POSTS : str = "social-media-posts"
133+ KAFKA_TOPIC_SENTIMENT_ANALYSIS : str = "sentiment-analysis"
134+ KAFKA_TOPIC_ENTITY_RECOGNITION : str = "entity-recognition"
135+
136+ # NLP model settings
137+ SPACY_MODEL_NAME : str = "en_core_web_lg"
138+ TRANSFORMER_MODEL_NAME : str = "distilbert-base-uncased"
139+ SENTENCE_TRANSFORMER_MODEL_NAME : str = "all-MiniLM-L6-v2"
140+
74141 # Email settings
75142 SMTP_TLS : bool = True
76143 SMTP_SSL : bool = False
@@ -81,9 +148,6 @@ def SQLALCHEMY_DATABASE_URI(self) -> PostgresDsn:
81148 EMAILS_FROM_EMAIL : EmailStr | None = None
82149 EMAILS_FROM_NAME : EmailStr | None = None
83150
84- # Celery settings
85- CELERY_BROKER : str = "amqp://guest:guest@localhost:5672//"
86-
87151 @model_validator (mode = "after" )
88152 def _set_default_emails_from (self ) -> Self :
89153 if not self .EMAILS_FROM_NAME :
@@ -111,6 +175,9 @@ def _check_default_secret(self, var_name: str, value: str | None) -> None:
111175 def _enforce_non_default_secrets (self ) -> Self :
112176 """Enforce that secrets don't use default values."""
113177 self ._check_default_secret ("POSTGRES_PASSWORD" , self .POSTGRES_PASSWORD )
178+ self ._check_default_secret ("MONGODB_PASSWORD" , self .MONGODB_PASSWORD )
179+ self ._check_default_secret ("REDIS_PASSWORD" , self .REDIS_PASSWORD )
180+ self ._check_default_secret ("PINECONE_API_KEY" , self .PINECONE_API_KEY )
114181 self ._check_default_secret ("SECRET_KEY" , self .SECRET_KEY )
115182 self ._check_default_secret ("FIRST_SUPERUSER_PASSWORD" , self .FIRST_SUPERUSER_PASSWORD )
116183 return self
0 commit comments