From df3c38ce2e6b9e1420542fc235a01be0d32d1d6d Mon Sep 17 00:00:00 2001 From: connorhaugh <49422820+connorhaugh@users.noreply.github.com> Date: Wed, 10 Apr 2024 10:28:30 -0400 Subject: [PATCH] feat: add heartbeat to authoring api (#34449) * feat: add heartbeat to authoring api --- .../contentstore/rest_api/v0/urls.py | 4 ++ .../rest_api/v0/views/__init__.py | 1 + .../rest_api/v0/views/api_heartbeat.py | 48 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 cms/djangoapps/contentstore/rest_api/v0/views/api_heartbeat.py diff --git a/cms/djangoapps/contentstore/rest_api/v0/urls.py b/cms/djangoapps/contentstore/rest_api/v0/urls.py index 2a7e400099..0232854710 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/urls.py +++ b/cms/djangoapps/contentstore/rest_api/v0/urls.py @@ -13,6 +13,7 @@ from .views import ( TranscriptView, YoutubeTranscriptCheckView, YoutubeTranscriptUploadView, + APIHeartBeatView ) from .views import assets from .views import authoring_videos @@ -45,6 +46,9 @@ urlpatterns = [ ), # Authoring API + re_path( + r'^heartbeat$', APIHeartBeatView.as_view(), name='heartbeat' + ), re_path( fr'^file_assets/{settings.COURSE_ID_PATTERN}$', assets.AssetsCreateRetrieveView.as_view(), name='cms_api_create_retrieve_assets' diff --git a/cms/djangoapps/contentstore/rest_api/v0/views/__init__.py b/cms/djangoapps/contentstore/rest_api/v0/views/__init__.py index b6403d53e3..85b7b7d93b 100644 --- a/cms/djangoapps/contentstore/rest_api/v0/views/__init__.py +++ b/cms/djangoapps/contentstore/rest_api/v0/views/__init__.py @@ -4,3 +4,4 @@ Views for v0 contentstore API. from .advanced_settings import AdvancedCourseSettingsView from .tabs import CourseTabSettingsView, CourseTabListView, CourseTabReorderView from .transcripts import TranscriptView, YoutubeTranscriptCheckView, YoutubeTranscriptUploadView +from .api_heartbeat import APIHeartBeatView diff --git a/cms/djangoapps/contentstore/rest_api/v0/views/api_heartbeat.py b/cms/djangoapps/contentstore/rest_api/v0/views/api_heartbeat.py new file mode 100644 index 0000000000..f8b539557e --- /dev/null +++ b/cms/djangoapps/contentstore/rest_api/v0/views/api_heartbeat.py @@ -0,0 +1,48 @@ +""" View For Getting the Status of The Authoring API """ +import edx_api_doc_tools as apidocs +from rest_framework.views import APIView +from rest_framework.request import Request +from rest_framework.response import Response +from rest_framework import status +from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes +import cms.djangoapps.contentstore.toggles as toggles + + +class APIHeartBeatView(DeveloperErrorViewMixin, APIView): + """ + View for getting the Authoring API's status + """ + + @apidocs.schema( + parameters=[], + responses={ + 200: "The API is online", + 401: "The requester is not authenticated.", + 403: "The API is not availible", + }, + ) + @view_auth_classes(is_authenticated=True) + def get(self, request: Request): + """ + Get an object containing the Authoring API's status + + **Example Request** + + GET /api/contentstore/v0/heartbeat + + **Response Values** + + If the request is successful, an HTTP 200 "OK" response is returned. + The HTTP 200 response contains a single dict with the "authoring_api_enabled" value "True". + + **Example Response** + + ```json + { + "authoring_api_enabled": "True" + } + ``` + """ + if toggles.use_studio_content_api(): + return Response({'status': 'heartbeat successful'}, status=status.HTTP_200_OK) + return Response(status=status.HTTP_403_FORBIDDEN)