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:8080/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:8080/users
% curl -H "Authorization: Bearer $ACCESS" http://localhost:8080/users
Layers:
- 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=DEBUG
Install uv, e.g.:
% curl -LsSf https://astral.sh/uv/install.sh | sh
Then install the dependencies:
% uv sync
Start the server locally:
% uv run adev runserver -p 8080 user_service
% uv run gunicorn user_service:create_app --bind localhost:8080 --worker-class aiohttp.GunicornWebWorker
To build and run the api in a Docker container:
% docker build -t langrenn-sprint/user-service:latest .
% docker run --env-file .env -p 8080:8080 -d langrenn-sprint/user-service:latest
The easier way would be with docker-compose:
docker compose up --build
We use pytest for contract testing.
To run linters, checkers and tests:
% uv run poe release
To run tests with logging, do:
% uv run pytest -m integration -- --log-cli-level=DEBUG