atk-common 1.8.0__tar.gz → 1.10.0__tar.gz

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.
Files changed (36) hide show
  1. {atk_common-1.8.0 → atk_common-1.10.0}/PKG-INFO +1 -1
  2. {atk_common-1.8.0 → atk_common-1.10.0}/setup.py +1 -1
  3. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common/__init__.py +8 -5
  4. atk_common-1.10.0/src/atk_common/enums/__init__.py +14 -0
  5. atk_common-1.10.0/src/atk_common/enums/api_error_type_enum.py +5 -0
  6. atk_common-1.10.0/src/atk_common/enums/http_status_enum.py +8 -0
  7. atk_common-1.10.0/src/atk_common/enums/response_status_enum.py +6 -0
  8. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common/error_utils.py +8 -5
  9. atk_common-1.10.0/src/atk_common/http_utils.py +21 -0
  10. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common/log_utils.py +2 -1
  11. atk_common-1.10.0/src/atk_common/mq_utils.py +0 -0
  12. atk_common-1.10.0/src/atk_common/response_utils.py +11 -0
  13. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common.egg-info/PKG-INFO +1 -1
  14. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common.egg-info/SOURCES.txt +5 -0
  15. atk_common-1.10.0/src/shared_python_atk_enforcement/__init__.py +0 -0
  16. {atk_common-1.8.0 → atk_common-1.10.0}/tests/test_http_utils.py +1 -1
  17. atk_common-1.8.0/src/atk_common/enums/__init__.py +0 -8
  18. atk_common-1.8.0/src/atk_common/http_utils.py +0 -23
  19. atk_common-1.8.0/src/atk_common/response_utils.py +0 -6
  20. {atk_common-1.8.0 → atk_common-1.10.0}/README.md +0 -0
  21. {atk_common-1.8.0 → atk_common-1.10.0}/license.txt +0 -0
  22. {atk_common-1.8.0 → atk_common-1.10.0}/pyproject.toml +0 -0
  23. {atk_common-1.8.0 → atk_common-1.10.0}/setup.cfg +0 -0
  24. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common/datetime_utils.py +0 -0
  25. /atk_common-1.8.0/src/shared_python_atk_enforcement/__init__.py → /atk_common-1.10.0/src/atk_common/db_utils.py +0 -0
  26. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common/docker_utils.py +0 -0
  27. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common/enums/command_status_enum.py +0 -0
  28. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common/enums/speed_control_status_enum.py +0 -0
  29. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common/env_utils.py +0 -0
  30. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common/rabbitmq_consumer.py +0 -0
  31. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common.egg-info/dependency_links.txt +0 -0
  32. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common.egg-info/requires.txt +0 -0
  33. {atk_common-1.8.0 → atk_common-1.10.0}/src/atk_common.egg-info/top_level.txt +0 -0
  34. {atk_common-1.8.0 → atk_common-1.10.0}/tests/test_docker_utils.py +0 -0
  35. {atk_common-1.8.0 → atk_common-1.10.0}/tests/test_error_utils.py +0 -0
  36. {atk_common-1.8.0 → atk_common-1.10.0}/tests/test_log_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: atk_common
3
- Version: 1.8.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
@@ -36,7 +36,7 @@ setup(
36
36
  # For a discussion on single-sourcing the version across setup.py and the
37
37
  # project code, see
38
38
  # https://packaging.python.org/guides/single-sourcing-package-version/
39
- version="1.8.0", # Required
39
+ version="1.10.0", # Required
40
40
  # This is a one-line description or tagline of what your project does. This
41
41
  # corresponds to the "Summary" metadata field:
42
42
  # https://packaging.python.org/specifications/core-metadata/#summary
@@ -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
  ]
@@ -0,0 +1,14 @@
1
+ # __init__.py
2
+ from atk_common.enums.command_status_enum import CommandStatusType
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
7
+
8
+ __all__ = [
9
+ 'CommandStatusType',
10
+ 'SpeedControlStatusType',
11
+ 'ApiErrorType',
12
+ 'ResponseStatus',
13
+ 'HttpStatus',
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
@@ -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
@@ -0,0 +1,21 @@
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
4
+ from atk_common.enums.http_status_enum import HttpStatus
5
+ from atk_common.env_utils import get_env_value
6
+
7
+ def is_http_status_ok(status_code):
8
+ return status_code >= HttpStatus.OK.value and status_code < HttpStatus.REDIRECT.value
9
+
10
+ def is_http_status_internal(status_code):
11
+ return status_code >= HttpStatus.INTERNAL.value
12
+
13
+ def get_test_response(docker_container_data, component):
14
+ data = {}
15
+ data['utcDateTime'] = get_utc_date_time()
16
+ if docker_container_data is None:
17
+ data['containerData'] = None
18
+ data['component'] = component
19
+ else:
20
+ data['containerData'] = docker_container_data
21
+ return data
@@ -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:
File without changes
@@ -0,0 +1,11 @@
1
+ from atk_common.enums.response_status_enum import ResponseStatus
2
+
3
+ def create_response(status, status_code, response_msg):
4
+ data = {}
5
+ data['status'] = status
6
+ data['statusCode'] = status_code
7
+ data['responseMsg'] = response_msg
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.8.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
@@ -5,11 +5,13 @@ setup.cfg
5
5
  setup.py
6
6
  src/atk_common/__init__.py
7
7
  src/atk_common/datetime_utils.py
8
+ src/atk_common/db_utils.py
8
9
  src/atk_common/docker_utils.py
9
10
  src/atk_common/env_utils.py
10
11
  src/atk_common/error_utils.py
11
12
  src/atk_common/http_utils.py
12
13
  src/atk_common/log_utils.py
14
+ src/atk_common/mq_utils.py
13
15
  src/atk_common/rabbitmq_consumer.py
14
16
  src/atk_common/response_utils.py
15
17
  src/atk_common.egg-info/PKG-INFO
@@ -18,7 +20,10 @@ src/atk_common.egg-info/dependency_links.txt
18
20
  src/atk_common.egg-info/requires.txt
19
21
  src/atk_common.egg-info/top_level.txt
20
22
  src/atk_common/enums/__init__.py
23
+ src/atk_common/enums/api_error_type_enum.py
21
24
  src/atk_common/enums/command_status_enum.py
25
+ src/atk_common/enums/http_status_enum.py
26
+ src/atk_common/enums/response_status_enum.py
22
27
  src/atk_common/enums/speed_control_status_enum.py
23
28
  src/shared_python_atk_enforcement/__init__.py
24
29
  tests/test_docker_utils.py
@@ -5,7 +5,7 @@ from atk_common.http_utils import get_test_response
5
5
  class TestHttpUtils(unittest.TestCase):
6
6
 
7
7
  def test_get_test_response_none(self):
8
- resp_json = get_test_response()
8
+ resp_json = get_test_response(None, 'bo-config-db-api')
9
9
  self.assertIsNotNone(resp_json)
10
10
 
11
11
  if __name__ == "__main__":
@@ -1,8 +0,0 @@
1
- # __init__.py
2
- from atk_common.enums.command_status_enum import CommandStatusType
3
- from atk_common.enums.speed_control_status_enum import SpeedControlStatusType
4
-
5
- __all__ = [
6
- 'CommandStatusType',
7
- 'SpeedControlStatusType'
8
- ]
@@ -1,23 +0,0 @@
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
4
- from atk_common.env_utils import get_env_value
5
-
6
- def is_status_code_ok(status_code):
7
- return status_code >= 200 and status_code < 300
8
-
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
@@ -1,6 +0,0 @@
1
- def create_save_resp(status, status_code, response_msg):
2
- data = {}
3
- data['status'] = status
4
- data['statusCode'] = status_code
5
- data['responseMsg'] = response_msg
6
- return data
File without changes
File without changes
File without changes
File without changes