py-juxlib 0.3.1__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.
- juxlib/__init__.py +43 -0
- juxlib/api/__init__.py +39 -0
- juxlib/api/client.py +178 -0
- juxlib/api/models.py +92 -0
- juxlib/config/__init__.py +53 -0
- juxlib/config/manager.py +481 -0
- juxlib/config/schema.py +172 -0
- juxlib/errors/__init__.py +104 -0
- juxlib/errors/codes.py +76 -0
- juxlib/errors/exceptions.py +721 -0
- juxlib/metadata/__init__.py +52 -0
- juxlib/metadata/ci.py +239 -0
- juxlib/metadata/detection.py +113 -0
- juxlib/metadata/git.py +163 -0
- juxlib/metadata/models.py +157 -0
- juxlib/metadata/project.py +133 -0
- juxlib/py.typed +0 -0
- juxlib/signing/__init__.py +68 -0
- juxlib/signing/keys.py +165 -0
- juxlib/signing/signer.py +121 -0
- juxlib/signing/verifier.py +181 -0
- juxlib/signing/xml.py +154 -0
- juxlib/storage/__init__.py +46 -0
- juxlib/storage/filesystem.py +405 -0
- py_juxlib-0.3.1.dist-info/METADATA +177 -0
- py_juxlib-0.3.1.dist-info/RECORD +28 -0
- py_juxlib-0.3.1.dist-info/WHEEL +4 -0
- py_juxlib-0.3.1.dist-info/licenses/LICENSE +190 -0
juxlib/__init__.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2026 Georges Martin <jrjsmrtn@gmail.com>
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
py-juxlib: Shared Python library for Jux tools ecosystem.
|
|
6
|
+
|
|
7
|
+
This library provides common functionality for Jux client tools:
|
|
8
|
+
|
|
9
|
+
- Environment metadata detection (Git, CI/CD, runtime)
|
|
10
|
+
- XML digital signatures (XMLDSig signing and verification)
|
|
11
|
+
- API client for Jux OpenAPI servers
|
|
12
|
+
- Configuration management with multi-source loading
|
|
13
|
+
- Local filesystem storage with offline queue
|
|
14
|
+
- User-friendly error handling framework
|
|
15
|
+
|
|
16
|
+
Example usage:
|
|
17
|
+
|
|
18
|
+
>>> from juxlib.metadata import capture_metadata
|
|
19
|
+
>>> metadata = capture_metadata()
|
|
20
|
+
>>> print(f"Project: {metadata.project_name}")
|
|
21
|
+
|
|
22
|
+
>>> from juxlib.signing import sign_xml, load_private_key
|
|
23
|
+
>>> key = load_private_key("~/.ssh/jux/dev-key.pem")
|
|
24
|
+
>>> signed_tree = sign_xml(tree, key)
|
|
25
|
+
|
|
26
|
+
>>> from juxlib.api import JuxAPIClient
|
|
27
|
+
>>> client = JuxAPIClient(api_url="https://jux.example.com")
|
|
28
|
+
>>> response = client.publish_report(signed_xml)
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
from importlib.metadata import metadata
|
|
32
|
+
|
|
33
|
+
_meta = metadata("py-juxlib")
|
|
34
|
+
__version__ = _meta["Version"]
|
|
35
|
+
__author__ = _meta["Author-email"].split("<")[0].strip()
|
|
36
|
+
__email__ = _meta["Author-email"].split("<")[1].rstrip(">")
|
|
37
|
+
|
|
38
|
+
# Public API will be populated as modules are implemented
|
|
39
|
+
__all__ = [
|
|
40
|
+
"__author__",
|
|
41
|
+
"__email__",
|
|
42
|
+
"__version__",
|
|
43
|
+
]
|
juxlib/api/__init__.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2026 Georges Martin <jrjsmrtn@gmail.com>
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
HTTP client for Jux OpenAPI servers.
|
|
6
|
+
|
|
7
|
+
This module provides a resilient HTTP client for publishing signed JUnit XML
|
|
8
|
+
reports to Jux servers, with automatic retry logic and authentication handling.
|
|
9
|
+
|
|
10
|
+
Features:
|
|
11
|
+
- Bearer token authentication for remote servers
|
|
12
|
+
- Localhost bypass (no auth required for local development)
|
|
13
|
+
- Exponential backoff retry on server errors
|
|
14
|
+
- Pydantic models for type-safe response handling
|
|
15
|
+
|
|
16
|
+
Example usage:
|
|
17
|
+
|
|
18
|
+
>>> from juxlib.api import JuxAPIClient
|
|
19
|
+
>>>
|
|
20
|
+
>>> client = JuxAPIClient(
|
|
21
|
+
... api_url="https://jux.example.com",
|
|
22
|
+
... bearer_token="your-token"
|
|
23
|
+
... )
|
|
24
|
+
>>>
|
|
25
|
+
>>> with open("junit-report-signed.xml") as f:
|
|
26
|
+
... response = client.publish_report(f.read())
|
|
27
|
+
>>>
|
|
28
|
+
>>> print(f"Test run ID: {response.test_run_id}")
|
|
29
|
+
>>> print(f"Success rate: {response.success_rate}%")
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
from juxlib.api.client import JuxAPIClient
|
|
33
|
+
from juxlib.api.models import PublishResponse, TestRun
|
|
34
|
+
|
|
35
|
+
__all__: list[str] = [
|
|
36
|
+
"JuxAPIClient",
|
|
37
|
+
"PublishResponse",
|
|
38
|
+
"TestRun",
|
|
39
|
+
]
|
juxlib/api/client.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2026 Georges Martin <jrjsmrtn@gmail.com>
|
|
3
|
+
|
|
4
|
+
"""HTTP client for Jux REST API v1.0.0.
|
|
5
|
+
|
|
6
|
+
This module provides a resilient HTTP client for publishing signed JUnit XML
|
|
7
|
+
reports to Jux servers, with automatic retry logic and authentication handling.
|
|
8
|
+
|
|
9
|
+
API Specification: Jux API v1.0.0
|
|
10
|
+
Endpoint: POST /api/v1/junit/submit
|
|
11
|
+
Content-Type: application/xml
|
|
12
|
+
Authentication: Bearer token (remote) or localhost bypass
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import requests
|
|
16
|
+
from requests.adapters import HTTPAdapter
|
|
17
|
+
from urllib3.util.retry import Retry
|
|
18
|
+
|
|
19
|
+
from juxlib.api.models import PublishResponse
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class JuxAPIClient:
|
|
23
|
+
"""HTTP client for Jux REST API v1.0.0.
|
|
24
|
+
|
|
25
|
+
Simple client that POSTs signed JUnit XML to the Jux API Server.
|
|
26
|
+
The server auto-extracts metadata from XML <properties> elements.
|
|
27
|
+
|
|
28
|
+
Features:
|
|
29
|
+
- Bearer token authentication for remote servers
|
|
30
|
+
- Localhost bypass (no auth for 127.0.0.1, ::1, localhost)
|
|
31
|
+
- Exponential backoff retry on server errors (500, 502, 503, 504)
|
|
32
|
+
- Configurable timeout and max retries
|
|
33
|
+
- Connection pooling with session management
|
|
34
|
+
|
|
35
|
+
Example:
|
|
36
|
+
>>> client = JuxAPIClient(
|
|
37
|
+
... api_url="https://jux.example.com/api/v1",
|
|
38
|
+
... bearer_token="your-api-token"
|
|
39
|
+
... )
|
|
40
|
+
>>> response = client.publish_report(signed_xml)
|
|
41
|
+
>>> print(response.test_run_id)
|
|
42
|
+
550e8400-e29b-41d4-a716-446655440000
|
|
43
|
+
|
|
44
|
+
Localhost Example (no auth):
|
|
45
|
+
>>> client = JuxAPIClient(api_url="http://localhost:4000/api/v1")
|
|
46
|
+
>>> response = client.publish_report(signed_xml)
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
def __init__(
|
|
50
|
+
self,
|
|
51
|
+
api_url: str,
|
|
52
|
+
bearer_token: str | None = None,
|
|
53
|
+
timeout: int = 30,
|
|
54
|
+
max_retries: int = 3,
|
|
55
|
+
):
|
|
56
|
+
"""Initialize Jux API client.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
api_url: Base API URL (e.g., https://jux.example.com/api/v1)
|
|
60
|
+
bearer_token: Optional Bearer token for remote authentication.
|
|
61
|
+
Not required for localhost (127.0.0.1, ::1, localhost).
|
|
62
|
+
timeout: Request timeout in seconds (default: 30)
|
|
63
|
+
max_retries: Maximum retry attempts for transient failures (default: 3)
|
|
64
|
+
|
|
65
|
+
Example:
|
|
66
|
+
>>> # Remote server with authentication
|
|
67
|
+
>>> client = JuxAPIClient(
|
|
68
|
+
... api_url="https://jux.example.com/api/v1",
|
|
69
|
+
... bearer_token="your-token-here"
|
|
70
|
+
... )
|
|
71
|
+
|
|
72
|
+
>>> # Localhost (no authentication)
|
|
73
|
+
>>> client = JuxAPIClient(api_url="http://localhost:4000/api/v1")
|
|
74
|
+
"""
|
|
75
|
+
self.api_url = api_url.rstrip("/")
|
|
76
|
+
self.timeout = timeout
|
|
77
|
+
|
|
78
|
+
# Session with retry logic for transient failures
|
|
79
|
+
self.session = requests.Session()
|
|
80
|
+
retry_strategy = Retry(
|
|
81
|
+
total=max_retries,
|
|
82
|
+
backoff_factor=1, # 1s, 2s, 4s exponential backoff
|
|
83
|
+
status_forcelist=[500, 502, 503, 504], # Retry on server errors
|
|
84
|
+
allowed_methods=["POST"],
|
|
85
|
+
)
|
|
86
|
+
adapter = HTTPAdapter(max_retries=retry_strategy)
|
|
87
|
+
self.session.mount("http://", adapter)
|
|
88
|
+
self.session.mount("https://", adapter)
|
|
89
|
+
|
|
90
|
+
# Set Content-Type for XML (required by Jux API v1.0.0)
|
|
91
|
+
self.session.headers["Content-Type"] = "application/xml"
|
|
92
|
+
|
|
93
|
+
# Optional Bearer token authentication
|
|
94
|
+
if bearer_token:
|
|
95
|
+
self.session.headers["Authorization"] = f"Bearer {bearer_token}"
|
|
96
|
+
|
|
97
|
+
def publish_report(self, signed_xml: str) -> PublishResponse:
|
|
98
|
+
"""Publish signed JUnit XML to Jux API v1.0.0.
|
|
99
|
+
|
|
100
|
+
The server auto-extracts metadata from XML <properties> elements,
|
|
101
|
+
computes canonical hash, and detects signature algorithm from XMLDsig.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
signed_xml: Complete signed JUnit XML document with:
|
|
105
|
+
- XMLDsig signature (if signing enabled)
|
|
106
|
+
- Metadata in <properties> elements (project, git:*, ci:*, jux:*)
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
PublishResponse with nested test_run containing ID and statistics
|
|
110
|
+
|
|
111
|
+
Raises:
|
|
112
|
+
requests.exceptions.RequestException: Network errors, timeouts
|
|
113
|
+
requests.exceptions.HTTPError: HTTP 4xx/5xx errors with details
|
|
114
|
+
|
|
115
|
+
Example:
|
|
116
|
+
>>> response = client.publish_report(signed_xml)
|
|
117
|
+
>>> print(f"Test run created: {response.test_run_id}")
|
|
118
|
+
>>> print(f"Success rate: {response.success_rate}%")
|
|
119
|
+
"""
|
|
120
|
+
try:
|
|
121
|
+
response = self.session.post(
|
|
122
|
+
f"{self.api_url}/junit/submit",
|
|
123
|
+
data=signed_xml.encode("utf-8"),
|
|
124
|
+
timeout=self.timeout,
|
|
125
|
+
)
|
|
126
|
+
response.raise_for_status()
|
|
127
|
+
|
|
128
|
+
# Parse JSON response
|
|
129
|
+
data = response.json()
|
|
130
|
+
return PublishResponse(**data)
|
|
131
|
+
|
|
132
|
+
except requests.exceptions.Timeout as e:
|
|
133
|
+
raise requests.exceptions.RequestException(
|
|
134
|
+
f"Request timeout after {self.timeout}s"
|
|
135
|
+
) from e
|
|
136
|
+
|
|
137
|
+
except requests.exceptions.HTTPError as e:
|
|
138
|
+
# Enhanced error message with server details
|
|
139
|
+
if e.response is not None:
|
|
140
|
+
try:
|
|
141
|
+
error_data = e.response.json()
|
|
142
|
+
error_msg = error_data.get("error", str(e))
|
|
143
|
+
details = error_data.get("details", {})
|
|
144
|
+
raise requests.exceptions.HTTPError(
|
|
145
|
+
f"{e.response.status_code} {error_msg}: {details}"
|
|
146
|
+
) from e
|
|
147
|
+
except ValueError:
|
|
148
|
+
# Response not JSON, re-raise original
|
|
149
|
+
pass
|
|
150
|
+
raise
|
|
151
|
+
|
|
152
|
+
def close(self) -> None:
|
|
153
|
+
"""Close the HTTP session and release resources.
|
|
154
|
+
|
|
155
|
+
Call this method when you're done using the client to free up
|
|
156
|
+
connection pool resources.
|
|
157
|
+
|
|
158
|
+
Example:
|
|
159
|
+
>>> client = JuxAPIClient(api_url="http://localhost:4000/api/v1")
|
|
160
|
+
>>> try:
|
|
161
|
+
... response = client.publish_report(signed_xml)
|
|
162
|
+
... finally:
|
|
163
|
+
... client.close()
|
|
164
|
+
"""
|
|
165
|
+
self.session.close()
|
|
166
|
+
|
|
167
|
+
def __enter__(self) -> "JuxAPIClient":
|
|
168
|
+
"""Context manager entry."""
|
|
169
|
+
return self
|
|
170
|
+
|
|
171
|
+
def __exit__(
|
|
172
|
+
self,
|
|
173
|
+
exc_type: type[BaseException] | None,
|
|
174
|
+
exc_val: BaseException | None,
|
|
175
|
+
exc_tb: object,
|
|
176
|
+
) -> None:
|
|
177
|
+
"""Context manager exit - closes the session."""
|
|
178
|
+
self.close()
|
juxlib/api/models.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2026 Georges Martin <jrjsmrtn@gmail.com>
|
|
3
|
+
|
|
4
|
+
"""Pydantic models for Jux API v1.0.0 responses.
|
|
5
|
+
|
|
6
|
+
This module provides type-safe data models for the Jux REST API,
|
|
7
|
+
enabling validation and IDE support for API response handling.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from pydantic import BaseModel
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TestRun(BaseModel):
|
|
14
|
+
"""Test run summary from Jux API v1.0.0 query endpoints.
|
|
15
|
+
|
|
16
|
+
Represents the test run data returned by /test_runs endpoints.
|
|
17
|
+
|
|
18
|
+
Attributes:
|
|
19
|
+
id: UUID of the test run
|
|
20
|
+
project: Project name
|
|
21
|
+
branch: Git branch name (nullable)
|
|
22
|
+
commit_sha: Git commit SHA (nullable)
|
|
23
|
+
total_tests: Total number of tests in the run
|
|
24
|
+
failures: Number of failed tests
|
|
25
|
+
errors: Number of tests with errors
|
|
26
|
+
skipped: Number of skipped tests
|
|
27
|
+
success_rate: Success rate percentage (0-100)
|
|
28
|
+
inserted_at: ISO 8601 timestamp of test run creation
|
|
29
|
+
|
|
30
|
+
Example:
|
|
31
|
+
>>> test_run = TestRun(
|
|
32
|
+
... id="550e8400-e29b-41d4-a716-446655440000",
|
|
33
|
+
... project="my-app",
|
|
34
|
+
... total_tests=30,
|
|
35
|
+
... failures=2,
|
|
36
|
+
... errors=0,
|
|
37
|
+
... skipped=1,
|
|
38
|
+
... success_rate=90.0,
|
|
39
|
+
... inserted_at="2026-01-08T12:00:00.000000Z"
|
|
40
|
+
... )
|
|
41
|
+
>>> print(test_run.success_rate)
|
|
42
|
+
90.0
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
id: str
|
|
46
|
+
project: str
|
|
47
|
+
branch: str | None = None
|
|
48
|
+
commit_sha: str | None = None
|
|
49
|
+
total_tests: int
|
|
50
|
+
failures: int
|
|
51
|
+
errors: int
|
|
52
|
+
skipped: int
|
|
53
|
+
success_rate: float
|
|
54
|
+
inserted_at: str
|
|
55
|
+
tags: list[str] | None = None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class PublishResponse(BaseModel):
|
|
59
|
+
"""Response from Jux API v1.0.0 /junit/submit endpoint (jux-openapi SubmitResponse).
|
|
60
|
+
|
|
61
|
+
Represents the complete response when publishing a JUnit XML report.
|
|
62
|
+
|
|
63
|
+
Attributes:
|
|
64
|
+
test_run_id: UUID of the created test run
|
|
65
|
+
message: Human-readable success message
|
|
66
|
+
test_count: Total number of tests in the run
|
|
67
|
+
failure_count: Number of failed tests
|
|
68
|
+
error_count: Number of tests with errors
|
|
69
|
+
skipped_count: Number of skipped tests
|
|
70
|
+
success_rate: Success rate percentage (0-100, optional)
|
|
71
|
+
|
|
72
|
+
Example:
|
|
73
|
+
>>> response = PublishResponse(
|
|
74
|
+
... test_run_id="550e8400-e29b-41d4-a716-446655440000",
|
|
75
|
+
... message="Test results submitted successfully",
|
|
76
|
+
... test_count=30,
|
|
77
|
+
... failure_count=2,
|
|
78
|
+
... error_count=0,
|
|
79
|
+
... skipped_count=1,
|
|
80
|
+
... success_rate=90.0,
|
|
81
|
+
... )
|
|
82
|
+
>>> print(response.test_run_id)
|
|
83
|
+
550e8400-e29b-41d4-a716-446655440000
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
test_run_id: str
|
|
87
|
+
message: str
|
|
88
|
+
test_count: int
|
|
89
|
+
failure_count: int
|
|
90
|
+
error_count: int
|
|
91
|
+
skipped_count: int
|
|
92
|
+
success_rate: float | None = None
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# SPDX-FileCopyrightText: 2026 Georges Martin <jrjsmrtn@gmail.com>
|
|
3
|
+
|
|
4
|
+
"""Configuration management with multi-source loading.
|
|
5
|
+
|
|
6
|
+
This module provides a flexible configuration system that loads settings
|
|
7
|
+
from multiple sources with clear precedence rules:
|
|
8
|
+
|
|
9
|
+
1. Explicit values (highest priority)
|
|
10
|
+
2. Command-line arguments
|
|
11
|
+
3. Environment variables (JUX_* prefix)
|
|
12
|
+
4. Configuration files (jux.ini, pyproject.toml)
|
|
13
|
+
5. Default values (lowest priority)
|
|
14
|
+
|
|
15
|
+
Features:
|
|
16
|
+
- Schema-based validation with type coercion
|
|
17
|
+
- Source tracking for debugging
|
|
18
|
+
- Dependency checking between settings
|
|
19
|
+
- XDG-compliant file locations
|
|
20
|
+
|
|
21
|
+
Example usage:
|
|
22
|
+
|
|
23
|
+
>>> from juxlib.config import ConfigurationManager, StorageMode
|
|
24
|
+
>>>
|
|
25
|
+
>>> config = ConfigurationManager()
|
|
26
|
+
>>> config.load_from_env()
|
|
27
|
+
>>> config.load_from_file(Path("~/.config/jux/config.ini"))
|
|
28
|
+
>>>
|
|
29
|
+
>>> api_url = config.get("jux_api_url")
|
|
30
|
+
>>> storage_mode = config.get("jux_storage_mode") # Returns StorageMode enum
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
from .manager import (
|
|
34
|
+
ConfigurationManager,
|
|
35
|
+
ConfigValidationError,
|
|
36
|
+
get_default_config_path,
|
|
37
|
+
get_xdg_config_home,
|
|
38
|
+
get_xdg_data_home,
|
|
39
|
+
)
|
|
40
|
+
from .schema import ConfigSchema, StorageMode
|
|
41
|
+
|
|
42
|
+
__all__ = [ # noqa: RUF022 - intentionally grouped by category
|
|
43
|
+
# Main classes
|
|
44
|
+
"ConfigurationManager",
|
|
45
|
+
"ConfigSchema",
|
|
46
|
+
"StorageMode",
|
|
47
|
+
# Exceptions
|
|
48
|
+
"ConfigValidationError",
|
|
49
|
+
# Utility functions
|
|
50
|
+
"get_default_config_path",
|
|
51
|
+
"get_xdg_config_home",
|
|
52
|
+
"get_xdg_data_home",
|
|
53
|
+
]
|