sharedkernel 2.6.2__tar.gz → 2.6.4__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.
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/PKG-INFO +5 -1
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/README.md +4 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/setup.py +1 -1
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/config.py +2 -1
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/ip_session_service.py +33 -19
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/logger/logger_service.py +3 -2
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel.egg-info/PKG-INFO +5 -1
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/setup.cfg +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/common.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/data_format_converter.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/database/__init__.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/database/audit_model.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/database/distributed_cache.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/database/mongo_generic_audit_repository.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/database/mongo_generic_repository.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/database/mongo_health_checker.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/database/pagination_response_dto.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/date_converter.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/diff_utils.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/enum/__init__.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/enum/error_code.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/enum/redis_mode_enum.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/enum/sort_order.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/exception/__init__.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/exception/exception.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/exception/exception_handlers.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/file_validation.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/jwt_service.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/logger/log_decorator.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/logger/log_dto.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/logger/log_enums.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/logger/log_info.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/logger/log_middlewares.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/multipart_upload.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/normalizer/__init__.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/normalizer/number_normalizer.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/normalizer/phone_number_normalizer.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/normalizer/string_normalizer.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/objects/__init__.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/objects/base_document.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/objects/json_string_model.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/objects/jwt_model.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/objects/result.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/objects/user_info.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/regex_masking.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/s3_uploader.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/string_extentions.py +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel.egg-info/SOURCES.txt +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel.egg-info/dependency_links.txt +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel.egg-info/requires.txt +0 -0
- {sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sharedkernel
|
|
3
|
-
Version: 2.6.
|
|
3
|
+
Version: 2.6.4
|
|
4
4
|
Summary: sharekernel is a shared package between all python projects
|
|
5
5
|
Author: Smilinno
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -31,6 +31,10 @@ Dynamic: summary
|
|
|
31
31
|
this is a shared kernel package
|
|
32
32
|
|
|
33
33
|
# Change Log
|
|
34
|
+
### Version 2.6.4
|
|
35
|
+
- Add Verbose to log
|
|
36
|
+
### Version 2.6.3
|
|
37
|
+
- fix bug ip-header-name
|
|
34
38
|
### Version 2.6.2
|
|
35
39
|
- Add Verbose
|
|
36
40
|
### Version 2.6.1
|
|
@@ -40,7 +40,7 @@ setup(
|
|
|
40
40
|
"redis",
|
|
41
41
|
],
|
|
42
42
|
# *strongly* suggested for sharing
|
|
43
|
-
version="2.6.
|
|
43
|
+
version="2.6.4",
|
|
44
44
|
description="sharekernel is a shared package between all python projects",
|
|
45
45
|
long_description=long_description,
|
|
46
46
|
long_description_content_type="text/markdown",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
IP_SESSION_VERBOSE = True if os.getenv("IP_SESSION_VERBOSE", "False").lower() == "true" else False
|
|
4
|
+
LOG_VERBOSE = True if os.getenv("LOG_VERBOSE", "False").lower() == "true" else False
|
|
4
5
|
|
|
5
6
|
# Log *******************************************************************************
|
|
6
7
|
LOG_ENABLE = True if os.getenv("LOG_ENABLE", "False").lower() == "true" else False
|
|
@@ -60,93 +60,107 @@ class IPSessionAuth:
|
|
|
60
60
|
except (ValueError, TypeError, json.JSONDecodeError):
|
|
61
61
|
raise BusinessException(ErrorCode.Internal_Server)
|
|
62
62
|
|
|
63
|
+
def _get_ip_from_request(self, request: dict, ip_header_name: str) -> str:
|
|
64
|
+
ip_address = request.headers.get(ip_header_name)
|
|
65
|
+
|
|
66
|
+
if not ip_address:
|
|
67
|
+
return None
|
|
68
|
+
|
|
69
|
+
if ip_header_name.lower() == "x-forwarded-for":
|
|
70
|
+
ip_address = ip_address.split(",")[0]
|
|
71
|
+
|
|
72
|
+
return ip_address
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
63
76
|
|
|
64
77
|
@unified_logger()
|
|
65
78
|
def ip_session_auth(self, request: Request):
|
|
66
79
|
|
|
67
80
|
if not config.IP_SESSION_AUTH_ENABLE:
|
|
68
|
-
if config.
|
|
81
|
+
if config.IP_SESSION_VERBOSE:
|
|
69
82
|
print("IP_SESSION_AUTH | OK | IP Session Auth is disabled")
|
|
70
83
|
return
|
|
71
84
|
|
|
72
|
-
if config.
|
|
73
|
-
print("
|
|
85
|
+
if config.IP_SESSION_VERBOSE:
|
|
86
|
+
print("="*70)
|
|
87
|
+
print("IP_SESSION_AUTH | INFO | Request Headers:\n", request.headers)
|
|
74
88
|
|
|
75
89
|
api_key = request.headers.get(config.APIKEY_HEADER_NAME)
|
|
76
90
|
|
|
77
91
|
if api_key:
|
|
78
|
-
if config.
|
|
92
|
+
if config.IP_SESSION_VERBOSE:
|
|
79
93
|
print("IP_SESSION_AUTH | OK | API Key is provided")
|
|
80
94
|
return
|
|
81
95
|
|
|
82
96
|
state = getattr(request.state, "decoded_token", None)
|
|
83
|
-
if config.
|
|
97
|
+
if config.IP_SESSION_VERBOSE:
|
|
84
98
|
print("IP_SESSION_AUTH | INFO | State: ", state)
|
|
85
99
|
|
|
86
100
|
if not state:
|
|
87
|
-
if config.
|
|
101
|
+
if config.IP_SESSION_VERBOSE:
|
|
88
102
|
print("IP_SESSION_AUTH | ERROR | No state found")
|
|
89
103
|
raise UnAuthorizedException()
|
|
90
104
|
|
|
91
105
|
nameid = state.get("nameid")
|
|
92
106
|
sessionid = state.get("sessionId")
|
|
93
|
-
if config.
|
|
107
|
+
if config.IP_SESSION_VERBOSE:
|
|
94
108
|
print("IP_SESSION_AUTH | INFO | Nameid: ", nameid)
|
|
95
109
|
print("IP_SESSION_AUTH | INFO | Sessionid: ", sessionid)
|
|
96
110
|
|
|
97
111
|
if not nameid or not sessionid:
|
|
98
|
-
if config.
|
|
112
|
+
if config.IP_SESSION_VERBOSE:
|
|
99
113
|
print("IP_SESSION_AUTH | ERROR | No nameid or sessionid found")
|
|
100
114
|
raise UnAuthorizedException()
|
|
101
115
|
|
|
102
|
-
request_ip =
|
|
116
|
+
request_ip = self._get_ip_from_request(request, config.IP_HEADER_NAME)
|
|
103
117
|
|
|
104
118
|
if not request_ip:
|
|
105
|
-
if config.
|
|
119
|
+
if config.IP_SESSION_VERBOSE:
|
|
106
120
|
print("IP_SESSION_AUTH | ERROR | No request ip found")
|
|
107
121
|
raise UnAuthorizedException()
|
|
108
122
|
|
|
109
123
|
request_ip = request_ip.strip()
|
|
110
|
-
if config.
|
|
124
|
+
if config.IP_SESSION_VERBOSE:
|
|
111
125
|
print("IP_SESSION_AUTH | INFO | Request ip: ", request_ip)
|
|
112
126
|
|
|
113
127
|
if self._is_ip_allowed(request_ip):
|
|
114
|
-
if config.
|
|
128
|
+
if config.IP_SESSION_VERBOSE:
|
|
115
129
|
print("IP_SESSION_AUTH | OK | IP is in whitelist")
|
|
116
130
|
return
|
|
117
131
|
|
|
118
132
|
redis_key = f"userId:{nameid}:session:{sessionid}"
|
|
119
133
|
user_data = self.redis.get(redis_key)
|
|
120
|
-
if config.
|
|
134
|
+
if config.IP_SESSION_VERBOSE:
|
|
121
135
|
print("IP_SESSION_AUTH | INFO | User data: ", user_data)
|
|
122
136
|
|
|
123
137
|
if not user_data:
|
|
124
|
-
if config.
|
|
138
|
+
if config.IP_SESSION_VERBOSE:
|
|
125
139
|
print("IP_SESSION_AUTH | ERROR | No user data found")
|
|
126
140
|
raise UnAuthorizedException()
|
|
127
141
|
|
|
128
142
|
try:
|
|
129
143
|
payload = json.loads(user_data.decode())
|
|
130
144
|
except (ValueError, UnicodeDecodeError, TypeError):
|
|
131
|
-
if config.
|
|
145
|
+
if config.IP_SESSION_VERBOSE:
|
|
132
146
|
print("IP_SESSION_AUTH | ERROR | Error decoding user data")
|
|
133
147
|
raise UnAuthorizedException()
|
|
134
148
|
|
|
135
149
|
stored_ip = payload.get("Ip")
|
|
136
|
-
if config.
|
|
150
|
+
if config.IP_SESSION_VERBOSE:
|
|
137
151
|
print("IP_SESSION_AUTH | INFO | Stored ip: ", stored_ip)
|
|
138
152
|
|
|
139
153
|
if not stored_ip:
|
|
140
|
-
if config.
|
|
154
|
+
if config.IP_SESSION_VERBOSE:
|
|
141
155
|
print("IP_SESSION_AUTH | ERROR | No stored ip found")
|
|
142
156
|
raise UnAuthorizedException()
|
|
143
157
|
|
|
144
158
|
if stored_ip.strip() != request_ip:
|
|
145
|
-
if config.
|
|
159
|
+
if config.IP_SESSION_VERBOSE:
|
|
146
160
|
print("IP_SESSION_AUTH | ERROR | Stored ip does not match request ip")
|
|
147
161
|
raise UnAuthorizedException()
|
|
148
162
|
|
|
149
163
|
lifetime_minutes = self._get_lifetime()
|
|
150
164
|
self.redis.expire(redis_key, lifetime_minutes * 60)
|
|
151
|
-
if config.
|
|
165
|
+
if config.IP_SESSION_VERBOSE:
|
|
152
166
|
print("IP_SESSION_AUTH | OK | IP session auth successful")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sharedkernel
|
|
3
|
-
Version: 2.6.
|
|
3
|
+
Version: 2.6.4
|
|
4
4
|
Summary: sharekernel is a shared package between all python projects
|
|
5
5
|
Author: Smilinno
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -31,6 +31,10 @@ Dynamic: summary
|
|
|
31
31
|
this is a shared kernel package
|
|
32
32
|
|
|
33
33
|
# Change Log
|
|
34
|
+
### Version 2.6.4
|
|
35
|
+
- Add Verbose to log
|
|
36
|
+
### Version 2.6.3
|
|
37
|
+
- fix bug ip-header-name
|
|
34
38
|
### Version 2.6.2
|
|
35
39
|
- Add Verbose
|
|
36
40
|
### Version 2.6.1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/database/mongo_generic_audit_repository.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sharedkernel-2.6.2 → sharedkernel-2.6.4}/sharedkernel/normalizer/phone_number_normalizer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|