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 api/src/core/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def _get_client() -> AsyncIOMotorClient:
global _client
if _client is None:
_client = AsyncIOMotorClient(settings.MONGODB_URI)
_client = AsyncIOMotorClient(settings.MONGODB_CONNECTION_URI)
return _client


Expand Down
25 changes: 24 additions & 1 deletion api/src/core/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pika
from urllib.parse import quote_plus

from pydantic import PostgresDsn, computed_field
from pydantic_settings import BaseSettings, SettingsConfigDict
Expand Down Expand Up @@ -31,8 +32,13 @@ class Settings(BaseSettings):
API_URL: str = "http://localhost:8000"

# MongoDB
MONGODB_URI: str = "mongodb://template_user:template_pass@mongo:27017/securelearning?authSource=securelearning"
MONGODB_URI: str = ""
MONGODB_HOST: str = "mongo"
MONGODB_PORT: int = 27017
MONGODB_USER: str = "template_user"
MONGODB_PASSWORD: str = "template_pass"
MONGODB_DB: str = "securelearning"
MONGODB_AUTH_SOURCE: str = ""
MONGODB_COLLECTION_TEMPLATES: str = "templates"
MONGODB_COLLECTION_TENANT_LOGOS: str = "tenant_logos"
MONGODB_COLLECTION_CONTENT: str = "content_pieces"
Expand Down Expand Up @@ -94,5 +100,22 @@ def PGSQL_DATABASE_URI(self) -> PostgresDsn:
port=self.POSTGRES_PORT,
path=self.POSTGRES_DB,
)

@computed_field
@property
def MONGODB_CONNECTION_URI(self) -> str:
if self.MONGODB_URI:
return self.MONGODB_URI

username = quote_plus(self.MONGODB_USER)
password = quote_plus(self.MONGODB_PASSWORD)
auth_source = quote_plus(self.MONGODB_AUTH_SOURCE or self.MONGODB_DB)
db_name = quote_plus(self.MONGODB_DB)

return (
f"mongodb://{username}:{password}"
f"@{self.MONGODB_HOST}:{self.MONGODB_PORT}/{db_name}"
f"?authSource={auth_source}"
)

settings = Settings() # type: ignore
8 changes: 6 additions & 2 deletions deployment/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,12 @@ services:
KEYCLOAK_URL: ${KEYCLOAK_INTERNAL_URL}
KEYCLOAK_ISSUER_URL: ${KC_HOSTNAME_URL}
CLIENT_SECRET: ${CLIENT_SECRET}
MONGODB_URI: mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongo:27017/${MONGO_DB}?authSource=${MONGO_DB}
MONGODB_DB: securelearning
MONGODB_HOST: mongo
MONGODB_PORT: 27017
MONGODB_USER: ${MONGO_USER}
MONGODB_PASSWORD: ${MONGO_PASSWORD}
MONGODB_DB: ${MONGO_DB}
MONGODB_AUTH_SOURCE: ${MONGO_DB}
MONGODB_COLLECTION_TEMPLATES: templates
FILE_STORAGE_BACKEND: ${FILE_STORAGE_BACKEND}
GARAGE_S3_ENDPOINT: ${GARAGE_S3_ENDPOINT}
Expand Down
8 changes: 6 additions & 2 deletions deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,12 @@ services:
KEYCLOAK_URL: ${KEYCLOAK_INTERNAL_URL}
KEYCLOAK_ISSUER_URL: ${KC_HOSTNAME_URL}
CLIENT_SECRET: ${CLIENT_SECRET}
MONGODB_URI: mongodb://${MONGO_USER}:${MONGO_PASSWORD}@mongo:27017/${MONGO_DB}?authSource=${MONGO_DB}
MONGODB_DB: securelearning
MONGODB_HOST: mongo
MONGODB_PORT: 27017
MONGODB_USER: ${MONGO_USER}
MONGODB_PASSWORD: ${MONGO_PASSWORD}
MONGODB_DB: ${MONGO_DB}
MONGODB_AUTH_SOURCE: ${MONGO_DB}
MONGODB_COLLECTION_TEMPLATES: templates
FILE_STORAGE_BACKEND: ${FILE_STORAGE_BACKEND}
GARAGE_S3_ENDPOINT: ${GARAGE_S3_ENDPOINT}
Expand Down
Loading