reach_commons 0.14.95__tar.gz → 0.14.96__tar.gz

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.
Files changed (32) hide show
  1. {reach_commons-0.14.95 → reach_commons-0.14.96}/PKG-INFO +1 -1
  2. {reach_commons-0.14.95 → reach_commons-0.14.96}/pyproject.toml +1 -1
  3. reach_commons-0.14.96/reach_commons/app_logging/log_deprecated_endpoints.py +53 -0
  4. reach_commons-0.14.95/reach_commons/app_logging/log_deprecated_endpoints.py +0 -55
  5. {reach_commons-0.14.95 → reach_commons-0.14.96}/README.md +0 -0
  6. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/__init__.py +0 -0
  7. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/app_logging/__init__.py +0 -0
  8. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/app_logging/http_logger.py +0 -0
  9. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/app_logging/logger.py +0 -0
  10. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/app_logging/logging_config.py +0 -0
  11. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/clients/__init__.py +0 -0
  12. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/clients/event_processor.py +0 -0
  13. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/clients/hubspot.py +0 -0
  14. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/clients/outscraper.py +0 -0
  15. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/clients/reach_data_bridge.py +0 -0
  16. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/clients/reach_ops_api.py +0 -0
  17. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/mongo/__init__.py +0 -0
  18. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/mongo/customer_persistence.py +0 -0
  19. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/mongo/customer_persistence_async.py +0 -0
  20. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/mongo/validation/__init__.py +0 -0
  21. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/reach_aws/__init__.py +0 -0
  22. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/reach_aws/commons.py +0 -0
  23. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/reach_aws/dynamo_db.py +0 -0
  24. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/reach_aws/exceptions.py +0 -0
  25. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/reach_aws/firehose.py +0 -0
  26. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/reach_aws/kms.py +0 -0
  27. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/reach_aws/s3.py +0 -0
  28. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/reach_aws/sqs.py +0 -0
  29. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/reach_base_model.py +0 -0
  30. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/redis_manager.py +0 -0
  31. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/utils.py +0 -0
  32. {reach_commons-0.14.95 → reach_commons-0.14.96}/reach_commons/validations.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: reach_commons
3
- Version: 0.14.95
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
@@ -1,7 +1,7 @@
1
1
  # isort .; black .; poetry build; poetry publish
2
2
  [tool.poetry]
3
3
  name = "reach_commons"
4
- version = "0.14.95"
4
+ version = "0.14.96"
5
5
  description = "Reach Commons is a versatile utility library designed to streamline and enhance development workflows within the Reach ecosystem."
6
6
  authors = ["Wilson Moraes <wmoraes@getreach.ai>"]
7
7
  license = "MIT"
@@ -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,55 +0,0 @@
1
- from datetime import datetime, timedelta
2
- from functools import wraps
3
-
4
- from fastapi import Request
5
- from fastapi.responses import Response
6
-
7
- from reach_commons.app_logging.logger import get_reach_logger
8
-
9
- logger = get_reach_logger()
10
-
11
-
12
- def deprecated_warning(added_date: datetime, deprecation_period_days: int = 180):
13
- """
14
- Decorator to indicate that an endpoint is deprecated in FastAPI.
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.
19
-
20
- Args:
21
- added_date (datetime): The date when the deprecation was announced.
22
- deprecation_period_days (int): Number of days before the endpoint is removed (default: 180).
23
- """
24
-
25
- def decorator(func):
26
- @wraps(func)
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
38
-
39
- if current_date < removal_date:
40
- logger.warning(
41
- f"Deprecated endpoint accessed: {method} {path}. "
42
- f"Deprecation period ends on {removal_date_str}."
43
- )
44
-
45
- elif current_date >= removal_date:
46
- logger.error(
47
- f"Access to removed endpoint: {method} {path}. "
48
- f"Removal date was {removal_date_str}."
49
- )
50
-
51
- return await func(request, response, *args, **kwargs)
52
-
53
- return wrapper
54
-
55
- return decorator