python-sdk-remote 0.0.145__py3-none-any.whl → 0.0.146__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.
- python_sdk_remote/constants.py +1 -0
- python_sdk_remote/constants_src_mini_logger.py +14 -0
- python_sdk_remote/http_response.py +2 -2
- python_sdk_remote/mini_logger.py +70 -56
- python_sdk_remote/utilities.py +25 -14
- {python_sdk_remote-0.0.145.dist-info → python_sdk_remote-0.0.146.dist-info}/METADATA +1 -1
- python_sdk_remote-0.0.146.dist-info/RECORD +16 -0
- python_sdk_remote-0.0.145.dist-info/RECORD +0 -15
- {python_sdk_remote-0.0.145.dist-info → python_sdk_remote-0.0.146.dist-info}/WHEEL +0 -0
- {python_sdk_remote-0.0.145.dist-info → python_sdk_remote-0.0.146.dist-info}/top_level.txt +0 -0
python_sdk_remote/constants.py
CHANGED
|
@@ -11,7 +11,7 @@ AUTHORIZATION_KEY = 'authorization'
|
|
|
11
11
|
AUTHORIZATION_PREFIX = 'Bearer '
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
# TODO Align those methods with typescript-sdk https://github.com/circles-zone/typescript-sdk-remote-typescript-package/blob/dev/typescript-sdk/src/utils/index.ts
|
|
14
|
+
# TODO Align those methods with typescript-sdk https://github.com/circles-zone/typescript-sdk-remote-typescript-package/blob/dev/typescript-sdk/src/utils/index.ts # noqa: E501
|
|
15
15
|
# TODO Shall we create also createInternalServerErrorHttpResponse(), createOkHttpResponse() like we have in TypeScript?
|
|
16
16
|
|
|
17
17
|
# TODO: add handler wrapper?
|
|
@@ -104,7 +104,7 @@ def get_user_jwt_from_event(event: dict) -> str:
|
|
|
104
104
|
def create_return_http_headers() -> dict:
|
|
105
105
|
logger.start()
|
|
106
106
|
# Adding "Access-Control-Allow-Origin" : "*" to take care of CORS from localhost
|
|
107
|
-
# TODO Do we need to add those? In which cases? try adding crossDomain: true, to the request, 'Access-Control-Allow-Credentials': true to header
|
|
107
|
+
# TODO Do we need to add those? In which cases? try adding crossDomain: true, to the request, 'Access-Control-Allow-Credentials': true to header # noqa: E501
|
|
108
108
|
return_http_headers = {
|
|
109
109
|
"Content-Type": "application/json",
|
|
110
110
|
"Access-Control-Allow-Origin": "*",
|
python_sdk_remote/mini_logger.py
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import os
|
|
3
3
|
import sys
|
|
4
|
-
|
|
4
|
+
from enum import Enum
|
|
5
|
+
import inspect
|
|
6
|
+
from src.constants_src_mini_logger import LogMessageSeverity, StartEndEnum
|
|
7
|
+
|
|
8
|
+
# TODO LOGGER_MINIMAL_SEVERITY_DEFAULT
|
|
5
9
|
LOGGER_MINIMUM_SEVERITY = os.getenv("LOGGER_MINIMUM_SEVERITY", "INFO").upper()
|
|
6
10
|
# logging expects NOTSET/DEBUG/INFO/WARNING/ERROR/FATAL/CRITICAL
|
|
7
11
|
if LOGGER_MINIMUM_SEVERITY.isdigit():
|
|
12
|
+
# TODO logger_minimal_severity_default_value
|
|
8
13
|
logger_minimum_severity = int(LOGGER_MINIMUM_SEVERITY)
|
|
9
|
-
#
|
|
10
|
-
if logger_minimum_severity <
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
LOGGER_MINIMUM_SEVERITY =
|
|
14
|
-
elif logger_minimum_severity <
|
|
15
|
-
LOGGER_MINIMUM_SEVERITY =
|
|
16
|
-
elif logger_minimum_severity <
|
|
17
|
-
LOGGER_MINIMUM_SEVERITY =
|
|
14
|
+
# TODO Change Magic Numbers and use the values from Logger.MessageSeverity
|
|
15
|
+
if logger_minimum_severity < LogMessageSeverity.Start.value:
|
|
16
|
+
# TODO LOGGER_MINIMAL_SEVERITY_DEFAULT_NAME =
|
|
17
|
+
# TODO Change "DEBUG", "INFO", "WARNING" ... into enum values from Logger.LogMessageSeverity
|
|
18
|
+
LOGGER_MINIMUM_SEVERITY = LogMessageSeverity.Debug
|
|
19
|
+
elif logger_minimum_severity < LogMessageSeverity.Warning.value:
|
|
20
|
+
LOGGER_MINIMUM_SEVERITY = LogMessageSeverity.Info
|
|
21
|
+
elif logger_minimum_severity < LogMessageSeverity.Error.value:
|
|
22
|
+
LOGGER_MINIMUM_SEVERITY = LogMessageSeverity.Warning
|
|
23
|
+
elif logger_minimum_severity < LogMessageSeverity.Critical.value:
|
|
24
|
+
LOGGER_MINIMUM_SEVERITY = LogMessageSeverity.Error
|
|
18
25
|
else:
|
|
19
|
-
LOGGER_MINIMUM_SEVERITY =
|
|
26
|
+
LOGGER_MINIMUM_SEVERITY = LogMessageSeverity.Critical
|
|
20
27
|
|
|
21
28
|
logging.basicConfig(level=LOGGER_MINIMUM_SEVERITY, stream=sys.stdout,
|
|
22
29
|
format="%(asctime)s - %(message)s")
|
|
@@ -27,98 +34,105 @@ class MiniLogger:
|
|
|
27
34
|
# TODO Can we so one generic function call by all
|
|
28
35
|
|
|
29
36
|
@staticmethod
|
|
30
|
-
def
|
|
37
|
+
def _log(level: LogMessageSeverity, start_or_end: StartEndEnum = None, log_message: str = None, **kwargs):
|
|
31
38
|
"""
|
|
32
|
-
|
|
39
|
+
Private method to unify all log methods
|
|
33
40
|
|
|
34
41
|
Parameters:
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
level (MessageSeverity): log level
|
|
43
|
+
log_message (str): The message to be printed.
|
|
37
44
|
"""
|
|
45
|
+
object = kwargs.get("object")
|
|
46
|
+
method_name = level.name.lower()
|
|
47
|
+
method = getattr(logger, method_name)
|
|
48
|
+
if not start_or_end:
|
|
49
|
+
action_name = level.name
|
|
50
|
+
else:
|
|
51
|
+
action_name = start_or_end.name
|
|
52
|
+
stk = inspect.stack()[2]
|
|
53
|
+
function = stk.function
|
|
54
|
+
line = stk.lineno
|
|
38
55
|
if object is None:
|
|
39
|
-
|
|
56
|
+
method(f"Function: {function}, Line: {line}; {action_name} - {log_message}")
|
|
40
57
|
else:
|
|
41
|
-
|
|
58
|
+
method(f"Function: {function}, Line: {line}; {action_name} - {log_message} - {object}")
|
|
59
|
+
|
|
42
60
|
|
|
43
61
|
@staticmethod
|
|
44
|
-
|
|
62
|
+
# TODO Add a new file called align_logger_and_minilogger_test.py, which makes sure the signature of all methods of MiniLogger and Logger are the same and we can change from MiniLogger to Logger and vice versa by changing only one line in our code. If we should change the signatures, we should make them backward compatible.
|
|
63
|
+
def start(log_message: str = None, **kwargs):
|
|
45
64
|
"""
|
|
46
65
|
Print a log message with the current time.
|
|
47
66
|
|
|
48
67
|
Parameters:
|
|
49
|
-
|
|
68
|
+
log_message (str): The message to be printed.
|
|
50
69
|
"""
|
|
51
|
-
|
|
52
|
-
logger.debug(f"END - {message}")
|
|
53
|
-
else:
|
|
54
|
-
logger.debug(f"END - {message} - {object}")
|
|
70
|
+
MiniLogger._log(LogMessageSeverity.Debug, StartEndEnum.Start, log_message, **kwargs)
|
|
55
71
|
|
|
56
72
|
@staticmethod
|
|
57
|
-
def
|
|
73
|
+
def end(log_message: str = None, **kwargs):
|
|
58
74
|
"""
|
|
59
75
|
Print a log message with the current time.
|
|
60
76
|
|
|
61
77
|
Parameters:
|
|
62
|
-
|
|
63
|
-
object (dict): The object to be printed.
|
|
78
|
+
log_message (str): The message to be printed.
|
|
64
79
|
"""
|
|
65
|
-
|
|
66
|
-
logger.debug(f"DEBUG - {message}")
|
|
67
|
-
else:
|
|
68
|
-
logger.debug(f"DEBUG {message} - {object}")
|
|
80
|
+
MiniLogger._log(LogMessageSeverity.Debug, StartEndEnum.End, log_message, **kwargs)
|
|
69
81
|
|
|
82
|
+
# TODO convert all those methods (debug, info, warning, error) into one unified private method
|
|
83
|
+
# TODO Add to the unified private method print of the name of method, version
|
|
84
|
+
# and line number of the calling function/method to the mini_logger methods
|
|
70
85
|
@staticmethod
|
|
71
|
-
def
|
|
86
|
+
def debug(log_message: str = None, **kwargs):
|
|
72
87
|
"""
|
|
73
88
|
Print a log message with the current time.
|
|
74
89
|
|
|
75
90
|
Parameters:
|
|
76
|
-
|
|
77
|
-
object (dict): The object to be printed.
|
|
91
|
+
log_message (str): The message to be printed.
|
|
78
92
|
"""
|
|
79
|
-
|
|
80
|
-
logger.info(f"INFO - {message}")
|
|
81
|
-
else:
|
|
82
|
-
logger.info(f"INFO {message} - {object}")
|
|
93
|
+
MiniLogger._log(LogMessageSeverity.Debug, log_message=log_message, **kwargs)
|
|
83
94
|
|
|
84
95
|
@staticmethod
|
|
85
|
-
def
|
|
96
|
+
def info(log_message: str = None, **kwargs):
|
|
86
97
|
"""
|
|
87
98
|
Print a log message with the current time.
|
|
88
99
|
|
|
89
100
|
Parameters:
|
|
90
|
-
|
|
91
|
-
|
|
101
|
+
log_message (str): The message to be printed.
|
|
102
|
+
"""
|
|
103
|
+
MiniLogger._log(LogMessageSeverity.Info, log_message=log_message, **kwargs)
|
|
104
|
+
|
|
105
|
+
@staticmethod
|
|
106
|
+
def warning(log_message: str = None, **kwargs):
|
|
107
|
+
"""
|
|
108
|
+
Print a log message with the current time.
|
|
109
|
+
|
|
110
|
+
Parameters:
|
|
111
|
+
log_message (str): The message to be printed.
|
|
92
112
|
"""
|
|
93
113
|
# TODO Add the source of the message - We should add the object or atleast some parts of it
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
else:
|
|
97
|
-
logger.warning(f"WARNING {message} - {object}")
|
|
114
|
+
MiniLogger._log(LogMessageSeverity.Warning, log_message=log_message, **kwargs)
|
|
115
|
+
|
|
98
116
|
|
|
99
117
|
@staticmethod
|
|
100
|
-
def error(
|
|
118
|
+
def error(log_message: str = None, **kwargs):
|
|
101
119
|
"""
|
|
102
120
|
Print a log error message with the current time.
|
|
103
121
|
|
|
104
122
|
Parameters:
|
|
105
|
-
|
|
106
|
-
object (dict): The object to be printed.
|
|
123
|
+
log_message (str): The message to be printed.
|
|
107
124
|
"""
|
|
108
|
-
|
|
109
|
-
logger.error(f"ERROR - {message}")
|
|
110
|
-
else:
|
|
111
|
-
logger.error(f"ERROR - {message} - {object}")
|
|
125
|
+
MiniLogger._log(LogMessageSeverity.Error, log_message=log_message, **kwargs)
|
|
112
126
|
|
|
113
127
|
@staticmethod
|
|
114
|
-
def exception(
|
|
128
|
+
def exception(log_message: str = None, **kwargs):
|
|
115
129
|
"""
|
|
116
130
|
Print a log error message with the current time.
|
|
117
131
|
|
|
118
132
|
Parameters:
|
|
119
|
-
|
|
120
|
-
object (dict / Exception): The object / Exception to be printed.
|
|
133
|
+
log_message (str): The message to be printed.
|
|
121
134
|
"""
|
|
135
|
+
object = kwargs.get("object")
|
|
122
136
|
if isinstance(object, Exception):
|
|
123
137
|
exception = object
|
|
124
138
|
elif isinstance(object, dict):
|
|
@@ -127,6 +141,6 @@ class MiniLogger:
|
|
|
127
141
|
exception = None
|
|
128
142
|
|
|
129
143
|
if object is None:
|
|
130
|
-
logger.exception(f"EXCEPTION - {
|
|
144
|
+
logger.exception(f"EXCEPTION - {log_message}")
|
|
131
145
|
else:
|
|
132
|
-
logger.exception(f"EXCEPTION- {
|
|
146
|
+
logger.exception(f"EXCEPTION- {log_message} - {object}", exc_info=exception)
|
python_sdk_remote/utilities.py
CHANGED
|
@@ -279,42 +279,53 @@ def is_datetime_in_datetime_range(check_datetime: datetime, datetime_range: (dat
|
|
|
279
279
|
return is_datetime_in_datetime_range_result
|
|
280
280
|
|
|
281
281
|
|
|
282
|
-
def get_brand_name(
|
|
283
|
-
|
|
282
|
+
def get_brand_name(raise_if_not_found: bool = True,
|
|
283
|
+
raise_if_empty: bool = False) -> str:
|
|
284
|
+
get_brand_name_result = our_get_env("BRAND_NAME",
|
|
285
|
+
raise_if_not_found=raise_if_not_found,
|
|
286
|
+
raise_if_empty=raise_if_empty)
|
|
284
287
|
return get_brand_name_result
|
|
285
288
|
|
|
286
289
|
|
|
287
|
-
def get_environment_name(
|
|
288
|
-
|
|
290
|
+
def get_environment_name(raise_if_not_found: bool = True,
|
|
291
|
+
raise_if_empty: bool = False) -> str:
|
|
292
|
+
environment_name = our_get_env("ENVIRONMENT_NAME",
|
|
293
|
+
raise_if_not_found=raise_if_not_found,
|
|
294
|
+
raise_if_empty=raise_if_empty)
|
|
289
295
|
EnvironmentName(environment_name) # if invalid, raises ValueError: x is not a valid EnvironmentName
|
|
290
296
|
return environment_name
|
|
291
297
|
|
|
292
298
|
|
|
293
299
|
def our_get_env(key: str, default: str = None, raise_if_not_found: bool = True,
|
|
294
300
|
raise_if_empty: bool = False) -> str:
|
|
295
|
-
logger.start(object={"key": key, "default": default,
|
|
301
|
+
logger.start(object={"key": key, "default": default,
|
|
302
|
+
"raise_if_not_found": raise_if_not_found,
|
|
296
303
|
"raise_if_empty": raise_if_empty})
|
|
297
304
|
env_var = os.getenv(key, default)
|
|
305
|
+
# TODO: "default is None" is always False
|
|
298
306
|
if ((raise_if_not_found and key not in os.environ and default is None)
|
|
299
307
|
or (raise_if_empty and not env_var and not default)):
|
|
300
|
-
raise Exception(f"Environment variable {key} not found - please check your .env file")
|
|
308
|
+
raise Exception(f"Environment variable {key} not found - please check your .env file") # noqa: E501
|
|
301
309
|
logger.end(object={"env_var": env_var})
|
|
302
310
|
return env_var
|
|
303
311
|
|
|
304
312
|
|
|
305
|
-
# TODO As only the database package uses those, let's move those three to the database package
|
|
306
|
-
def get_sql_hostname() -> str:
|
|
307
|
-
get_sql_hostname_result = our_get_env("RDS_HOSTNAME"
|
|
313
|
+
# TODO As only the database package uses those, let's move those three to the database package # noqa: E501
|
|
314
|
+
def get_sql_hostname(raise_if_not_found: bool = True, raise_if_empty: bool = False) -> str:
|
|
315
|
+
get_sql_hostname_result = our_get_env("RDS_HOSTNAME",
|
|
316
|
+
raise_if_empty=raise_if_empty)
|
|
308
317
|
return get_sql_hostname_result
|
|
309
318
|
|
|
310
319
|
|
|
311
|
-
def get_sql_username() -> str:
|
|
312
|
-
get_sql_username_result = our_get_env("RDS_USERNAME"
|
|
320
|
+
def get_sql_username(raise_if_empty: bool = False) -> str:
|
|
321
|
+
get_sql_username_result = our_get_env("RDS_USERNAME",
|
|
322
|
+
raise_if_empty=raise_if_empty)
|
|
313
323
|
return get_sql_username_result
|
|
314
324
|
|
|
315
325
|
|
|
316
|
-
def get_sql_password() -> str:
|
|
317
|
-
get_sql_password_result = our_get_env("RDS_PASSWORD"
|
|
326
|
+
def get_sql_password(raise_if_empty: bool = False) -> str:
|
|
327
|
+
get_sql_password_result = our_get_env("RDS_PASSWORD",
|
|
328
|
+
raise_if_empty=raise_if_empty)
|
|
318
329
|
return get_sql_password_result
|
|
319
330
|
|
|
320
331
|
|
|
@@ -405,7 +416,7 @@ def validate_arguments(args: dict) -> None:
|
|
|
405
416
|
:return: True if all arguments are not None or '', False otherwise
|
|
406
417
|
"""
|
|
407
418
|
for arg, value in args.items():
|
|
408
|
-
if not
|
|
419
|
+
if not value:
|
|
409
420
|
raise ValueError(f"Argument {arg} is cannot be empty (got {value})")
|
|
410
421
|
|
|
411
422
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
python_sdk_remote/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
python_sdk_remote/constants.py,sha256=Zg4_KOlTkbqdKwua3oTe_64QyYvK_mhA6KnriQMBIPo,752
|
|
3
|
+
python_sdk_remote/constants_src_mini_logger.py,sha256=ukaPhopFSxnLeQwyHa4VUi3TACh4QuKn77JtSK8Z1Tg,247
|
|
4
|
+
python_sdk_remote/http_response.py,sha256=5_h9xOtUhsMzxUiLT4wkYBpL0StA7XYtaqKF4esGwis,6370
|
|
5
|
+
python_sdk_remote/is_test_data.py,sha256=zbUz-Juj7vOPG9TtIttMIBWFxbsOs4-TuR1RYfGNkp4,92
|
|
6
|
+
python_sdk_remote/item.py,sha256=6DQs1nBKbEmnHjE50vZtkMr14ECS_9b8cvE7ItPAbhE,322
|
|
7
|
+
python_sdk_remote/mini_logger.py,sha256=MYrtOQ5CkO_Rg2eQkSj6eGfJQDca_YiYBReJrOA7oNo,5662
|
|
8
|
+
python_sdk_remote/our_object.py,sha256=Db3_CbM4e1VtDU97VDesnBNMXNuYvnuDL7QqHv4MgJo,4618
|
|
9
|
+
python_sdk_remote/unified_json.py,sha256=zk4Lo9t9MSHXW8UKdo50YCYmFv5FgTsmHf6l2AWqLWU,961
|
|
10
|
+
python_sdk_remote/utilities.py,sha256=4xwiZ6dvHBFnG4LGFKoY-Sey8h5-jLOT9BcGGA9KyNY,16754
|
|
11
|
+
python_sdk_remote/valid_json_versions.py,sha256=-ZU65JYI6gTEfK8o6gu9Dmm9SQmwzj5pDbEXiyUbBhQ,138
|
|
12
|
+
python_sdk_remote/validate_environment.py,sha256=nzCHZDw56G56ekrTQT3gG48utjsU4VCwQi9dVsBDas0,2268
|
|
13
|
+
python_sdk_remote-0.0.146.dist-info/METADATA,sha256=rwIDxp7njWNgwWW57PAnBT_diDdptBdqUp3VEVXrTjk,729
|
|
14
|
+
python_sdk_remote-0.0.146.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
15
|
+
python_sdk_remote-0.0.146.dist-info/top_level.txt,sha256=JTpEq_svPlI5hTlPq30Ne-NkR-u5464gjVDP2U74PvE,18
|
|
16
|
+
python_sdk_remote-0.0.146.dist-info/RECORD,,
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
python_sdk_remote/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
python_sdk_remote/constants.py,sha256=0bg3t_4wzZLWFapseENer7qSx3NvniEF5n0H8AZ2G38,751
|
|
3
|
-
python_sdk_remote/http_response.py,sha256=eu8wF85zLqIuT5LhgCRb4fnYP5T91R92qJmejXZcgY8,6342
|
|
4
|
-
python_sdk_remote/is_test_data.py,sha256=zbUz-Juj7vOPG9TtIttMIBWFxbsOs4-TuR1RYfGNkp4,92
|
|
5
|
-
python_sdk_remote/item.py,sha256=6DQs1nBKbEmnHjE50vZtkMr14ECS_9b8cvE7ItPAbhE,322
|
|
6
|
-
python_sdk_remote/mini_logger.py,sha256=vzkrSSebDWbrgWlO1QyLuB-IJ4mIgvBxlxOMKQgAi1Y,4232
|
|
7
|
-
python_sdk_remote/our_object.py,sha256=Db3_CbM4e1VtDU97VDesnBNMXNuYvnuDL7QqHv4MgJo,4618
|
|
8
|
-
python_sdk_remote/unified_json.py,sha256=zk4Lo9t9MSHXW8UKdo50YCYmFv5FgTsmHf6l2AWqLWU,961
|
|
9
|
-
python_sdk_remote/utilities.py,sha256=JB_LQoRGDlNktbr4twg1CAGSus7d2NC_Npcpl-WR0Eo,15861
|
|
10
|
-
python_sdk_remote/valid_json_versions.py,sha256=-ZU65JYI6gTEfK8o6gu9Dmm9SQmwzj5pDbEXiyUbBhQ,138
|
|
11
|
-
python_sdk_remote/validate_environment.py,sha256=nzCHZDw56G56ekrTQT3gG48utjsU4VCwQi9dVsBDas0,2268
|
|
12
|
-
python_sdk_remote-0.0.145.dist-info/METADATA,sha256=OcPX_fOGobxPy9Mp_UMTW9sVgUK24k3YIqhpSPQNJTU,729
|
|
13
|
-
python_sdk_remote-0.0.145.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
14
|
-
python_sdk_remote-0.0.145.dist-info/top_level.txt,sha256=JTpEq_svPlI5hTlPq30Ne-NkR-u5464gjVDP2U74PvE,18
|
|
15
|
-
python_sdk_remote-0.0.145.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|