pilot-platform-common 1.0.2__tar.gz → 2.2.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 (57) hide show
  1. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/PKG-INFO +15 -3
  2. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/README.md +1 -1
  3. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/logging/logging.py +17 -1
  4. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/pilot_platform_common.egg-info/PKG-INFO +15 -3
  5. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/pyproject.toml +4 -2
  6. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/setup.py +2 -2
  7. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/test_logging.py +36 -13
  8. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/__init__.py +0 -0
  9. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/geid/__init__.py +0 -0
  10. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/geid/geid_client.py +0 -0
  11. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/jwt_handler/JWTHandler.py +0 -0
  12. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/jwt_handler/__init__.py +0 -0
  13. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/jwt_handler/jwt_handler_exception.py +0 -0
  14. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/jwt_handler/models.py +0 -0
  15. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/logging/__init__.py +0 -0
  16. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/logging/formatter.py +0 -0
  17. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/logging/logger.py +0 -0
  18. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/models/__init__.py +0 -0
  19. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/models/config_center_policy.py +0 -0
  20. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/models/service_id_generator.py +0 -0
  21. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/object_storage_adaptor/__init__.py +0 -0
  22. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/object_storage_adaptor/base_client.py +0 -0
  23. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/object_storage_adaptor/boto3_admin_client.py +0 -0
  24. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/object_storage_adaptor/boto3_client.py +0 -0
  25. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/object_storage_adaptor/minio_policy_client.py +0 -0
  26. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/permissions/__init__.py +0 -0
  27. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/permissions/exceptions.py +0 -0
  28. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/permissions/permissions.py +0 -0
  29. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/permissions/permissions_manager.py +0 -0
  30. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/permissions/schemas.py +0 -0
  31. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/project/__init__.py +0 -0
  32. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/project/project_client.py +0 -0
  33. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/project/project_exceptions.py +0 -0
  34. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/services/__init__.py +0 -0
  35. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/services/auth_client.py +0 -0
  36. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/vault/__init__.py +0 -0
  37. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/vault/vault_client.py +0 -0
  38. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/common/vault/vault_exception.py +0 -0
  39. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/pilot_platform_common.egg-info/SOURCES.txt +0 -0
  40. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/pilot_platform_common.egg-info/dependency_links.txt +0 -0
  41. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/pilot_platform_common.egg-info/requires.txt +0 -0
  42. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/pilot_platform_common.egg-info/top_level.txt +0 -0
  43. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/setup.cfg +0 -0
  44. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/__init__.py +0 -0
  45. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/conftest.py +0 -0
  46. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/fixtures/__init__.py +0 -0
  47. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/fixtures/fake.py +0 -0
  48. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/fixtures/metadata.py +0 -0
  49. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/permissions/__init__.py +0 -0
  50. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/permissions/test_auth_client.py +0 -0
  51. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/permissions/test_permissions.py +0 -0
  52. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/permissions/test_permissions_manager.py +0 -0
  53. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/test_formatter.py +0 -0
  54. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/test_geid_client.py +0 -0
  55. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/test_jwt_handler.py +0 -0
  56. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/test_project_client.py +0 -0
  57. {pilot-platform-common-1.0.2 → pilot_platform_common-2.2.0}/tests/test_vault_client.py +0 -0
@@ -1,18 +1,30 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pilot-platform-common
3
- Version: 1.0.2
3
+ Version: 2.2.0
4
4
  Summary: Generates entity ID and connects with Vault (secret engine) to retrieve credentials
5
5
  Author: Indoc Systems
6
6
  Author-email: etaylor@indocresearch.org
7
7
  Classifier: Programming Language :: Python :: 3
8
8
  Classifier: Operating System :: OS Independent
9
- Requires-Python: >=3.9
9
+ Requires-Python: >=3.10
10
10
  Description-Content-Type: text/markdown
11
+ Requires-Dist: python-dotenv>=0.19.1
12
+ Requires-Dist: httpx<0.27.0,>=0.23.0
13
+ Requires-Dist: redis<5.0.0,>=4.5.0
14
+ Requires-Dist: aioboto3==9.6.0
15
+ Requires-Dist: xmltodict==0.13.0
16
+ Requires-Dist: minio==7.1.8
17
+ Requires-Dist: python-json-logger==2.0.2
18
+ Requires-Dist: pyjwt==2.6.0
19
+ Requires-Dist: starlette<0.38.0,>=0.37.2
20
+ Requires-Dist: requests<2.32.0,>=2.26.0
21
+ Requires-Dist: cryptography==39.0.0
22
+ Requires-Dist: pydantic<3.0.0,>=2.7.1
11
23
 
12
24
  # common
13
25
 
14
26
  [![Run Tests](https://github.com/PilotDataPlatform/common/actions/workflows/run-tests.yml/badge.svg?branch=develop)](https://github.com/PilotDataPlatform/common/actions/workflows/run-tests.yml)
15
- [![Python](https://img.shields.io/badge/python-3.8-brightgreen.svg)](https://www.python.org/)
27
+ [![Python](https://img.shields.io/badge/python-3.10-brightgreen.svg)](https://www.python.org/)
16
28
  [![PyPI](https://img.shields.io/pypi/v/pilot-platform-common.svg)](https://pypi.org/project/pilot-platform-common/)
17
29
 
18
30
  Importable package responsible for cross-service tasks within the Pilot Platform (e.g. logging, Vault connection, etc.).
@@ -1,7 +1,7 @@
1
1
  # common
2
2
 
3
3
  [![Run Tests](https://github.com/PilotDataPlatform/common/actions/workflows/run-tests.yml/badge.svg?branch=develop)](https://github.com/PilotDataPlatform/common/actions/workflows/run-tests.yml)
4
- [![Python](https://img.shields.io/badge/python-3.8-brightgreen.svg)](https://www.python.org/)
4
+ [![Python](https://img.shields.io/badge/python-3.10-brightgreen.svg)](https://www.python.org/)
5
5
  [![PyPI](https://img.shields.io/pypi/v/pilot-platform-common.svg)](https://pypi.org/project/pilot-platform-common/)
6
6
 
7
7
  Importable package responsible for cross-service tasks within the Pilot Platform (e.g. logging, Vault connection, etc.).
@@ -10,6 +10,8 @@ from collections.abc import Mapping
10
10
  from typing import Any
11
11
  from typing import Union
12
12
 
13
+ from opentelemetry import trace
14
+
13
15
  AUDIT = logging.INFO + 5
14
16
 
15
17
 
@@ -19,12 +21,22 @@ class Logger(logging.Logger):
19
21
 
20
22
 
21
23
  class JsonFormatter(logging.Formatter):
22
- """Convert LogRecord to json string."""
24
+ """Convert LogRecord to JSON string with trace and span IDs."""
23
25
 
24
26
  def format(self, record: logging.LogRecord) -> str:
27
+ # Get the current span
28
+ span = trace.get_current_span()
29
+
30
+ # Extract trace ID and span ID
31
+ span_context = span.get_span_context()
32
+ trace_id = format(span_context.trace_id, '032x') if span_context.is_valid else None
33
+ span_id = format(span_context.span_id, '016x') if span_context.is_valid else None
34
+ trace_enabled = span_context.trace_flags.sampled if span_context.trace_flags is not None else False
35
+
25
36
  asctime = dt.datetime.fromtimestamp(record.created, tz=dt.timezone.utc).isoformat()
26
37
  level = record.levelname
27
38
  logger = record.name
39
+ location = f'{record.filename}:{record.lineno}'
28
40
  message = record.getMessage()
29
41
  exc_info = None
30
42
  if record.exc_info:
@@ -38,9 +50,13 @@ class JsonFormatter(logging.Formatter):
38
50
  'asctime': asctime,
39
51
  'level': level,
40
52
  'logger': logger,
53
+ 'location': location,
41
54
  'message': message,
42
55
  'exc_info': exc_info,
43
56
  'details': details,
57
+ 'trace_id': trace_id,
58
+ 'span_id': span_id,
59
+ 'trace_enabled': trace_enabled,
44
60
  }
45
61
  )
46
62
 
@@ -1,18 +1,30 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pilot-platform-common
3
- Version: 1.0.2
3
+ Version: 2.2.0
4
4
  Summary: Generates entity ID and connects with Vault (secret engine) to retrieve credentials
5
5
  Author: Indoc Systems
6
6
  Author-email: etaylor@indocresearch.org
7
7
  Classifier: Programming Language :: Python :: 3
8
8
  Classifier: Operating System :: OS Independent
9
- Requires-Python: >=3.9
9
+ Requires-Python: >=3.10
10
10
  Description-Content-Type: text/markdown
11
+ Requires-Dist: python-dotenv>=0.19.1
12
+ Requires-Dist: httpx<0.27.0,>=0.23.0
13
+ Requires-Dist: redis<5.0.0,>=4.5.0
14
+ Requires-Dist: aioboto3==9.6.0
15
+ Requires-Dist: xmltodict==0.13.0
16
+ Requires-Dist: minio==7.1.8
17
+ Requires-Dist: python-json-logger==2.0.2
18
+ Requires-Dist: pyjwt==2.6.0
19
+ Requires-Dist: starlette<0.38.0,>=0.37.2
20
+ Requires-Dist: requests<2.32.0,>=2.26.0
21
+ Requires-Dist: cryptography==39.0.0
22
+ Requires-Dist: pydantic<3.0.0,>=2.7.1
11
23
 
12
24
  # common
13
25
 
14
26
  [![Run Tests](https://github.com/PilotDataPlatform/common/actions/workflows/run-tests.yml/badge.svg?branch=develop)](https://github.com/PilotDataPlatform/common/actions/workflows/run-tests.yml)
15
- [![Python](https://img.shields.io/badge/python-3.8-brightgreen.svg)](https://www.python.org/)
27
+ [![Python](https://img.shields.io/badge/python-3.10-brightgreen.svg)](https://www.python.org/)
16
28
  [![PyPI](https://img.shields.io/pypi/v/pilot-platform-common.svg)](https://pypi.org/project/pilot-platform-common/)
17
29
 
18
30
  Importable package responsible for cross-service tasks within the Pilot Platform (e.g. logging, Vault connection, etc.).
@@ -1,11 +1,11 @@
1
1
  [tool.poetry]
2
2
  name = "common"
3
- version = "1.0.2"
3
+ version = "2.2.0"
4
4
  description = ""
5
5
  authors = ["Indoc Systems"]
6
6
 
7
7
  [tool.poetry.dependencies]
8
- python = "^3.9"
8
+ python = "^3.10"
9
9
  python-dotenv = ">=0.19.1"
10
10
  python-json-logger = ">= 0.1.11, <= 2.02"
11
11
  aioboto3 = "^9.6.0"
@@ -18,6 +18,8 @@ starlette = ">=0.37.2,<0.38.0"
18
18
  cryptography = "39.0.0"
19
19
  pydantic = "^2.7.1"
20
20
  requests = ">=2.26.0,<2.32.0"
21
+ opentelemetry-instrumentation-fastapi = "^0.39b0"
22
+ opentelemetry-sdk = "1.18.0"
21
23
 
22
24
  [tool.poetry.dev-dependencies]
23
25
  pytest = "7.2.1"
@@ -11,7 +11,7 @@ long_description = (this_directory / 'README.md').read_text()
11
11
 
12
12
  setuptools.setup(
13
13
  name='pilot-platform-common',
14
- version='1.0.2',
14
+ version='2.2.0',
15
15
  author='Indoc Systems',
16
16
  author_email='etaylor@indocresearch.org',
17
17
  description='Generates entity ID and connects with Vault (secret engine) to retrieve credentials',
@@ -22,7 +22,7 @@ setuptools.setup(
22
22
  'Programming Language :: Python :: 3',
23
23
  'Operating System :: OS Independent',
24
24
  ],
25
- python_requires='>=3.9',
25
+ python_requires='>=3.10',
26
26
  install_requires=[
27
27
  'python-dotenv>=0.19.1',
28
28
  'httpx>=0.23.0,<0.27.0',
@@ -8,6 +8,11 @@ import logging
8
8
  from logging import LogRecord
9
9
  from logging import getLevelName
10
10
 
11
+ from opentelemetry import trace
12
+ from opentelemetry.sdk.trace import TracerProvider
13
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor
14
+ from opentelemetry.sdk.trace.export import ConsoleSpanExporter
15
+
11
16
  from common.logging.logging import AUDIT
12
17
  from common.logging.logging import JsonFormatter
13
18
  from common.logging.logging import Logger
@@ -17,6 +22,12 @@ from common.logging.logging import extend_logger_class
17
22
 
18
23
  class TestJsonFormatter:
19
24
  def test_format_converts_log_record_into_expected_json_string(self, fake):
25
+ provider = TracerProvider()
26
+ processor = BatchSpanProcessor(ConsoleSpanExporter())
27
+ provider.add_span_processor(processor)
28
+ trace.set_tracer_provider(provider)
29
+ tracer = trace.get_tracer('test.format.logging')
30
+
20
31
  logger = fake.word()
21
32
  level = fake.pyint(0, 5) * 10
22
33
  message = fake.word()
@@ -24,20 +35,32 @@ class TestJsonFormatter:
24
35
  exception = Exception(exception_message)
25
36
  exc_info = (type(exception), exception, exception.__traceback__)
26
37
  details = fake.pydict(allowed_types=(str, int, float, bool))
27
- record = LogRecord(logger, level, '', 0, message, details, exc_info)
38
+ record = LogRecord(logger, level, 'test.py', 0, message, details, exc_info)
28
39
  asctime = dt.datetime.fromtimestamp(record.created, tz=dt.timezone.utc).isoformat()
29
- expected_string = json.dumps(
30
- {
31
- 'asctime': asctime,
32
- 'level': getLevelName(level),
33
- 'logger': logger,
34
- 'message': message,
35
- 'exc_info': f'Exception: {exception_message}',
36
- 'details': details,
37
- }
38
- )
39
-
40
- received_string = JsonFormatter().format(record)
40
+ with tracer.start_as_current_span('test-log-record-format') as span:
41
+ span_context = span.get_span_context()
42
+ trace_id = format(span_context.trace_id, '032x') if span_context.is_valid else None
43
+ span_id = format(span_context.span_id, '016x') if span_context.is_valid else None
44
+ trace_enabled = span_context.trace_flags.sampled if span_context.trace_flags is not None else False
45
+ expected_string = json.dumps(
46
+ {
47
+ 'asctime': asctime,
48
+ 'level': getLevelName(level),
49
+ 'logger': logger,
50
+ 'location': 'test.py:0',
51
+ 'message': message,
52
+ 'exc_info': f'Exception: {exception_message}',
53
+ 'details': details,
54
+ 'trace_id': trace_id,
55
+ 'span_id': span_id,
56
+ 'trace_enabled': trace_enabled,
57
+ }
58
+ )
59
+ received_string = JsonFormatter().format(record)
60
+ trace.get_tracer_provider().shutdown()
61
+ # Normalize newlines by replacing them with `\\n` in both strings for comparison
62
+ expected_string = expected_string.replace('\n', '\\n')
63
+ received_string = received_string.replace('\n', '\\n')
41
64
 
42
65
  assert received_string == expected_string
43
66