Skip to content

Commit

Permalink
fix mongo auth
Browse files Browse the repository at this point in the history
  • Loading branch information
grillazz committed Apr 17, 2024
1 parent 2f4fc0e commit 3ac5ef4
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ jobs:
MONGODB_DATABASE: greenhouse
MONGODB_COLLECTION: greens
MONGODB_TEST: farmland
MONGODB_PARAMS: retryWrites=true&w=majority
MONGO_URL: mongodb://farmer:[email protected]:27017/?retryWrites=true&w=majority
MONGODB_PARAMS: ?authSource=admin&authMechanism=SCRAM-SHA-1&retryWrites=true&w=majority

services:
mongodb:
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ safety: ## apply safety check in project.
.PHONY: format
format: ## format project code.
black --line-length=120 .
isort -rc -m 3 --tc .
isort -rc -m 3 --tc .

.PHONY: clean
clean: ## Clean Reset project containers and volumes with compose
docker-compose down -v --remove-orphans | true
docker-compose rm -f
1 change: 0 additions & 1 deletion greens/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Settings(BaseSettings):
down: str = os.getenv("DOWN", "down")
web_server: str = os.getenv("WEB_SERVER", "web_server")

db_url: str = os.getenv("MONGO_URL", "")
mongodb_database: str = os.getenv("MONGODB_DATABASE", "")
mongodb_collection: str = os.getenv("MONGODB_COLLECTION", "")
mongodb_test: str = os.getenv("MONGODB_TEST", "")
Expand Down
4 changes: 2 additions & 2 deletions greens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def lifespan(app: FastAPI):
app.state.mongo_client, app.state.mongo_db, app.state.mongo_collection = (
await init_mongo(
global_settings.mongodb_database,
global_settings.mongodb_url,
global_settings.mongodb_url.unicode_string(),
global_settings.mongodb_collection,
)
)
Expand All @@ -28,7 +28,7 @@ async def lifespan(app: FastAPI):
app.state.logger.info("Parking tractors in garage...")


app = FastAPI(lifespan=lifespan, title="Greens API", version="0.4.0")
app = FastAPI(lifespan=lifespan, title="Greens API", version="0.5.0")

app.include_router(v1, prefix="/api/v1")

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fastapi-mongodb"
version = "0.4.0"
version = "0.5.0"
description = ""
authors = ["Jakub Miazek <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def client() -> AsyncGenerator:
app.state.mongo_client, app.state.mongo_db, app.state.mongo_collection = (
await init_mongo(
global_settings.mongodb_test,
global_settings.db_url,
global_settings.mongodb_url.unicode_string(),
global_settings.mongodb_collection,
)
)
Expand Down
3 changes: 1 addition & 2 deletions tests/test_routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ async def test_health_check(client: AsyncClient):
assert response.json() == snapshot(
{
"version": "7.0.8",
"databases": ["admin", "config", "farmland", "local"],
"databases": ["admin", "config", "local"],
"collections": {
"admin": ["system.users", "system.version"],
"config": ["system.sessions"],
"farmland": ["greens"],
"local": ["startup_log"],
},
}
Expand Down

0 comments on commit 3ac5ef4

Please sign in to comment.