A tiny HTTP service to read and write app-scoped configs stored in MongoDB.
- Read one config:
GET /{app_id}/get?config_id=motd - Read all configs for an app:
GET /{app_id}/get - Write a config (GET):
GET /{app_id}/set?config_id=motd&value=hello&auth=some_secret_key - Write a config (POST):
POST /{app_id}/setwith JSON body
The service enforces an API key for write operations via API_AUTH_TOKEN.
- Build the image:
docker build -t config-service:latest .- Run MongoDB (example using Docker):
docker run -d --name mongo -p 27017:27017 mongo:7- Run the service:
docker run --rm -p 8000:8000 \
-e MONGO_URI="mongodb://host.docker.internal:27017" \
-e API_AUTH_TOKEN="some_secret_key" \
--name config-service \
config-service:latest- If running Mongo in another container on the same Docker network, you can set
MONGO_URI=mongodb://mongo:27017and attach both containers to the same network.
GET /health->{"status":"ok"}
GET /{app_id}/get?config_id=motd- 200:
{"app_id":"test_app","config_id":"motd","value":"hello","updated_at":"...","created_at":"..." } - 404 if not found.
- 200:
GET /{app_id}/get- 200:
{"app_id":"test_app","count":2,"configs":{"motd":"hello","feature_flag":true}}
- 200:
Provide the token in one of:
-
Query param:
?auth=API_AUTH_TOKEN -
Header:
X-API-KEY: API_AUTH_TOKEN -
POST body field:
"auth": "API_AUTH_TOKEN" -
GET style (matches your example):
GET /{app_id}/set?config_id=motd&value=hello&auth=some_secret_key- Returns:
{ "success": true, "upserted": true, "config": { "app_id": "test_app", "config_id": "motd", "value": "hello", "updated_at": "...", "created_at": "..." } }
-
POST style (recommended):
POST /{app_id}/set- Body:
{ "config_id": "motd", "value": "hello", "auth": "some_secret_key" }
- The service will attempt to parse JSON-like strings for
value. Examples that will parse as JSON:{"a":1},[1,2,3],"hello",123,true,false,null
- If parsing fails, the value is stored as a string.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
export MONGO_URI="mongodb://localhost:27017"
export API_AUTH_TOKEN="some_secret_key"
uvicorn app:app --reloadOpen docs at: http://localhost:8000/docs
- Collection:
configs - Document:
{ "app_id": "test_app", "config_id": "motd", "value": "hello", "created_at": "2025-01-01T00:00:00Z", "updated_at": "2025-01-01T00:00:00Z" } - Unique index on
(app_id, config_id).
- Set
API_AUTH_TOKENto a strong secret. - Prefer POST with header
X-API-KEYto avoid logging secrets in URLs. - Restrict network access as appropriate for your environment.