/tpFastApi

Project given to students

Primary LanguagePython

tpFastApi

Deploy env

Create a .env file in the root of the project with the following content:

MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=fastapi
MYSQL_USER=fastapi
MYSQL_PASSWORD=fastapi
DB_URI=mysql+pymysql://fastapi:fastapi@mariadb:3306/fastapi

You can change the values or customize the values on docker compose file

To test the api use Insomnia and import the file Insomnia_API_TEST.yaml For the test you need to create a user with the username admin and password admin (use the bootstrap script to create the user)

Run the project

# start the project
docker compose up -d

# in some cases, the database is not ready when the api is starting
# you can restart the api container
docker compose restart api

# Create the first admin user or update user password and set admin role
docker compose exec api python -m app [username]

You can now access the api at http://localhost:8081 Docs are available at http://localhost:8081/docs

Work asked by the teacher

  • Database (SQLModel)
  • The app need to be scalable in container
  • Query and Reply with json and http protocol
  • No external lib other than FastAPI and SQLModel

Features 15 points

Authentication Endpoint 5 points

  • User can log in (basic auth, user login on every request)
  • User can register
  • User can log out (we use basic auth, so we can just forget the user)
  • Add role user and admin
  • Create bootstrap script to create first admin user

Syslog Endpoint 5 points

  • Add user authentication to the endpoint
  • Create endpoint to
    • Push log with severity
    • Query log with filter on severity
  • Logs have datetime, ip / dns, severity, service, message

Admin Endpoint 5 points

These endpoints are only accessible by admin users

  • Add admin authentication to the endpoint
  • can update logs
  • can delete logs

Bonus 5 points

  • 1 point: api test with postman
  • 1 point: web interface with framework of your choice (waaa la flemme)
  • 1 point: Store password hashed
  • 1 point: Documentation for how to set up the project
  • 1 point: Use real database (PostgresSQL, MySQL) and not SQLite