Skip to content

langrenn-sprint/user-service

Repository files navigation

user-service

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/users

Architecture

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

Environment variables

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

Requirement for development

Install uv, e.g.:

% curl -LsSf https://astral.sh/uv/install.sh | sh

Then install the dependencies:

% uv sync

Running the API locally

Start the server locally:

% uv run --env-file .env fastapi dev

Running the API in a wsgi-server (gunicorn)

% uv run --env-file .env uvicorn app:api --host 0.0.0.0 --port 8000 --workers 1 --log-config=logging.yaml

Running the wsgi-server in Docker

To 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:latest

The easier way would be with docker-compose:

docker compose up --build

Running tests

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

About

A simple user service with login and authorization endpoints

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors