Skip to content

A simple user service with login and authorization endpoints

License

Notifications You must be signed in to change notification settings

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

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 adev runserver -p 8080 user_service

Running the API in a wsgi-server (gunicorn)

% uv run gunicorn user_service:create_app --bind localhost:8080 --worker-class aiohttp.GunicornWebWorker

Running the wsgi-server in Docker

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

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