Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/release-notes/artifacts/pr0413.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version_schema: 2

changes:
- title: Switched haproxy-route-policy database backend to PostgreSQL
author: tphan025
type: minor
description: >
Changed the default database backend from SQLite to PostgreSQL with
environment-variable-based configuration for host, port, user, password,
and database name. Added psycopg2-binary as a project dependency.
urls:
pr:
- https://github.com/canonical/haproxy-operator/pull/413
related_doc:
related_issue:
visibility: public
highlight: false
14 changes: 11 additions & 3 deletions haproxy-route-policy/haproxy_route_policy/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pathlib import Path
import os
import json
import psycopg2.extensions

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -76,9 +77,16 @@

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
"ENGINE": "django.db.backends.postgresql",
"PASSWORD": os.getenv("DJANGO_DATABASE_PASSWORD", ""),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it refuste to start without a password? What are the consequences of having PASSWORD as an empty string?

"HOST": os.getenv("DJANGO_DATABASE_HOST", "localhost"),
"PORT": os.getenv("DJANGO_DATABASE_PORT", 5432),
"USER": os.getenv("DJANGO_DATABASE_USER", "postgres"),
"NAME": os.getenv("DJANGO_DATABASE_NAME", "postgres"),
"OPTIONS": {
"isolation_level": psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE,
},
},
}


Expand Down
8 changes: 8 additions & 0 deletions haproxy-route-policy/haproxy_route_policy/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@

from django.contrib import admin
from django.urls import include, path
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
TokenVerifyView,
)

from policy import urls as policy_urls

urlpatterns = [
path("admin/", admin.site.urls),
path("api/token/", TokenObtainPairView.as_view(), name="token_obtain_pair"),
path("api/token/refresh/", TokenRefreshView.as_view(), name="token_refresh"),
path("api/token/verify/", TokenVerifyView.as_view(), name="token_verify"),
path("", include(policy_urls)),
]
1 change: 1 addition & 0 deletions haproxy-route-policy/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies = [
"django>=6.0.3",
"djangorestframework>=3.16.1",
"djangorestframework-simplejwt>=5.5.1",
"psycopg2-binary>=2.9.11",
"validators>=0.35.0",
"whitenoise>=6.12.0",
]
Expand Down
43 changes: 43 additions & 0 deletions haproxy-route-policy/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading