diff --git a/trade_remedies_public/config/urls.py b/trade_remedies_public/config/urls.py index b3c5093c..df816e15 100644 --- a/trade_remedies_public/config/urls.py +++ b/trade_remedies_public/config/urls.py @@ -32,7 +32,7 @@ # todo - config/urls.py should not contain anything, put these URLs in their relevant apps urlpatterns = [ path("", login_views.LandingView.as_view(), name="landing"), - path("health/", core_views.HealthCheckView.as_view(), name="healthcheck"), + path("healthcheck/", core_views.PingdomHealthCheckView.as_view(), name="pingdom_healthcheck"), path("holding_page/", core_views.HoldingView.as_view(), name="holdingpage"), # path('start/', core_views.StartView.as_view(), name='start'), path("twofactor/", login_views.TwoFactorView.as_view(), name="two_factor"), diff --git a/trade_remedies_public/core/views.py b/trade_remedies_public/core/views.py index 97237f91..d528dda1 100644 --- a/trade_remedies_public/core/views.py +++ b/trade_remedies_public/core/views.py @@ -1,6 +1,5 @@ import json import logging -import os import pytz from django.conf import settings @@ -19,6 +18,8 @@ from trade_remedies_client.exceptions import APIException from trade_remedies_client.mixins import TradeRemediesAPIClientMixin from v2_api_client.client import TRSAPIClient +from v2_api_client.mixins import APIClientMixin + from cases.constants import ( CASE_TYPE_REPAYMENT, @@ -43,7 +44,6 @@ from core.validators import user_create_validators from registration.views import BaseRegisterView -health_check_token = os.environ.get("HEALTH_CHECK_TOKEN") logger = logging.getLogger(__name__) @@ -62,15 +62,6 @@ def check_required_keys(self, request): return errors -class HealthCheckView(View, TradeRemediesAPIClientMixin): - def get(self, request): - response = self.trusted_client.health_check() - if all([response[k] == "OK" for k in response]): - return HttpResponse("OK") - else: - return HttpResponse(f"ERROR: {response}") - - class HomeView(TemplateView): def get(self, request, *args, **kwargs): return redirect("/dashboard/") @@ -1094,3 +1085,17 @@ def get(self, request, *args, **kwargs): query = request.GET.get("term") results = self.trusted_client.companies_house_search(query) return HttpResponse(json.dumps(results), content_type="application/json") + + +class PingdomHealthCheckView(View, APIClientMixin): + def get(self, request): + response = self.client.healthcheck() + + if "OK" in response: + response = HttpResponse(response, content_type="text/xml", status=200) + else: + response = HttpResponse(response, content_type="text/xml", status=503) + + response["Cache-Control"] = "no-cache, no-store, must-revalidate" + + return response