Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set brownouts for deprecated embed API v2
Browse files Browse the repository at this point in the history
Ref #10677
stsewd committed Nov 21, 2024

Verified

This commit was signed with the committer’s verified signature.
stsewd Santos Gallegos
1 parent dc8c965 commit 27f3196
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
@@ -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 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, 13, 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()

0 comments on commit 27f3196

Please sign in to comment.