Skip to content

Commit 27f3196

Browse files
committed
Set brownouts for deprecated embed API v2
Ref #10677
1 parent dc8c965 commit 27f3196

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

readthedocs/embed/views.py

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""Views for the embed app."""
2-
2+
import datetime
33
import json
44
import re
55

6+
import pytz
67
import structlog
8+
from django.conf import settings
79
from django.template.defaultfilters import slugify
810
from docutils.nodes import make_id
911
from pyquery import PyQuery as PQ # noqa
@@ -66,8 +68,39 @@ def external(self):
6668
# Always return False because APIv2 does not support external domains
6769
return False
6870

71+
def _is_disabled_for_deprecation(self):
72+
if settings.RTD_ENFORCE_BROWNOUTS_FOR_DEPRECATIONS:
73+
return False
74+
75+
tzinfo = pytz.timezone("America/Los_Angeles")
76+
now = datetime.datetime.now(tz=tzinfo)
77+
# Dates as per https://about.readthedocs.com/blog/2024/11/embed-api-v2-deprecated/.
78+
# fmt: off
79+
is_disabled = (
80+
# 12 hours brownout.
81+
datetime.datetime(2024, 12, 9, 0, 0, 0, tzinfo=tzinfo) < now < datetime.datetime(2024, 12, 9, 12, 0, 0, tzinfo=tzinfo)
82+
# 24 hours brownout.
83+
or datetime.datetime(2025, 1, 13, 0, 0, 0, tzinfo=tzinfo) < now < datetime.datetime(2025, 1, 13, 0, 0, 0, tzinfo=tzinfo)
84+
# Permanent removal.
85+
or datetime.datetime(2025, 1, 20, 0, 0, 0, tzinfo=tzinfo) < now
86+
)
87+
# fmt: on
88+
return is_disabled
89+
6990
def get(self, request):
7091
"""Handle the get request."""
92+
93+
if self._is_disabled_for_deprecation():
94+
return Response(
95+
{
96+
"error": (
97+
"Embed API v2 has been deprecated and is no longer available, please use embed API v3 instead. "
98+
"Read our blog post for more information: https://about.readthedocs.com/blog/2024/11/embed-api-v2-deprecated/."
99+
)
100+
},
101+
status=status.HTTP_410_GONE,
102+
)
103+
71104
project = self._get_project()
72105
version = self._get_version()
73106

0 commit comments

Comments
 (0)