From 386b14e341cf388f6085e51b85d38e3f121d8ce4 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Wed, 5 Jun 2024 14:37:24 +0530 Subject: [PATCH] Add endpoint to get version info --- config/settings/base.py | 14 ++++++++------ config/settings/deployment.py | 12 ++++++------ config/urls.py | 3 ++- config/views.py | 7 ++++++- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/config/settings/base.py b/config/settings/base.py index 03e764e8b3..c94fea3c6c 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -512,9 +512,9 @@ ) FILE_UPLOAD_BUCKET_EXTERNAL_ENDPOINT = env( "FILE_UPLOAD_BUCKET_EXTERNAL_ENDPOINT", - default=BUCKET_EXTERNAL_ENDPOINT - if BUCKET_ENDPOINT - else FILE_UPLOAD_BUCKET_ENDPOINT, + default=( + BUCKET_EXTERNAL_ENDPOINT if BUCKET_ENDPOINT else FILE_UPLOAD_BUCKET_ENDPOINT + ), ) ALLOWED_MIME_TYPES = env.list( @@ -566,9 +566,9 @@ ) FACILITY_S3_BUCKET_EXTERNAL_ENDPOINT = env( "FACILITY_S3_BUCKET_EXTERNAL_ENDPOINT", - default=BUCKET_EXTERNAL_ENDPOINT - if BUCKET_ENDPOINT - else FACILITY_S3_BUCKET_ENDPOINT, + default=( + BUCKET_EXTERNAL_ENDPOINT if BUCKET_ENDPOINT else FACILITY_S3_BUCKET_ENDPOINT + ), ) # for setting the shifting mode @@ -592,6 +592,8 @@ json.loads(base64.b64decode(env("JWKS_BASE64", default=generate_encoded_jwks()))) ) +APP_VERSION = env("APP_VERSION", default="unknown") + # ABDM ENABLE_ABDM = env.bool("ENABLE_ABDM", default=False) ABDM_CLIENT_ID = env("ABDM_CLIENT_ID", default="") diff --git a/config/settings/deployment.py b/config/settings/deployment.py index e0fec0187f..0c523acd18 100644 --- a/config/settings/deployment.py +++ b/config/settings/deployment.py @@ -7,13 +7,13 @@ from sentry_sdk.integrations.redis import RedisIntegration from .base import * # noqa -from .base import env +from .base import APP_VERSION, DATABASES, TEMPLATES, env # DATABASES # ------------------------------------------------------------------------------ -DATABASES["default"] = env.db("DATABASE_URL") # noqa F405 -DATABASES["default"]["ATOMIC_REQUESTS"] = True # noqa F405 -DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60) # noqa F405 +DATABASES["default"] = env.db("DATABASE_URL") +DATABASES["default"]["ATOMIC_REQUESTS"] = True +DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60) # SECURITY # ------------------------------------------------------------------------------ @@ -45,7 +45,7 @@ # TEMPLATES # ------------------------------------------------------------------------------ # https://docs.djangoproject.com/en/dev/ref/settings/#templates -TEMPLATES[-1]["OPTIONS"]["loaders"] = [ # type: ignore[index] # noqa F405 +TEMPLATES[-1]["OPTIONS"]["loaders"] = [ # type: ignore[index] ( "django.template.loaders.cached.Loader", [ @@ -98,7 +98,7 @@ if SENTRY_DSN := env("SENTRY_DSN", default=""): sentry_sdk.init( dsn=SENTRY_DSN, - release=env("APP_VERSION", default="unknown"), + release=APP_VERSION, environment=env("SENTRY_ENVIRONMENT", default="deployment-unknown"), traces_sample_rate=env.float("SENTRY_TRACES_SAMPLE_RATE", default=0), profiles_sample_rate=env.float("SENTRY_PROFILES_SAMPLE_RATE", default=0), diff --git a/config/urls.py b/config/urls.py index b59954a17d..4d112c686a 100644 --- a/config/urls.py +++ b/config/urls.py @@ -33,11 +33,12 @@ ) from .auth_views import AnnotatedTokenVerifyView, TokenObtainPairView, TokenRefreshView -from .views import home_view, ping +from .views import app_version, home_view, ping urlpatterns = [ path("", home_view, name="home"), path("ping/", ping, name="ping"), + path("app_version/", app_version, name="app_version"), # Django Admin, use {% url 'admin:index' %} path(settings.ADMIN_URL, admin.site.urls), # Rest API diff --git a/config/views.py b/config/views.py index 228ed1fe62..1cd9d3e310 100644 --- a/config/views.py +++ b/config/views.py @@ -1,10 +1,15 @@ +from django.conf import settings from django.http import JsonResponse from django.shortcuts import render +def app_version(_): + return JsonResponse({"version": settings.APP_VERSION}) + + def home_view(request): return render(request, "pages/home.html") -def ping(request): +def ping(_): return JsonResponse({"status": "OK"})