atk-common 3.18.0__py3-none-any.whl → 3.20.0__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.
- atk_common/classes/env_handler.py +53 -15
- atk_common/interfaces/env_handler_interface.py +1 -2
- atk_common/interfaces/logger_interface.py +0 -1
- {atk_common-3.18.0.dist-info → atk_common-3.20.0.dist-info}/METADATA +1 -1
- {atk_common-3.18.0.dist-info → atk_common-3.20.0.dist-info}/RECORD +8 -8
- {atk_common-3.18.0.dist-info → atk_common-3.20.0.dist-info}/WHEEL +0 -0
- {atk_common-3.18.0.dist-info → atk_common-3.20.0.dist-info}/licenses/license.txt +0 -0
- {atk_common-3.18.0.dist-info → atk_common-3.20.0.dist-info}/top_level.txt +0 -0
@@ -1,13 +1,17 @@
|
|
1
1
|
import os
|
2
|
+
from pathlib import Path
|
2
3
|
from typing import Optional
|
3
4
|
from atk_common.interfaces import IEnvHandler
|
4
5
|
from atk_common.interfaces import ILogger
|
5
6
|
|
6
|
-
class
|
7
|
-
def __init__(self, logger: Optional[ILogger]):
|
7
|
+
class MyEnvHandler(IEnvHandler):
|
8
|
+
def __init__(self, logger: Optional[ILogger]):
|
8
9
|
self.logger = logger
|
9
10
|
|
10
|
-
def
|
11
|
+
def set_logger(self, logger: ILogger):
|
12
|
+
self.logger = logger
|
13
|
+
|
14
|
+
def val_str(self, value: Optional[object]) -> str:
|
11
15
|
if value is None:
|
12
16
|
return '<Empty>'
|
13
17
|
if isinstance(value, str):
|
@@ -16,23 +20,57 @@ class EnvHandler(IEnvHandler):
|
|
16
20
|
return value
|
17
21
|
return str(value)
|
18
22
|
|
19
|
-
def is_value_null_or_empty(self, value):
|
20
|
-
if
|
21
|
-
return
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def is_value_null_or_empty(self, value: Optional[str]) -> bool:
|
24
|
+
if value is None:
|
25
|
+
return True
|
26
|
+
s = value.strip()
|
27
|
+
return s == '' or s.lower() == 'null'
|
28
|
+
|
29
|
+
def get_env_value(self, key: str) -> Optional[str]:
|
25
30
|
val = os.environ.get(key)
|
31
|
+
if val is None:
|
32
|
+
err_msg = f"Environment key '{key}' is missing."
|
33
|
+
if self.logger:
|
34
|
+
self.logger.error(err_msg)
|
35
|
+
raise ValueError(err_msg)
|
26
36
|
if self.logger:
|
27
37
|
self.logger.info(key + ':' + self.val_str(val))
|
28
|
-
if val
|
29
|
-
|
38
|
+
if self.is_value_null_or_empty(val):
|
39
|
+
return None
|
40
|
+
return val
|
41
|
+
|
42
|
+
@staticmethod
|
43
|
+
def read_secret(path):
|
44
|
+
return Path(path).read_text().rstrip('\n')
|
45
|
+
|
46
|
+
def get_env_value_secret(self, key: str, file_key: str) -> str:
|
47
|
+
val = os.environ.get(key)
|
48
|
+
if val is None:
|
49
|
+
err_msg = f"Environment key '{key}' is missing."
|
30
50
|
if self.logger:
|
31
51
|
self.logger.error(err_msg)
|
32
52
|
raise ValueError(err_msg)
|
33
53
|
if self.is_value_null_or_empty(val):
|
34
|
-
|
54
|
+
secret_path = os.getenv(file_key)
|
55
|
+
if secret_path is None:
|
56
|
+
err_msg = f"Secret file key '{file_key}' is missing."
|
57
|
+
if self.logger:
|
58
|
+
self.logger.error(err_msg)
|
59
|
+
raise ValueError(err_msg)
|
60
|
+
if self.is_value_null_or_empty(secret_path):
|
61
|
+
err_msg = f"Secret file variable '{file_key}' is not set."
|
62
|
+
if self.logger:
|
63
|
+
self.logger.error(err_msg)
|
64
|
+
raise ValueError(err_msg)
|
65
|
+
if not Path(secret_path).is_file():
|
66
|
+
err_msg = f"Secret file '{secret_path}' not found."
|
67
|
+
if self.logger:
|
68
|
+
self.logger.error(err_msg)
|
69
|
+
raise ValueError(err_msg)
|
70
|
+
val = self.read_secret(secret_path)
|
71
|
+
if self.is_value_null_or_empty(val):
|
72
|
+
err_msg = f"Secret from key file '{secret_path}' is empty."
|
73
|
+
if self.logger:
|
74
|
+
self.logger.error(err_msg)
|
75
|
+
raise ValueError(err_msg)
|
35
76
|
return val
|
36
|
-
|
37
|
-
def set_logger(self, logger: ILogger):
|
38
|
-
self.logger = logger
|
@@ -1,9 +1,8 @@
|
|
1
1
|
# interfaces/env_handler_interface.py
|
2
2
|
from typing import Optional, Protocol
|
3
|
-
from atk_common.interfaces import ILogger
|
4
3
|
|
5
4
|
class IEnvHandler(Protocol):
|
6
|
-
def set_logger(self, logger
|
5
|
+
def set_logger(self, logger) -> None: ...
|
7
6
|
def val_str(self, value: Optional[object]) -> str: ...
|
8
7
|
def is_value_null_or_empty(self, value: Optional[str]) -> bool: ...
|
9
8
|
def get_env_value(self, key: str) -> Optional[str]: ...
|
@@ -19,7 +19,7 @@ atk_common/response_utils.py,sha256=AxlmwkFoDU5XcFOzBQiuZxAQgswihpKXHSo1T0JJw3Q,
|
|
19
19
|
atk_common/classes/__init__.py,sha256=O_VHYxAilmoz3i9L6jkwS-JZ4UaTezdhFiA5liNl1lY,532
|
20
20
|
atk_common/classes/bo_logger.py,sha256=wo1-BNWZjzSnlcM7c0LB7tK__2g3BENXvSvCLEiTOME,2065
|
21
21
|
atk_common/classes/docker_handler.py,sha256=VNJecc2ZWcpwNBa61QTGM_kYrsoZTjktMcFRFGF4xI4,3048
|
22
|
-
atk_common/classes/env_handler.py,sha256=
|
22
|
+
atk_common/classes/env_handler.py,sha256=_Lv_sBUCwsjxO22oRSC4v2xrbVMv-DMW2Mer4OQKJmk,2877
|
23
23
|
atk_common/classes/error_handler.py,sha256=DgRzWx4Yu8PKX1bqj55aWhrkqb92ebDaEwtxgKhTLls,3270
|
24
24
|
atk_common/classes/http_response_handler.py,sha256=qgtGyEwUe4lIiayS6syWanr2VE6GaKHddazNL_PxEFM,2327
|
25
25
|
atk_common/classes/rabbitmq_consumer.py,sha256=UySYDCMXCapi5XNQnsn7q7sVcVvZKKo73qj6OpEv8Ak,3004
|
@@ -66,10 +66,10 @@ atk_common/enums/test_image_type_enum.py,sha256=HUjxJorehnzRXMNF2uHk2DrAJ3Y_ajQv
|
|
66
66
|
atk_common/enums/violation_type_enum.py,sha256=01qTHOj-O8bOc-nwIHVnxLosm4cusD_YuqXM3ZsiRRk,86
|
67
67
|
atk_common/interfaces/__init__.py,sha256=HynEg28Uy3msO7qd__VxajTasSe9-Evpj9yi3Uw2NTo,508
|
68
68
|
atk_common/interfaces/docker_handler_interface.py,sha256=hs71uNcFvSbTqRvcL4XarHx6DONP1J7MrUUz-oO28bM,458
|
69
|
-
atk_common/interfaces/env_handler_interface.py,sha256=
|
69
|
+
atk_common/interfaces/env_handler_interface.py,sha256=9pBQMUp5Sq-T3ewHX-BXigWyS3Wt8ZDrcJ-xQmTlRpc,424
|
70
70
|
atk_common/interfaces/error_handler_interface.py,sha256=ErhQ69T3fCYUl6sS5GwiMgW-znapmGcmgWLR2QLNu8c,506
|
71
71
|
atk_common/interfaces/http_response_handler_interface.py,sha256=Cl_njN_klHz1u06FCJPata1dua1w4Cs-Qt9Rg7uaB1c,169
|
72
|
-
atk_common/interfaces/logger_interface.py,sha256=
|
72
|
+
atk_common/interfaces/logger_interface.py,sha256=H23ZyDgeuHCgURWW8zDe-LYaKge3GT5CfQpfHXS0a4A,421
|
73
73
|
atk_common/utils/__init__.py,sha256=hU5xicoI6dXRDz0gQADIDo2YbiL2UptTehVBISReIDo,1857
|
74
74
|
atk_common/utils/consumer_retry_handler.py,sha256=aumO5iwVP90UI3aYpMQeQXuDElSZfSmI5wxz6pbNnJY,2811
|
75
75
|
atk_common/utils/datetime_utils.py,sha256=h3tv6iPD4peBXLCAcws41nuxIM4KpR1vk71LYXTDHKo,3662
|
@@ -82,7 +82,7 @@ atk_common/utils/http_utils.py,sha256=eSRuQeDgN0ISQdByZqE6cIGXoorcAXz7PEtVntHUKA
|
|
82
82
|
atk_common/utils/internal_response_utils.py,sha256=2X9eLFEy1pO3Aesj1IRXg2yprwNcBDM5_dXaA5vfmMI,694
|
83
83
|
atk_common/utils/mq_utils.py,sha256=DmVcXIZHG45p7cQVvgen6OT8QbW_UifFFJGJBybTkJQ,1835
|
84
84
|
atk_common/utils/str_utils.py,sha256=sg3jwTTIfQvgGP-lcY5Xh4PXXhKWse_4HswBQYQKEo4,260
|
85
|
-
atk_common-3.
|
85
|
+
atk_common-3.20.0.dist-info/licenses/license.txt,sha256=_0O6fWM00-wTurDjnZhUP_N5QiwGhItaQZqHq5eqadA,1063
|
86
86
|
atk_package/__init__.py,sha256=okIFEefQhQrw6DZg6oCEVWsEdkVCk-57VXBW0IUG_wU,834
|
87
87
|
atk_package/datetime_utils.py,sha256=qsVF7l90P1-xukG2tV_jLqG9J_Yfl5wTpyfrdPBlyMo,239
|
88
88
|
atk_package/env_utils.py,sha256=bXOrxM3fZUslqfmZt75iphbEJHbG4riJa8XOVzPwIII,313
|
@@ -95,7 +95,7 @@ atk_package/enums/__init__.py,sha256=EtUr_--MQj1Rc_R0sF_ELXIThmhpfmhDWq3YaK9oQMk
|
|
95
95
|
atk_package/enums/command_status_enum.py,sha256=M2Nln27a_DbzI07-gfytWQk2X087JhkU6Fmard5qVHs,127
|
96
96
|
atk_package/enums/speed_control_status_enum.py,sha256=qpURh0K1L1tSpbrzVnckoe4hUn1illIkbo7k4mLfzIM,182
|
97
97
|
shared_python_atk_enforcement/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
98
|
-
atk_common-3.
|
99
|
-
atk_common-3.
|
100
|
-
atk_common-3.
|
101
|
-
atk_common-3.
|
98
|
+
atk_common-3.20.0.dist-info/METADATA,sha256=1-z5T2ctaAYb54SFV5AL8upYfRo7S--P5QdDYDXe5cQ,1761
|
99
|
+
atk_common-3.20.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
100
|
+
atk_common-3.20.0.dist-info/top_level.txt,sha256=4CwRjkLnheIdI4jQwc4tK3dbRc58WqUmoqjkdDTWlME,41
|
101
|
+
atk_common-3.20.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|