atk-common 1.36.0__py3-none-any.whl → 1.37.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
@@ -4,7 +4,7 @@ from atk_common.db_utils import sql, sql_with_record, convert_none_to_null, date
4
4
  from atk_common.docker_utils import get_current_container_info
5
5
  from atk_common.env_utils import get_env_value
6
6
  from atk_common.error_utils import get_message, create_error_log, get_error_entity, resend_error_entity, handle_error, get_response_error, get_error_type
7
- from atk_common.http_utils import is_http_status_ok, is_http_status_internal, get_test_response
7
+ from atk_common.http_utils import is_http_status_ok, is_http_status_internal, get_test_response, create_http_response
8
8
  from atk_common.file_utils import get_image_file_type
9
9
  from atk_common.log_utils import add_log_item, add_log_item_http
10
10
  from atk_common.rabbitmq_consumer import RabbitMQConsumer
@@ -31,6 +31,7 @@ __all__ = [
31
31
  'is_http_status_ok',
32
32
  'is_http_status_internal',
33
33
  'get_test_response',
34
+ 'create_http_response',
34
35
  'get_image_file_type',
35
36
  'add_log_item',
36
37
  'add_log_item_http',
atk_common/error_utils.py CHANGED
@@ -43,18 +43,10 @@ def get_error_entity(error, method, error_type, status_code, container_info):
43
43
  mimetype='application/json'
44
44
  )
45
45
 
46
- def resend_error_entity(error_entity, method, container_info):
47
- data = {}
48
- data['statusCode'] = error_entity['statusCode']
49
- data['exceptionType'] = error_entity['exceptionType']
50
- data['errorType'] = error_entity['errorType']
51
- data['message'] = error_entity['message']
52
- data['method'] = method
53
- data['timestamp'] = get_utc_date_time()
54
- data['containerInfo'] = container_info
55
- create_error_log(data)
46
+ def resend_error_entity(error_entity):
47
+ create_error_log(error_entity)
56
48
  return Response(
57
- response=json.dumps(data),
49
+ response=json.dumps(error_entity),
58
50
  status=HTTPStatus.INTERNAL_SERVER_ERROR,
59
51
  mimetype='application/json'
60
52
  )
atk_common/http_utils.py CHANGED
@@ -1,5 +1,10 @@
1
+ from flask import Response
2
+ import json
1
3
  from http import HTTPStatus
2
4
  from atk_common.datetime_utils import get_utc_date_time
5
+ from atk_common.enums.api_error_type_enum import ApiErrorType
6
+ from atk_common.error_utils import get_error_entity, resend_error_entity
7
+ from atk_common.response_utils import is_response_http
3
8
 
4
9
  def is_http_status_ok(status_code):
5
10
  return status_code >= HTTPStatus.OK.value and status_code < HTTPStatus.MULTIPLE_CHOICES.value
@@ -16,3 +21,22 @@ def get_test_response(docker_container_data, component):
16
21
  else:
17
22
  data['containerData'] = docker_container_data
18
23
  return data
24
+
25
+ # If response['status'] == 0 (OK, http status = 200): create Response and return response['responseMsg']
26
+ # If http status == 500:
27
+ # If response['status'] == 1 (HTTP): resend received error entity
28
+ # If response['status'] == 2 (INTERNAL): create new error entity and return as response
29
+ # If http status other value: create new error entity and return as response
30
+ def create_http_response(method, response, container_info):
31
+ if is_http_status_ok(response['statusCode']):
32
+ return Response(
33
+ response=json.dumps(response['responseMsg']),
34
+ status=HTTPStatus.OK,
35
+ mimetype='application/json'
36
+ )
37
+ if is_http_status_internal(response['statusCode']):
38
+ if is_response_http(response):
39
+ resend_error_entity(response['responseMsg'])
40
+ return get_error_entity(response['responseMsg'], method, ApiErrorType.INTERNAL, response['statusCode'], container_info)
41
+ return get_error_entity(response['responseMsg'], method, ApiErrorType.CONNECTION, response['statusCode'], container_info)
42
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: atk_common
3
- Version: 1.36.0
3
+ Version: 1.37.0
4
4
  Summary: ATK common methods
5
5
  Home-page: https://github.com/pypa/atk_common
6
6
  Author: Roger
@@ -1,11 +1,11 @@
1
- atk_common/__init__.py,sha256=DVQ5Q9hlTq9spM4OU5omLll7w5KQmbPBMiX6wUH0r2c,1674
1
+ atk_common/__init__.py,sha256=csSn6oq7DBZQ7-Ji9rAgNbWv5MfdEX118REj4W_6TBM,1725
2
2
  atk_common/datetime_utils.py,sha256=3OIzPCt7W3vA4HvjnlfV0KJjRAjXuTaJ_QOa-cCMNns,2044
3
3
  atk_common/db_utils.py,sha256=odUtXcS7Mumw5eGyVyVimL_U_lP7TqMX9v8nWO5nMvg,902
4
4
  atk_common/docker_utils.py,sha256=nkUhp2OhwJsm41JDujHDY-JxQfdDjy91duprH59Esfk,2084
5
5
  atk_common/env_utils.py,sha256=66v-S0vlkJNaun6ay1XcOGRtYJb4Ce4odJsWxuaHsQc,373
6
- atk_common/error_utils.py,sha256=_7y_0lPln1dKNMWDcENO6T9G2kVhl-Kr2z8eHulMaVo,2987
6
+ atk_common/error_utils.py,sha256=6sEWTmqIoz4gk_GL3I6QeyMfRYz1iYdptMn-bCYLbLQ,2636
7
7
  atk_common/file_utils.py,sha256=UDwcRquO9IrqRrlUM0t-_g4R1-FKt8ZqQinSEqXOAk8,112
8
- atk_common/http_utils.py,sha256=M1Qz2Cus3Ek8nUOqraT-30GKSj7nkAvJx2f7rnpX5Pk,656
8
+ atk_common/http_utils.py,sha256=ujGHxLbB5-5HgdhkMWgxochdF-j1Dd9ZCpBh1Hx1LDk,1963
9
9
  atk_common/log_utils.py,sha256=k7VaknmSGvHQV6-eznltNUa3BOAywjFHkhVzDT1P0Hs,496
10
10
  atk_common/mq_utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  atk_common/rabbitmq_consumer.py,sha256=4MhuwZs47Jt1fX4sUxr1MKRe7o2QRbPe9_utXEsa8QE,1907
@@ -42,7 +42,7 @@ atk_common/enums/sensor_type_enum.py,sha256=UBa3LPyGTKgEJV578CqFlwXjnlXqVlybrvzd
42
42
  atk_common/enums/speed_control_status_enum.py,sha256=qpURh0K1L1tSpbrzVnckoe4hUn1illIkbo7k4mLfzIM,182
43
43
  atk_common/enums/speed_control_status_type_enum.py,sha256=qpURh0K1L1tSpbrzVnckoe4hUn1illIkbo7k4mLfzIM,182
44
44
  atk_common/enums/violation_type_enum.py,sha256=01qTHOj-O8bOc-nwIHVnxLosm4cusD_YuqXM3ZsiRRk,86
45
- atk_common-1.36.0.dist-info/licenses/license.txt,sha256=_0O6fWM00-wTurDjnZhUP_N5QiwGhItaQZqHq5eqadA,1063
45
+ atk_common-1.37.0.dist-info/licenses/license.txt,sha256=_0O6fWM00-wTurDjnZhUP_N5QiwGhItaQZqHq5eqadA,1063
46
46
  atk_package/__init__.py,sha256=EceDa352WFHTdC_LxYANXf_TS9pGzK3MCx87bwAKTvg,811
47
47
  atk_package/datetime_utils.py,sha256=qsVF7l90P1-xukG2tV_jLqG9J_Yfl5wTpyfrdPBlyMo,239
48
48
  atk_package/env_utils.py,sha256=bXOrxM3fZUslqfmZt75iphbEJHbG4riJa8XOVzPwIII,313
@@ -55,7 +55,7 @@ atk_package/enums/__init__.py,sha256=EtUr_--MQj1Rc_R0sF_ELXIThmhpfmhDWq3YaK9oQMk
55
55
  atk_package/enums/command_status_enum.py,sha256=M2Nln27a_DbzI07-gfytWQk2X087JhkU6Fmard5qVHs,127
56
56
  atk_package/enums/speed_control_status_enum.py,sha256=qpURh0K1L1tSpbrzVnckoe4hUn1illIkbo7k4mLfzIM,182
57
57
  shared_python_atk_enforcement/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
58
- atk_common-1.36.0.dist-info/METADATA,sha256=ZiRPVbhqdI159JVsMURwc-P4lc8dQut-q3ZTmzunXJc,1464
59
- atk_common-1.36.0.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
60
- atk_common-1.36.0.dist-info/top_level.txt,sha256=4CwRjkLnheIdI4jQwc4tK3dbRc58WqUmoqjkdDTWlME,41
61
- atk_common-1.36.0.dist-info/RECORD,,
58
+ atk_common-1.37.0.dist-info/METADATA,sha256=XO-0ZTatJq7tuXy7HsawtmpNz80kpy2PjP7y7mJGeqE,1464
59
+ atk_common-1.37.0.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
60
+ atk_common-1.37.0.dist-info/top_level.txt,sha256=4CwRjkLnheIdI4jQwc4tK3dbRc58WqUmoqjkdDTWlME,41
61
+ atk_common-1.37.0.dist-info/RECORD,,