atk-common 1.3.0__py3-none-any.whl → 1.4.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/docker_utils.py +65 -0
- atk_common/env_utils.py +2 -0
- atk_common/error_utils.py +3 -1
- atk_common/http_utils.py +22 -0
- atk_common/rabbitmq_consumer.py +5 -3
- {atk_common-1.3.0.dist-info → atk_common-1.4.0.dist-info}/METADATA +1 -1
- {atk_common-1.3.0.dist-info → atk_common-1.4.0.dist-info}/RECORD +10 -9
- {atk_common-1.3.0.dist-info → atk_common-1.4.0.dist-info}/WHEEL +0 -0
- {atk_common-1.3.0.dist-info → atk_common-1.4.0.dist-info}/license.txt +0 -0
- {atk_common-1.3.0.dist-info → atk_common-1.4.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
import docker
|
2
|
+
import os
|
3
|
+
import socket
|
4
|
+
from atk_common.env_utils import get_env_value
|
5
|
+
|
6
|
+
def find_image_prop_list_by_name(image_list, image_name):
|
7
|
+
for image in image_list:
|
8
|
+
if image.tags and len(image.tags) > 0:
|
9
|
+
# Check if the image name is in the first tag
|
10
|
+
if image_name in image.tags[0]:
|
11
|
+
return image.tags[0]
|
12
|
+
return None
|
13
|
+
|
14
|
+
def get_image_version(default_value=None):
|
15
|
+
"""
|
16
|
+
Get the version of a Docker image.
|
17
|
+
|
18
|
+
:param image_name: Name of the Docker image
|
19
|
+
:return: Version of the Docker image
|
20
|
+
"""
|
21
|
+
try:
|
22
|
+
image_name = get_env_value('DOCKER_IMAGE_NAME', default_value)
|
23
|
+
if image_name is None:
|
24
|
+
return None
|
25
|
+
client = docker.from_env()
|
26
|
+
image_list = client.images.list()
|
27
|
+
image_prop_list = find_image_prop_list_by_name(image_list, image_name)
|
28
|
+
if image_prop_list is None:
|
29
|
+
return None
|
30
|
+
image_props = image_prop_list.split(':')
|
31
|
+
if len(image_props) < 2:
|
32
|
+
return None
|
33
|
+
return image_props[1]
|
34
|
+
except docker.errors.ImageNotFound:
|
35
|
+
return None
|
36
|
+
|
37
|
+
def get_current_container_info():
|
38
|
+
try:
|
39
|
+
client = docker.from_env()
|
40
|
+
|
41
|
+
# Get current container's hostname (usually the container ID)
|
42
|
+
container_id = socket.gethostname()
|
43
|
+
|
44
|
+
# Fetch container object using partial ID
|
45
|
+
container = client.containers.get(container_id)
|
46
|
+
|
47
|
+
name = container.name
|
48
|
+
ports = container.attrs['NetworkSettings']['Ports']
|
49
|
+
|
50
|
+
print(f"🔍 Container name: {name}")
|
51
|
+
print("🌐 Port mappings:")
|
52
|
+
if ports:
|
53
|
+
for container_port, host_bindings in ports.items():
|
54
|
+
if host_bindings:
|
55
|
+
for binding in host_bindings:
|
56
|
+
print(f" {container_port} -> {binding['HostIp']}:{binding['HostPort']}")
|
57
|
+
else:
|
58
|
+
print(f" {container_port} -> Not bound to host")
|
59
|
+
else:
|
60
|
+
print("No exposed ports found.")
|
61
|
+
return None
|
62
|
+
|
63
|
+
except Exception as e:
|
64
|
+
print("❌ Error getting container info:", e)
|
65
|
+
return None
|
atk_common/env_utils.py
CHANGED
atk_common/error_utils.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
from datetime import datetime
|
2
2
|
import json
|
3
3
|
from atk_common.datetime_utils import get_utc_date_time
|
4
|
+
from atk_common.docker_utils import get_image_version
|
4
5
|
from atk_common.log_utils import add_log_item
|
5
6
|
from atk_common.response_utils import create_save_resp
|
6
7
|
|
@@ -18,6 +19,7 @@ def get_error_entity(app, error, component, method, error_type, status_code):
|
|
18
19
|
data['message'] = get_message(error)
|
19
20
|
data['component'] = component
|
20
21
|
data['method'] = method
|
22
|
+
data['imageVersion'] = get_image_version(component)
|
21
23
|
data['timestamp'] = get_utc_date_time()
|
22
24
|
return app.response_class(
|
23
25
|
response=json.dumps(data),
|
@@ -41,7 +43,7 @@ def get_response_error(resp):
|
|
41
43
|
|
42
44
|
# Return values:
|
43
45
|
# 1 - Connection error
|
44
|
-
# 2 -
|
46
|
+
# 2 - Internal error
|
45
47
|
def get_error_type(conn):
|
46
48
|
if conn is None:
|
47
49
|
return 1
|
atk_common/http_utils.py
CHANGED
@@ -1,2 +1,24 @@
|
|
1
|
+
import json
|
2
|
+
from atk_common.datetime_utils import get_utc_date_time
|
3
|
+
from atk_common.docker_utils import get_current_container_info, get_image_version
|
4
|
+
from atk_common.env_utils import get_env_value
|
5
|
+
|
1
6
|
def is_status_code_ok(status_code):
|
2
7
|
return status_code >= 200 and status_code < 300
|
8
|
+
|
9
|
+
def get_test_response(default_value=None):
|
10
|
+
data = {}
|
11
|
+
container_info = get_current_container_info()
|
12
|
+
if container_info is not None:
|
13
|
+
data['containerName'] = container_info.name
|
14
|
+
data['containerPorts'] = container_info.ports
|
15
|
+
else:
|
16
|
+
data['containerName'] = None
|
17
|
+
data['containerPorts'] = None
|
18
|
+
data['imageName'] = get_env_value('DOCKER_IMAGE_NAME', default_value)
|
19
|
+
if data['imageName'] is None:
|
20
|
+
data['imageVersion'] = None
|
21
|
+
else:
|
22
|
+
data['imageVersion'] = get_image_version(data['imageName'])
|
23
|
+
data['timestamp'] = get_utc_date_time()
|
24
|
+
return json.dumps(data)
|
atk_common/rabbitmq_consumer.py
CHANGED
@@ -3,12 +3,11 @@ import socket
|
|
3
3
|
import time
|
4
4
|
|
5
5
|
class RabbitMQConsumer:
|
6
|
-
def __init__(self, queue_name, user, pwd, host, vhost, dlx, dlq,
|
6
|
+
def __init__(self, queue_name, user, pwd, host, vhost, dlx, dlq, content_type, message_handler, log):
|
7
7
|
|
8
8
|
rabbit_url = 'amqp://' + user + ':' + pwd + '@' + host + '/' + vhost
|
9
9
|
|
10
10
|
self.connection = Connection(rabbit_url, heartbeat=10)
|
11
|
-
queue = None
|
12
11
|
if dlx is not None and dlq is not None:
|
13
12
|
queue = Queue(name=queue_name,
|
14
13
|
queue_arguments={
|
@@ -17,7 +16,10 @@ class RabbitMQConsumer:
|
|
17
16
|
)
|
18
17
|
else:
|
19
18
|
queue = Queue(name=queue_name)
|
20
|
-
|
19
|
+
if content_type is not None:
|
20
|
+
self.consumer = Consumer(self.connection, queues=queue, callbacks=[message_handler], accept=[content_type])
|
21
|
+
else:
|
22
|
+
self.consumer = Consumer(self.connection, queues=queue, callbacks=[message_handler], accept=None)
|
21
23
|
self.consumer.consume()
|
22
24
|
|
23
25
|
self.message_handler = message_handler # Custom message handler
|
@@ -1,10 +1,11 @@
|
|
1
1
|
atk_common/__init__.py,sha256=EceDa352WFHTdC_LxYANXf_TS9pGzK3MCx87bwAKTvg,811
|
2
2
|
atk_common/datetime_utils.py,sha256=qsVF7l90P1-xukG2tV_jLqG9J_Yfl5wTpyfrdPBlyMo,239
|
3
|
-
atk_common/
|
4
|
-
atk_common/
|
5
|
-
atk_common/
|
3
|
+
atk_common/docker_utils.py,sha256=BuulyBYuUoNS-iV4ZsknRifx5L2KWcKrrHDRqg6zqaY,2194
|
4
|
+
atk_common/env_utils.py,sha256=66v-S0vlkJNaun6ay1XcOGRtYJb4Ce4odJsWxuaHsQc,373
|
5
|
+
atk_common/error_utils.py,sha256=5OiL5nMBEkDc193m2cVMD2Bs-fwRvPeSlI7PwnqB0o4,1533
|
6
|
+
atk_common/http_utils.py,sha256=AzWuSkiH086JNsyAw1smOP6bNGyyeL4KkkxLYyNadOQ,936
|
6
7
|
atk_common/log_utils.py,sha256=DGGwXjD5jvpMZJNW1QBoJRdDaTY1e1Z69j0LSOOzsWA,419
|
7
|
-
atk_common/rabbitmq_consumer.py,sha256=
|
8
|
+
atk_common/rabbitmq_consumer.py,sha256=4MhuwZs47Jt1fX4sUxr1MKRe7o2QRbPe9_utXEsa8QE,1907
|
8
9
|
atk_common/response_utils.py,sha256=ezqTSNdGwueFXzijKB7CKPWxZml39bqjAZOeIMWMntk,197
|
9
10
|
atk_common/enums/__init__.py,sha256=oW0aVnwewfH6sNu14jjZ5_uP4iRN4pRmGdTNC204rHo,236
|
10
11
|
atk_common/enums/command_status_enum.py,sha256=M2Nln27a_DbzI07-gfytWQk2X087JhkU6Fmard5qVHs,127
|
@@ -21,8 +22,8 @@ atk_package/enums/__init__.py,sha256=oW0aVnwewfH6sNu14jjZ5_uP4iRN4pRmGdTNC204rHo
|
|
21
22
|
atk_package/enums/command_status_enum.py,sha256=M2Nln27a_DbzI07-gfytWQk2X087JhkU6Fmard5qVHs,127
|
22
23
|
atk_package/enums/speed_control_status_enum.py,sha256=qpURh0K1L1tSpbrzVnckoe4hUn1illIkbo7k4mLfzIM,182
|
23
24
|
shared_python_atk_enforcement/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
|
-
atk_common-1.
|
25
|
-
atk_common-1.
|
26
|
-
atk_common-1.
|
27
|
-
atk_common-1.
|
28
|
-
atk_common-1.
|
25
|
+
atk_common-1.4.0.dist-info/METADATA,sha256=WDZvHM1C2qyv4CZcFatHogVf8xonI0FF1SFO6XNcuRc,1193
|
26
|
+
atk_common-1.4.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
27
|
+
atk_common-1.4.0.dist-info/license.txt,sha256=_0O6fWM00-wTurDjnZhUP_N5QiwGhItaQZqHq5eqadA,1063
|
28
|
+
atk_common-1.4.0.dist-info/top_level.txt,sha256=4CwRjkLnheIdI4jQwc4tK3dbRc58WqUmoqjkdDTWlME,41
|
29
|
+
atk_common-1.4.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|