Root:
Swagger: http://localhost:8000/swagger/
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:
- Add yourself to the Azure Subscription iptch Sandbox (find instructions here).
- On your device, set the environment variable
G_COLLECTION_SECRET_KEY
to the Azure secret key (ask a friend). - Install and run Docker.
- Open this project in VS Code.
- Install the VS Code extension Dev Containers (
Cmd+Shift+X
orCtrl+Shift+X
). - Run Dev Containers: Rebuild Container (
Cmd+Shift+P
orCtrl+Shift+P
). - Run
az login
to log into Azure using your ipt address (to access blob storage). If it doesn't work, tryaz login --tenant iptzug.onmicrosoft.com
. - Run
python manage.py migrate
to prepare the local DB. - Run
python manage.py runserver
to start up the app. - Code away!
Required: Python >= 3.10, Azure CLI
Recommended: DB Viewer, e.g. DBeaver
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
All Calls need a JWT Token. Get one from the published app.
- In Chrome via Developer Tools
- Network
- Open the cards overview
- Copy the Authorization: part from Request Header of
cards
(notcards/
)
Example Call with JWT
curl --request GET 'http://127.0.0.1:8000/cards/' \
--header 'Authorization: Bearer <<access_token from above>>'
Deployment Pipeline via GitHub Actions
Definition in .github/workflows/main_g-collection.yml
Automatic Deployment when changes on main
Based on this tutorial
- Subscription: iptch Sandbox
- Ressource Group: rg-genius-collection
- App Service: g-collection
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
- 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']
- e.g.
If you just want to get a clean database (without deleting the tables), execute:
python manage.py flush
Otherwise:
- delete
db.sqlite3
python manage.py makemigrations
python manage.py migrate
- delete all tables & cascade (e.g. via DBeaver)
- execute commands in app-service > SSH
python manage.py migrate
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.
Use the repository g_collection_mgmt to fill data to your local SQLite Database:
- Create an empty database with correct schema:
python manage.py migrate
- Execute the script in g_collection_mgmt
- Connect to the SQLite DB and set yourself as admin in the
core_user
table.