commit 60fa579eccc2c779862ad76556c87378dc20a788 Author: Kevin Heyer Date: Fri Sep 5 12:02:41 2025 +0200 First Commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5070191 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] +CMD ["gunicorn", "config.wsgi:application", "--bind", "0.0.0.0:8000"] diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/__pycache__/__init__.cpython-311.pyc b/api/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..9a9a706 Binary files /dev/null and b/api/__pycache__/__init__.cpython-311.pyc differ diff --git a/api/__pycache__/views.cpython-311.pyc b/api/__pycache__/views.cpython-311.pyc new file mode 100644 index 0000000..a236f54 Binary files /dev/null and b/api/__pycache__/views.cpython-311.pyc differ diff --git a/api/admin.py b/api/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/api/apps.py b/api/apps.py new file mode 100644 index 0000000..878e7d5 --- /dev/null +++ b/api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "api" diff --git a/api/migrations/__init__.py b/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/models.py b/api/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/api/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/api/tests.py b/api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/api/views.py b/api/views.py new file mode 100644 index 0000000..4665146 --- /dev/null +++ b/api/views.py @@ -0,0 +1,8 @@ +from rest_framework.decorators import api_view, permission_classes +from rest_framework.permissions import AllowAny +from rest_framework.response import Response + +@api_view(["GET"]) +@permission_classes([AllowAny]) # erstmal offen, später absichern +def ping(request): + return Response({"status": "ok"}) \ No newline at end of file diff --git a/config/__init__.py b/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/config/__pycache__/__init__.cpython-311.pyc b/config/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..2579686 Binary files /dev/null and b/config/__pycache__/__init__.cpython-311.pyc differ diff --git a/config/__pycache__/settings.cpython-311.pyc b/config/__pycache__/settings.cpython-311.pyc new file mode 100644 index 0000000..6a0e5f5 Binary files /dev/null and b/config/__pycache__/settings.cpython-311.pyc differ diff --git a/config/__pycache__/urls.cpython-311.pyc b/config/__pycache__/urls.cpython-311.pyc new file mode 100644 index 0000000..c5ad2ae Binary files /dev/null and b/config/__pycache__/urls.cpython-311.pyc differ diff --git a/config/__pycache__/wsgi.cpython-311.pyc b/config/__pycache__/wsgi.cpython-311.pyc new file mode 100644 index 0000000..01cbb7e Binary files /dev/null and b/config/__pycache__/wsgi.cpython-311.pyc differ diff --git a/config/asgi.py b/config/asgi.py new file mode 100644 index 0000000..87078af --- /dev/null +++ b/config/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for config project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") + +application = get_asgi_application() diff --git a/config/settings.py b/config/settings.py new file mode 100644 index 0000000..1c18edc --- /dev/null +++ b/config/settings.py @@ -0,0 +1,160 @@ +import environ +import os + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + +# Load Env-Vars +env = environ.Env() +environ.Env.read_env(os.path.join(BASE_DIR, ".env")) + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = env( + "SECRET_KEY", + default="django-insecure-lbfv*h@=mjj#xq^!k@-5f2oiq@u6ms9t6=3&nr+!#itih%jh^l" +) + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = env.bool("DEBUG", default=True) + +ALLOWED_HOSTS = ["localhost","127.0.0.1"] + + +# Application definition + +INSTALLED_APPS = [ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "rest_framework", +] + +MIDDLEWARE = [ + "django.middleware.security.SecurityMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.common.CommonMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware", + "django.middleware.clickjacking.XFrameOptionsMiddleware", +] + +ROOT_URLCONF = "config.urls" + +TEMPLATES = [ + { + "BACKEND": "django.template.backends.django.DjangoTemplates", + "DIRS": [], + "APP_DIRS": True, + "OPTIONS": { + "context_processors": [ + "django.template.context_processors.debug", + "django.template.context_processors.request", + "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", + ], + }, + }, +] + +WSGI_APPLICATION = "config.wsgi.application" + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": BASE_DIR / "db.sqlite3", + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.2/topics/i18n/ + +LANGUAGE_CODE = "en-us" + +TIME_ZONE = "UTC" + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.2/howto/static-files/ + +STATIC_URL = "static/" + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" + +REST_FRAMEWORK = { + "DEFAULT_PERMISSION_CLASSES": [ + "rest_framework.permissions.IsAuthenticated", + ], + "DEFAULT_AUTHENTICATION_CLASSES": [ + "rest_framework.authentication.SessionAuthentication", + "rest_framework.authentication.BasicAuthentication", + ], +} + +# OIDC Vars + +SSO_ENABLED = env.bool("SSO_ENABLED", default=False) + +if SSO_ENABLED: + INSTALLED_APPS += [ + "mozilla_django_oidc", + ] + + MIDDLEWARE += [ + "mozilla_django_oidc.middleware.SessionRefresh", + ] + + LOGIN_URL = "/oidc/authenticate/" + LOGIN_REDIRECT_URL = "/" + LOGOUT_REDIRECT_URL = "/" + + + OIDC_RP_CLIENT_ID = env("OIDC_RP_CLIENT_ID", default="django-app") + OIDC_RP_CLIENT_SECRET = env("OIDC_RP_CLIENT_SECRET", default="changeme") + OIDC_OP_DISCOVERY_ENDPOINT = env( + "OIDC_OP_DISCOVERY_ENDPOINT", + default="http://localhost:9091/.well-known/openid-configuration", + ) + + OIDC_RP_SIGN_ALGO = "RS256" + OIDC_STORE_ID_TOKEN = True + OIDC_STORE_ACCESS_TOKEN = True \ No newline at end of file diff --git a/config/urls.py b/config/urls.py new file mode 100644 index 0000000..52f3b99 --- /dev/null +++ b/config/urls.py @@ -0,0 +1,14 @@ +from django.conf import settings +from django.contrib import admin +from django.urls import path, include +from api.views import ping + +urlpatterns = [ + path("admin/", admin.site.urls), + path("api/ping/", ping), +] + +if settings.SSO_ENABLED: + urlpatterns += [ + path("oidc/", include("mozilla_django_oidc.urls")), + ] \ No newline at end of file diff --git a/config/wsgi.py b/config/wsgi.py new file mode 100644 index 0000000..a9afbb3 --- /dev/null +++ b/config/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for config project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") + +application = get_wsgi_application() diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..8d26c77 Binary files /dev/null and b/db.sqlite3 differ diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..faccadb --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +echo "Running migrations..." +python manage.py migrate --noinput + +echo "Creating superuser if it doesn't exist..." +python manage.py createsuperuser \ + --noinput \ + --username "${DJANGO_SUPERUSER_USERNAME}" \ + --email "${DJANGO_SUPERUSER_EMAIL}" || true + +echo "Starting server..." +exec "$@" \ No newline at end of file diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..d28672e --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c15c8f2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,16 @@ +asgiref==3.9.1 +certifi==2025.8.3 +cffi==1.17.1 +charset-normalizer==3.4.3 +cryptography==45.0.7 +Django==4.2.24 +django-environ==0.12.0 +django-filter==25.1 +djangorestframework==3.16.1 +idna==3.10 +josepy==2.1.0 +mozilla-django-oidc==4.0.1 +pycparser==2.22 +requests==2.32.5 +sqlparse==0.5.3 +urllib3==2.5.0