reach_commons 0.14.95__py3-none-any.whl → 0.14.96__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reach_commons/app_logging/log_deprecated_endpoints.py +35 -37
- {reach_commons-0.14.95.dist-info → reach_commons-0.14.96.dist-info}/METADATA +1 -1
- {reach_commons-0.14.95.dist-info → reach_commons-0.14.96.dist-info}/RECORD +4 -4
- {reach_commons-0.14.95.dist-info → reach_commons-0.14.96.dist-info}/WHEEL +0 -0
|
@@ -1,55 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
from functools import wraps
|
|
1
|
+
import datetime
|
|
3
2
|
|
|
4
|
-
from fastapi import Request
|
|
5
|
-
from fastapi.responses import Response
|
|
3
|
+
from fastapi import Request, Response
|
|
6
4
|
|
|
7
5
|
from reach_commons.app_logging.logger import get_reach_logger
|
|
8
6
|
|
|
9
7
|
logger = get_reach_logger()
|
|
10
8
|
|
|
11
9
|
|
|
12
|
-
def
|
|
10
|
+
def add_deprecation_headers(
|
|
11
|
+
request: Request,
|
|
12
|
+
response: Response,
|
|
13
|
+
added_date: datetime.datetime,
|
|
14
|
+
deprecation_period_days: int = 180,
|
|
15
|
+
replacement_url: str = None,
|
|
16
|
+
):
|
|
13
17
|
"""
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- Adds a "Warning" header to the response during the deprecation period.
|
|
17
|
-
- Uses HTTP status 409 ("Gone") after the deprecation period ends.
|
|
18
|
-
- Uses HTTP status 301 ("Moved Permanently") if a replacement URL is provided.
|
|
18
|
+
Adds deprecation headers to the response and logs deprecation information.
|
|
19
19
|
|
|
20
20
|
Args:
|
|
21
|
-
|
|
21
|
+
request (Request): The HTTP request object.
|
|
22
|
+
response (Response): The HTTP response object.
|
|
23
|
+
added_date (datetime.datetime): The date when deprecation was announced.
|
|
22
24
|
deprecation_period_days (int): Number of days before the endpoint is removed (default: 180).
|
|
25
|
+
replacement_url (str, optional): URL of the replacement endpoint, if available.
|
|
23
26
|
"""
|
|
27
|
+
removal_date = added_date + datetime.timedelta(days=deprecation_period_days)
|
|
28
|
+
removal_date_str = removal_date.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
|
29
|
+
current_date = datetime.datetime.utcnow()
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
async def wrapper(request: Request, response: Response, *args, **kwargs):
|
|
28
|
-
removal_date = added_date + timedelta(days=deprecation_period_days)
|
|
29
|
-
removal_date_str = removal_date.strftime("%a, %d %b %Y %H:%M:%S GMT")
|
|
30
|
-
current_date = datetime.utcnow()
|
|
31
|
-
|
|
32
|
-
path = request.url.path if request else "Unknown Path"
|
|
33
|
-
method = request.method if request else "Unknown Method"
|
|
34
|
-
|
|
35
|
-
warning_message = f'299 "{method} {path}" is deprecated and will be removed on [{removal_date_str}]"'
|
|
36
|
-
|
|
37
|
-
response.headers["Deprecation-Warning"] = warning_message
|
|
31
|
+
path = request.url.path if request else "Unknown Path"
|
|
32
|
+
method = request.method if request else "Unknown Method"
|
|
38
33
|
|
|
39
|
-
|
|
40
|
-
logger.warning(
|
|
41
|
-
f"Deprecated endpoint accessed: {method} {path}. "
|
|
42
|
-
f"Deprecation period ends on {removal_date_str}."
|
|
43
|
-
)
|
|
34
|
+
deprecation_warning = f'299 "{method} {path}" is deprecated and will be removed on [{removal_date_str}]"'
|
|
44
35
|
|
|
45
|
-
|
|
46
|
-
logger.error(
|
|
47
|
-
f"Access to removed endpoint: {method} {path}. "
|
|
48
|
-
f"Removal date was {removal_date_str}."
|
|
49
|
-
)
|
|
36
|
+
response.headers["Deprecation-Warning"] = deprecation_warning
|
|
50
37
|
|
|
51
|
-
|
|
38
|
+
if replacement_url:
|
|
39
|
+
response.headers["Replacement-Endpoint"] = replacement_url
|
|
52
40
|
|
|
53
|
-
|
|
41
|
+
if current_date < removal_date:
|
|
42
|
+
logger.warning(
|
|
43
|
+
f"Deprecated endpoint accessed: {method} {path}. "
|
|
44
|
+
f"Deprecation period ends on {removal_date_str}."
|
|
45
|
+
+ (f" Replacement endpoint: {replacement_url}" if replacement_url else "")
|
|
46
|
+
)
|
|
54
47
|
|
|
55
|
-
|
|
48
|
+
elif current_date >= removal_date:
|
|
49
|
+
logger.error(
|
|
50
|
+
f"Access to removed endpoint: {method} {path}. "
|
|
51
|
+
f"Removal date was {removal_date_str}."
|
|
52
|
+
+ (f" Replacement endpoint: {replacement_url}" if replacement_url else "")
|
|
53
|
+
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
reach_commons/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
reach_commons/app_logging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
reach_commons/app_logging/http_logger.py,sha256=mljQCdmsmtD2HsC_gsFwZAxPlAiLPYVirVrCjXFxitY,2541
|
|
4
|
-
reach_commons/app_logging/log_deprecated_endpoints.py,sha256=
|
|
4
|
+
reach_commons/app_logging/log_deprecated_endpoints.py,sha256=MDGWr998TCWdGGf2L3r-NmnNhuKFDgKqRnkeAbgdkr4,2018
|
|
5
5
|
reach_commons/app_logging/logger.py,sha256=Iq2XTl1zLgHDmVsTMdlFadcYJOqQNhBcFSscacKs_Xs,2295
|
|
6
6
|
reach_commons/app_logging/logging_config.py,sha256=Y1JaZOoQBWgQjkOqYmeDRIm0p2eCOl3yTzgsgqyqm8I,1539
|
|
7
7
|
reach_commons/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -26,6 +26,6 @@ reach_commons/reach_base_model.py,sha256=oyAXoBwXLzsJ8GB1lxsJqiNf4QtfUJ_NI9MkiZ4
|
|
|
26
26
|
reach_commons/redis_manager.py,sha256=_4FOYPMapwRmWU-5SO1Bm0Cb__Ngkx2hrOPlrJETzX0,1896
|
|
27
27
|
reach_commons/utils.py,sha256=zny3JSj1Ljq1Bbt9RCLhqy0-sWrzb_cPoIccKpWk_Nk,8377
|
|
28
28
|
reach_commons/validations.py,sha256=jc78boM62S9Z0Ip_nV1z7I983gGpW2Y7vOCQtmia8OU,964
|
|
29
|
-
reach_commons-0.14.
|
|
30
|
-
reach_commons-0.14.
|
|
31
|
-
reach_commons-0.14.
|
|
29
|
+
reach_commons-0.14.96.dist-info/METADATA,sha256=ggrA_DRTLYpowCFQckm5achdzcxZZcieA5VY3ctA9f0,1861
|
|
30
|
+
reach_commons-0.14.96.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
31
|
+
reach_commons-0.14.96.dist-info/RECORD,,
|
|
File without changes
|