|
1 | 1 | """Views for the embed app."""
|
2 |
| - |
| 2 | +import datetime |
3 | 3 | import json
|
4 | 4 | import re
|
5 | 5 |
|
| 6 | +import pytz |
6 | 7 | import structlog
|
| 8 | +from django.conf import settings |
7 | 9 | from django.template.defaultfilters import slugify
|
8 | 10 | from docutils.nodes import make_id
|
9 | 11 | from pyquery import PyQuery as PQ # noqa
|
@@ -66,8 +68,39 @@ def external(self):
|
66 | 68 | # Always return False because APIv2 does not support external domains
|
67 | 69 | return False
|
68 | 70 |
|
| 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 | + |
69 | 90 | def get(self, request):
|
70 | 91 | """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 | + |
71 | 104 | project = self._get_project()
|
72 | 105 | version = self._get_version()
|
73 | 106 |
|
|
0 commit comments