Back-end service to administer users and login
Example of usage:
% curl -H "Content-Type: application/json" \
-X POST \
--data '{"username":"admin","password":"passw123"}' \
http://localhost:8000/login
% export ACCESS="" #token from response
% curl -H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS" \
-X POST \
--data @tests/files/user.json \
http://localhost:8000/users
% curl -H "Authorization: Bearer $ACCESS" http://localhost:8000/usersLayers:
- views: routing functions, maps representations to/from model
- services: enforce validation, calls adapter-layer for storing/retrieving objects
- models: model-classes
- adapters: adapters to external services
To run the service locally, you need to supply a set of environment variables. A simple way to solve this is to supply a .env file in the root directory.
A minimal .env:
JWT_SECRET=secret
JWT_EXP_DELTA_SECONDS=3600
ADMIN_USERNAME=admin
ADMIN_PASSWORD=passw123
DB_USER=admin
DB_PASSWORD=admin
LOGGING_LEVEL=DEBUGInstall uv, e.g.:
% curl -LsSf https://astral.sh/uv/install.sh | shThen install the dependencies:
% uv syncStart the server locally:
% uv run --env-file .env fastapi dev% uv run --env-file .env uvicorn app:api --host 0.0.0.0 --port 8000 --workers 1 --log-config=logging.yamlTo build and run the api in a Docker container:
% docker build -t ghcr.io/langrenn-sprint/user-service:latest .
% docker run --env-file .env -p 8000:8000 -d ghcr.io/langrenn-sprint/user-service:latestThe easier way would be with docker-compose:
docker compose up --buildWe use pytest for contract testing.
To run linters, checkers and tests:
% uv run poe releaseTo run tests with logging, do:
% uv run pytest -m integration -- --log-cli-level=DEBUG