reach_commons 0.14.94__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 +53 -0
- {reach_commons-0.14.94.dist-info → reach_commons-0.14.96.dist-info}/METADATA +2 -1
- {reach_commons-0.14.94.dist-info → reach_commons-0.14.96.dist-info}/RECORD +4 -3
- {reach_commons-0.14.94.dist-info → reach_commons-0.14.96.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
|
|
3
|
+
from fastapi import Request, Response
|
|
4
|
+
|
|
5
|
+
from reach_commons.app_logging.logger import get_reach_logger
|
|
6
|
+
|
|
7
|
+
logger = get_reach_logger()
|
|
8
|
+
|
|
9
|
+
|
|
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
|
+
):
|
|
17
|
+
"""
|
|
18
|
+
Adds deprecation headers to the response and logs deprecation information.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
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.
|
|
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.
|
|
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()
|
|
30
|
+
|
|
31
|
+
path = request.url.path if request else "Unknown Path"
|
|
32
|
+
method = request.method if request else "Unknown Method"
|
|
33
|
+
|
|
34
|
+
deprecation_warning = f'299 "{method} {path}" is deprecated and will be removed on [{removal_date_str}]"'
|
|
35
|
+
|
|
36
|
+
response.headers["Deprecation-Warning"] = deprecation_warning
|
|
37
|
+
|
|
38
|
+
if replacement_url:
|
|
39
|
+
response.headers["Replacement-Endpoint"] = replacement_url
|
|
40
|
+
|
|
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
|
+
)
|
|
47
|
+
|
|
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,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: reach_commons
|
|
3
|
-
Version: 0.14.
|
|
3
|
+
Version: 0.14.96
|
|
4
4
|
Summary: Reach Commons is a versatile utility library designed to streamline and enhance development workflows within the Reach ecosystem.
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Wilson Moraes
|
|
@@ -15,6 +15,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.12
|
|
17
17
|
Requires-Dist: curlify (==2.2.1)
|
|
18
|
+
Requires-Dist: fastapi (==0.115.5)
|
|
18
19
|
Requires-Dist: pydantic (==2.9.2)
|
|
19
20
|
Requires-Dist: setuptools (==68.2.2)
|
|
20
21
|
Requires-Dist: twine (==4.0.2)
|
|
@@ -1,6 +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=MDGWr998TCWdGGf2L3r-NmnNhuKFDgKqRnkeAbgdkr4,2018
|
|
4
5
|
reach_commons/app_logging/logger.py,sha256=Iq2XTl1zLgHDmVsTMdlFadcYJOqQNhBcFSscacKs_Xs,2295
|
|
5
6
|
reach_commons/app_logging/logging_config.py,sha256=Y1JaZOoQBWgQjkOqYmeDRIm0p2eCOl3yTzgsgqyqm8I,1539
|
|
6
7
|
reach_commons/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -25,6 +26,6 @@ reach_commons/reach_base_model.py,sha256=oyAXoBwXLzsJ8GB1lxsJqiNf4QtfUJ_NI9MkiZ4
|
|
|
25
26
|
reach_commons/redis_manager.py,sha256=_4FOYPMapwRmWU-5SO1Bm0Cb__Ngkx2hrOPlrJETzX0,1896
|
|
26
27
|
reach_commons/utils.py,sha256=zny3JSj1Ljq1Bbt9RCLhqy0-sWrzb_cPoIccKpWk_Nk,8377
|
|
27
28
|
reach_commons/validations.py,sha256=jc78boM62S9Z0Ip_nV1z7I983gGpW2Y7vOCQtmia8OU,964
|
|
28
|
-
reach_commons-0.14.
|
|
29
|
-
reach_commons-0.14.
|
|
30
|
-
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
|