atk-common 1.9.0__py3-none-any.whl → 1.10.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/__init__.py CHANGED
@@ -1,11 +1,11 @@
1
1
  # __init__.py
2
2
  from atk_common.datetime_utils import date_time_utc, get_utc_date_time
3
3
  from atk_common.env_utils import get_env_value
4
- from atk_common.error_utils import get_message, get_error_entity, handle_error, get_response_error, get_error_type
5
- from atk_common.http_utils import is_status_code_ok, get_test_response
4
+ from atk_common.error_utils import get_message, create_error_log, get_error_entity, handle_error, get_response_error, get_error_type
5
+ from atk_common.http_utils import is_http_status_ok, is_http_status_internal, get_test_response
6
6
  from atk_common.log_utils import add_log_item, add_log_item_http
7
7
  from atk_common.rabbitmq_consumer import RabbitMQConsumer
8
- from atk_common.response_utils import create_save_resp
8
+ from atk_common.response_utils import create_response, is_response_ok
9
9
  from atk_common.docker_utils import get_current_container_info
10
10
 
11
11
  __all__ = [
@@ -13,15 +13,18 @@ __all__ = [
13
13
  'get_utc_date_time',
14
14
  'get_env_value',
15
15
  'get_message',
16
+ 'create_error_log',
16
17
  'get_error_entity',
17
18
  'handle_error',
18
19
  'get_response_error',
19
20
  'get_error_type',
20
- 'is_status_code_ok',
21
+ 'is_http_status_ok',
22
+ 'is_http_status_internal',
21
23
  'get_test_response',
22
24
  'add_log_item',
23
25
  'add_log_item_http',
24
26
  'RabbitMQConsumer',
25
- 'create_save_resp',
27
+ 'create_response',
28
+ 'is_response_ok',
26
29
  'get_current_container_info',
27
30
  ]
atk_common/db_utils.py ADDED
File without changes
@@ -1,8 +1,14 @@
1
1
  # __init__.py
2
2
  from atk_common.enums.command_status_enum import CommandStatusType
3
3
  from atk_common.enums.speed_control_status_enum import SpeedControlStatusType
4
+ from atk_common.enums.api_error_type_enum import ApiErrorType
5
+ from atk_common.enums.response_status_enum import ResponseStatus
6
+ from atk_common.enums.http_status_enum import HttpStatus
4
7
 
5
8
  __all__ = [
6
9
  'CommandStatusType',
7
- 'SpeedControlStatusType'
10
+ 'SpeedControlStatusType',
11
+ 'ApiErrorType',
12
+ 'ResponseStatus',
13
+ 'HttpStatus',
8
14
  ]
@@ -0,0 +1,5 @@
1
+ from enum import Enum
2
+
3
+ class ApiErrorType(Enum):
4
+ CONNECTION = 1
5
+ INTERNAL = 2
@@ -0,0 +1,8 @@
1
+ from enum import Enum
2
+
3
+ class HttpStatus(Enum):
4
+ INFO = 100
5
+ OK = 200
6
+ REDIRECT = 300
7
+ CLIENT = 400
8
+ INTERNAL = 500
@@ -0,0 +1,6 @@
1
+ from enum import Enum
2
+
3
+ class ResponseStatus(Enum):
4
+ OK = 0
5
+ HTTP = 1
6
+ INTERNAL = 2
atk_common/error_utils.py CHANGED
@@ -1,6 +1,9 @@
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.enums.api_error_type_enum import ApiErrorType
5
+ from atk_common.enums.http_status_enum import HttpStatus
6
+ from atk_common.http_utils import is_http_status_internal
4
7
  from atk_common.log_utils import add_log_item
5
8
  from atk_common.response_utils import create_save_resp
6
9
 
@@ -35,13 +38,13 @@ def get_error_entity(app, error, method, error_type, status_code, container_info
35
38
  if app is not None:
36
39
  return app.response_class(
37
40
  response=json.dumps(data),
38
- status=500,
41
+ status=HttpStatus.INTERNAL,
39
42
  mimetype='application/json'
40
43
  )
41
44
  return None
42
45
 
43
46
  def handle_error(resp, status):
44
- if resp.status_code == 500:
47
+ if is_http_status_internal(resp.status_code):
45
48
  add_log_item(resp.json().get('message'))
46
49
  return create_save_resp(status, resp.status_code, resp.json())
47
50
  else:
@@ -49,7 +52,7 @@ def handle_error(resp, status):
49
52
  return create_save_resp(status, resp.status_code, resp.text)
50
53
 
51
54
  def get_response_error(resp):
52
- if resp.status_code == 500:
55
+ if is_http_status_internal(resp.status_code):
53
56
  return resp.json()
54
57
  else:
55
58
  return resp.text
@@ -59,5 +62,5 @@ def get_response_error(resp):
59
62
  # 2 - Internal error
60
63
  def get_error_type(conn):
61
64
  if conn is None:
62
- return 1
63
- return 2
65
+ return ApiErrorType.CONNECTION
66
+ return ApiErrorType.INTERNAL
atk_common/http_utils.py CHANGED
@@ -1,26 +1,14 @@
1
1
  import json
2
2
  from atk_common.datetime_utils import get_utc_date_time
3
3
  from atk_common.docker_utils import get_current_container_info
4
+ from atk_common.enums.http_status_enum import HttpStatus
4
5
  from atk_common.env_utils import get_env_value
5
6
 
6
- def is_status_code_ok(status_code):
7
- return status_code >= 200 and status_code < 300
7
+ def is_http_status_ok(status_code):
8
+ return status_code >= HttpStatus.OK.value and status_code < HttpStatus.REDIRECT.value
8
9
 
9
- def get_test_response():
10
- data = {}
11
- container_info = get_current_container_info()
12
- if container_info is not None:
13
- data['imageName'] = container_info['imageName']
14
- data['imageVersion'] = container_info['imageVersion']
15
- data['containerName'] = container_info['containerName']
16
- data['containerPorts'] = container_info['ports']
17
- else:
18
- data['imageName'] = None
19
- data['imageVersion'] = None
20
- data['containerName'] = None
21
- data['containerPorts'] = None
22
- data['timestamp'] = get_utc_date_time()
23
- return data
10
+ def is_http_status_internal(status_code):
11
+ return status_code >= HttpStatus.INTERNAL.value
24
12
 
25
13
  def get_test_response(docker_container_data, component):
26
14
  data = {}
atk_common/log_utils.py CHANGED
@@ -1,4 +1,5 @@
1
1
  from atk_common.datetime_utils import get_utc_date_time
2
+ from atk_common.http_utils import is_http_status_internal
2
3
 
3
4
  def create_date_time():
4
5
  date_time = get_utc_date_time()
@@ -8,7 +9,7 @@ def add_log_item(text):
8
9
  print(create_date_time() + text)
9
10
 
10
11
  def add_log_item_http(resp):
11
- if resp.status_code == 500:
12
+ if is_http_status_internal(resp.status_code):
12
13
  err_resp_json = resp.json().get('message')
13
14
  add_log_item(err_resp_json)
14
15
  else:
atk_common/mq_utils.py ADDED
File without changes
@@ -1,6 +1,11 @@
1
- def create_save_resp(status, status_code, response_msg):
1
+ from atk_common.enums.response_status_enum import ResponseStatus
2
+
3
+ def create_response(status, status_code, response_msg):
2
4
  data = {}
3
5
  data['status'] = status
4
6
  data['statusCode'] = status_code
5
7
  data['responseMsg'] = response_msg
6
8
  return data
9
+
10
+ def is_response_ok(response):
11
+ return response['status'] == ResponseStatus.OK
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: atk_common
3
- Version: 1.9.0
3
+ Version: 1.10.0
4
4
  Summary: ATK common methods
5
5
  Home-page: https://github.com/pypa/atk_common
6
6
  Author: Roger
@@ -1,14 +1,19 @@
1
- atk_common/__init__.py,sha256=9aedYjZ5adS3zor4HPYubrFAmq2LuxhdtfwUKjDS6dE,956
1
+ atk_common/__init__.py,sha256=nG-PFquhz5ycFh1zY1zLqAFPOCbalD80_YmLcJ4vqr0,1093
2
2
  atk_common/datetime_utils.py,sha256=qsVF7l90P1-xukG2tV_jLqG9J_Yfl5wTpyfrdPBlyMo,239
3
+ atk_common/db_utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
4
  atk_common/docker_utils.py,sha256=nkUhp2OhwJsm41JDujHDY-JxQfdDjy91duprH59Esfk,2084
4
5
  atk_common/env_utils.py,sha256=66v-S0vlkJNaun6ay1XcOGRtYJb4Ce4odJsWxuaHsQc,373
5
- atk_common/error_utils.py,sha256=JBc-yl5_29BSZ6d2kZBEX3X17qCDvEa_GZ7FC7sYwdc,2115
6
- atk_common/http_utils.py,sha256=IQDVPgnu3L1FuMbBOWWfxpL80-YNAQYF93iMK9l1uA4,1189
7
- atk_common/log_utils.py,sha256=DGGwXjD5jvpMZJNW1QBoJRdDaTY1e1Z69j0LSOOzsWA,419
6
+ atk_common/error_utils.py,sha256=wRS6o691hleAPdTE-R90Q6xNSLTvxTuDswaBHiivuC0,2389
7
+ atk_common/http_utils.py,sha256=gbXTNIQsl4wLZzZVkaIcZWQT8VrngnmdJySZXZH07RM,789
8
+ atk_common/log_utils.py,sha256=k7VaknmSGvHQV6-eznltNUa3BOAywjFHkhVzDT1P0Hs,496
9
+ atk_common/mq_utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
10
  atk_common/rabbitmq_consumer.py,sha256=4MhuwZs47Jt1fX4sUxr1MKRe7o2QRbPe9_utXEsa8QE,1907
9
- atk_common/response_utils.py,sha256=ezqTSNdGwueFXzijKB7CKPWxZml39bqjAZOeIMWMntk,197
10
- atk_common/enums/__init__.py,sha256=oW0aVnwewfH6sNu14jjZ5_uP4iRN4pRmGdTNC204rHo,236
11
+ atk_common/response_utils.py,sha256=jlCm3a7GKolV6zR1emIEGmMH93V6yktiv-lgNa3TNEw,349
12
+ atk_common/enums/__init__.py,sha256=0XQUbLYh9phfGd_dw3OqwJrdo1QLxCMTaKKXr4YwwLI,487
13
+ atk_common/enums/api_error_type_enum.py,sha256=9oW6ZaZ3lhMwR8r2sVNWGliS9C_jV-otiOYdezAuTp0,91
11
14
  atk_common/enums/command_status_enum.py,sha256=M2Nln27a_DbzI07-gfytWQk2X087JhkU6Fmard5qVHs,127
15
+ atk_common/enums/http_status_enum.py,sha256=bJSTmkLxHnb04fWSDKuhTWrh_v9iCQM7otAVr731JDk,139
16
+ atk_common/enums/response_status_enum.py,sha256=ogYXlGm0gJJDGlY6Fwq9Kvl861aGPop2qzfXXExzMKw,99
12
17
  atk_common/enums/speed_control_status_enum.py,sha256=qpURh0K1L1tSpbrzVnckoe4hUn1illIkbo7k4mLfzIM,182
13
18
  atk_package/__init__.py,sha256=EceDa352WFHTdC_LxYANXf_TS9pGzK3MCx87bwAKTvg,811
14
19
  atk_package/datetime_utils.py,sha256=qsVF7l90P1-xukG2tV_jLqG9J_Yfl5wTpyfrdPBlyMo,239
@@ -22,8 +27,8 @@ atk_package/enums/__init__.py,sha256=oW0aVnwewfH6sNu14jjZ5_uP4iRN4pRmGdTNC204rHo
22
27
  atk_package/enums/command_status_enum.py,sha256=M2Nln27a_DbzI07-gfytWQk2X087JhkU6Fmard5qVHs,127
23
28
  atk_package/enums/speed_control_status_enum.py,sha256=qpURh0K1L1tSpbrzVnckoe4hUn1illIkbo7k4mLfzIM,182
24
29
  shared_python_atk_enforcement/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- atk_common-1.9.0.dist-info/METADATA,sha256=RW86i4Zpx9h0Yp8GwBjyGLDdfpzJjeKxiBqV6jvBoWM,1193
26
- atk_common-1.9.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
27
- atk_common-1.9.0.dist-info/license.txt,sha256=_0O6fWM00-wTurDjnZhUP_N5QiwGhItaQZqHq5eqadA,1063
28
- atk_common-1.9.0.dist-info/top_level.txt,sha256=4CwRjkLnheIdI4jQwc4tK3dbRc58WqUmoqjkdDTWlME,41
29
- atk_common-1.9.0.dist-info/RECORD,,
30
+ atk_common-1.10.0.dist-info/METADATA,sha256=1W7R0zeJiJLUfLBLny5W8tI1Y8_F8hGv6nWrq08_ZQs,1194
31
+ atk_common-1.10.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
32
+ atk_common-1.10.0.dist-info/license.txt,sha256=_0O6fWM00-wTurDjnZhUP_N5QiwGhItaQZqHq5eqadA,1063
33
+ atk_common-1.10.0.dist-info/top_level.txt,sha256=4CwRjkLnheIdI4jQwc4tK3dbRc58WqUmoqjkdDTWlME,41
34
+ atk_common-1.10.0.dist-info/RECORD,,