feat: add heartbeat to authoring api (#34449)

* feat: add heartbeat to authoring api
This commit is contained in:
connorhaugh
2024-04-10 10:28:30 -04:00
committed by GitHub
parent eb26333ca6
commit df3c38ce2e
3 changed files with 53 additions and 0 deletions

View File

@@ -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'

View File

@@ -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

View File

@@ -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)