Skip to content

Commit

Permalink
Set brownouts for deprecated embed API v2 (#11786)
Browse files Browse the repository at this point in the history
Ref #10677
  • Loading branch information
stsewd authored Nov 25, 2024
1 parent 5a97954 commit 6711656
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion readthedocs/embed/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Views for the embed app."""

import datetime
import json
import re

import pytz
import structlog
from django.conf import settings
from django.template.defaultfilters import slugify
from docutils.nodes import make_id
from pyquery import PyQuery as PQ # noqa
Expand Down Expand Up @@ -66,8 +68,39 @@ def external(self):
# Always return False because APIv2 does not support external domains
return False

def _is_disabled_for_deprecation(self):
if not settings.RTD_ENFORCE_BROWNOUTS_FOR_DEPRECATIONS:
return False

tzinfo = pytz.timezone("America/Los_Angeles")
now = datetime.datetime.now(tz=tzinfo)
# Dates as per https://about.readthedocs.com/blog/2024/11/embed-api-v2-deprecated/.
# fmt: off
is_disabled = (
# 12 hours brownout.
datetime.datetime(2024, 12, 9, 0, 0, 0, tzinfo=tzinfo) < now < datetime.datetime(2024, 12, 9, 12, 0, 0, tzinfo=tzinfo)
# 24 hours brownout.
or datetime.datetime(2025, 1, 13, 0, 0, 0, tzinfo=tzinfo) < now < datetime.datetime(2025, 1, 14, 0, 0, 0, tzinfo=tzinfo)
# Permanent removal.
or datetime.datetime(2025, 1, 20, 0, 0, 0, tzinfo=tzinfo) < now
)
# fmt: on
return is_disabled

def get(self, request):
"""Handle the get request."""

if self._is_disabled_for_deprecation():
return Response(
{
"error": (
"Embed API v2 has been deprecated and is no longer available, please use embed API v3 instead. "
"Read our blog post for more information: https://about.readthedocs.com/blog/2024/11/embed-api-v2-deprecated/."
)
},
status=status.HTTP_410_GONE,
)

project = self._get_project()
version = self._get_version()

Expand Down

0 comments on commit 6711656

Please sign in to comment.