Skip to content

Commit

Permalink
wip: config refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
grillazz committed Apr 5, 2024
1 parent 354b631 commit ebcf103
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ WEB_SERVER=web_server
MONGODB_HOST=mongodb
MONGODB_PORT=27017
MONGODB_USER=farmer
MONGODB_PASS=tractor
MONGO_DB=greenhouse
MONGO_COLLECTION=greens
MONGO_TEST_DB=farmland
MONGODB_PASSWORD=tractor
MONGODB_DATABASE=greenhouse
MONGODB_COLLECTION=greens
MONGODB_TEST=farmland
MONGO_URL=mongodb://farmer:tractor@mongodb:27017/?retryWrites=true&w=majority

8 changes: 4 additions & 4 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
MONGODB_HOST: mongodb
MONGODB_PORT: 27017
MONGODB_USER: farmer
MONGODB_PASS: tractor
MONGO_DB: greenhouse
MONGO_COLLECTION: greens
MONGO_TEST_DB: farmland
MONGODB_PASSWORD: tractor
MONGODB_DATABASE: greenhouse
MONGODB_COLLECTION: greens
MONGODB_TEST: farmland
MONGO_URL: mongodb://farmer:[email protected]:27017/?retryWrites=true&w=majority

services:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ services:
ports:
- "27017:27017"
environment:
- "MONGO_INITDB_DATABASE=${MONGO_DB}"
- "MONGO_INITDB_DATABASE=${MONGODB_DATABASE}"
- "MONGO_INITDB_ROOT_USERNAME=${MONGODB_USER}"
- "MONGO_INITDB_ROOT_PASSWORD=${MONGODB_PASS}"
- "MONGO_INITDB_ROOT_PASSWORD=${MONGODB_PASSWORD}"
command:
mongod --quiet --logpath /dev/null
8 changes: 4 additions & 4 deletions greens/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class Settings(BaseSettings):
web_server: str = os.getenv("WEB_SERVER", "web_server")

db_url: str = os.getenv("MONGO_URL", "")
db_name: str = os.getenv("MONGO_DB", "")
collection: str = os.getenv("MONGO_COLLECTION", "")
test_db_name: str = os.getenv("MONGO_TEST_DB", "")
mongodb_database: str = os.getenv("MONGODB_DATABASE", "")
collection: str = os.getenv("MONGODB_COLLECTION", "")
mongodb_test: str = os.getenv("MONGODB_TEST", "")

MONGODB_HOST: str
MONGODB_PORT: int
Expand All @@ -48,7 +48,7 @@ def mongodb_url(self) -> MongoDsn:
username=self.MONGODB_USER,
password=self.MONGODB_PASSWORD,

path=self.db_name,
path=self.mongodb_name, # TODO: url query params goes here
)

settings = Settings()
2 changes: 1 addition & 1 deletion greens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def lifespan(app: FastAPI):
app.state.logger = get_logger(__name__)
app.state.logger.info("Starting greens on your farmland...mmm")
app.state.mongo_client, app.state.mongo_db, app.state.mongo_collection = await init_mongo(
global_settings.db_name, global_settings.db_url, global_settings.collection
global_settings.mongodb_database, global_settings.db_url, global_settings.collection
)
try:
yield
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ async def client() -> AsyncGenerator:
) as client:
app.state.logger = get_logger(__name__)
app.state.mongo_client, app.state.mongo_db, app.state.mongo_collection = await init_mongo(
global_settings.test_db_name, global_settings.db_url, global_settings.collection
global_settings.mongodb_test, global_settings.db_url, global_settings.collection
)
yield client

0 comments on commit ebcf103

Please sign in to comment.