Skip to content

iptch/g_collection_be

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Genius Collection 2.0 - Backend

Endpoints

Root:

Swagger: http://localhost:8000/swagger/

Overview

This backend works with Django and Django Rest Framework. Data is stored in SQLite (local) or Postgres (remote) Database. The application is hosted on Azure. The authentication works via Azure OAuth which federates the requests to Google Cloud.

First time working with some of the tools mentioned above? Have a look at these links:

Running the app in a Dev Container

  1. Add yourself to the Azure Subscription iptch Sandbox (find instructions here).
  2. On your device, set the environment variable G_COLLECTION_SECRET_KEY to the Azure secret key (ask a friend).
  3. Install and run Docker.
  4. Open this project in VS Code.
  5. Install the VS Code extension Dev Containers (Cmd+Shift+X or Ctrl+Shift+X).
  6. Run Dev Containers: Rebuild Container (Cmd+Shift+P or Ctrl+Shift+P).
  7. Run az login to log into Azure using your ipt address (to access blob storage). If it doesn't work, try az login --tenant iptzug.onmicrosoft.com.
  8. Run python manage.py migrate to prepare the local DB.
  9. Run python manage.py runserver to start up the app.
  10. Code away!

Local Setup

Prerequisites

Required: Python >= 3.10, Azure CLI

Recommended: DB Viewer, e.g. DBeaver

Run configuration

Either use the devcontainer in .devcontainer with VS Code (described above) or execute the following steps:

  • Install requirements pip install -r requirements.txt
  • Login with Azure CLI using your ipt address (to access blob storage) az login
  • Run local server python manage.py runserver

Authentication

All Calls need a JWT Token. Get one from the published app.

  1. In Chrome via Developer Tools
  2. Network
  3. Open the cards overview
  4. Copy the Authorization: part from Request Header of cards (not cards/)

Example Call with JWT

curl --request GET 'http://127.0.0.1:8000/cards/' \
--header 'Authorization: Bearer <<access_token from above>>'

Deployment

Deployment Pipeline via GitHub Actions Definition in .github/workflows/main_g-collection.yml Automatic Deployment when changes on main Based on this tutorial

Azure Setup

  • Subscription: iptch Sandbox
  • Ressource Group: rg-genius-collection
  • App Service: g-collection

App Registrations

2 App Registrations, 1 for FE, 1 for BE App Registrations

  • Backend Registration needed for CORS from FE to BE
    • In "App Registrations" > "g-collection-be" > "Expose an API" > Add a scope
    • Add this scope to FE Application in "app.module.ts" > "protectedRessourceMap"
  • Frontend Registration is needed to initiate OAUTH Flow and obtaining the JWT Token

Remote Debugging

  • In Azure Portal, navigate to the "App Service" > "SSH"
  • execute python manage.py shell
  • This opens a Python Shell in the configured Djange setup where you can execute commands
    • e.g. os.environ['DJANGO_SETTINGS_MODULE']

DB configuration

resetting to empty state

If you just want to get a clean database (without deleting the tables), execute: python manage.py flush

Otherwise:

local

  • delete db.sqlite3
  • python manage.py makemigrations
  • python manage.py migrate

remote

  • delete all tables & cascade (e.g. via DBeaver)
  • execute commands in app-service > SSH
  • python manage.py migrate

Postgres Connection

Ensure the Firewall allows connection from your IP:

Resource Group: rg-genius-collection > Database: g-collection-postgres > Settings > Networking

Then connect via a DB Viewer:

  • Host: g-collection-postgres.postgres.database.azure.com
  • Port: 5432
  • Database: g-collection-db
  • Username: gcollectionadmin
  • Password: ask friend :-)

FYI: The App Service connects via "Service Connector" to the Postgres Instance.

Filling local DB with data

Use the repository g_collection_mgmt to fill data to your local SQLite Database:

  1. Create an empty database with correct schema: python manage.py migrate
  2. Execute the script in g_collection_mgmt
  3. Connect to the SQLite DB and set yourself as admin in the core_user table.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published