import os from pydantic_settings import BaseSettings, SettingsConfigDict class Configs(BaseSettings): """ MongoDB configuration settings. """ # MongoDB connection settings ENGINE: str = "mongodb" USERNAME: str = "appuser" # Application user PASSWORD: str = "apppassword" # Application password HOST: str = "10.10.2.13" PORT: int = 27017 DB: str = "appdb" # The application database AUTH_DB: str = "appdb" # Authentication is done against admin database @property def url(self): """Generate the database URL. mongodb://{MONGO_USERNAME}:{MONGO_PASSWORD}@{MONGO_HOST}:{MONGO_PORT}/{DB}?authSource={MONGO_AUTH_DB} """ # Include the database name in the URI return f"{self.ENGINE}://{self.USERNAME}:{self.PASSWORD}@{self.HOST}:{self.PORT}/{self.DB}?authSource={self.DB}" model_config = SettingsConfigDict(env_prefix="_MONGO_") # Create a singleton instance of the MongoDB configuration settings mongo_configs = Configs()