Skip to content

Commit

Permalink
Merge branch 'paas-migration' of https://github.com/uktrade/trade-rem…
Browse files Browse the repository at this point in the history
…edies-public into paas-migration
  • Loading branch information
osimuka committed Nov 18, 2024
2 parents d7b9c93 + 0230a38 commit dbb63ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion trade_remedies_public/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("healthcheck/", core_views.PingdomHealthCheckView.as_view(), name="pingdom_healthcheck"),
path("health/", core_views.HealthCheckView.as_view(), name="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"),
Expand Down
27 changes: 11 additions & 16 deletions trade_remedies_public/core/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import os

import pytz
from django.conf import settings
Expand All @@ -18,8 +19,6 @@
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,
Expand All @@ -44,6 +43,7 @@
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__)

Expand All @@ -62,6 +62,15 @@ 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/")
Expand Down Expand Up @@ -1085,17 +1094,3 @@ 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

0 comments on commit dbb63ea

Please sign in to comment.