quantumapi 0.21.0__tar.gz → 0.22.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.
- {quantumapi-0.21.0/quantumapi.egg-info → quantumapi-0.22.0}/PKG-INFO +23 -2
- {quantumapi-0.21.0 → quantumapi-0.22.0}/README.md +22 -1
- {quantumapi-0.21.0 → quantumapi-0.22.0}/pyproject.toml +1 -1
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/__init__.py +2 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/__init__.py +2 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/async_client.py +2 -0
- quantumapi-0.22.0/quantumapi/client/audit.py +66 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/base.py +8 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/sync_client.py +1 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/errors/__init__.py +2 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/errors/exceptions.py +9 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/models/__init__.py +5 -0
- quantumapi-0.22.0/quantumapi/models/audit.py +47 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0/quantumapi.egg-info}/PKG-INFO +23 -2
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi.egg-info/SOURCES.txt +3 -0
- quantumapi-0.22.0/tests/test_audit.py +99 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/LICENSE +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/applications.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/encryption.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/end_users.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/health.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/keys.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/qrng.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/resource_groups.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/roles.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/client/secrets.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/models/applications.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/models/encryption.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/models/end_users.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/models/health.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/models/keys.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/models/qrng.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/models/resource_groups.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/models/roles.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/models/secrets.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi/py.typed +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi.egg-info/dependency_links.txt +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi.egg-info/requires.txt +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/quantumapi.egg-info/top_level.txt +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/setup.cfg +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/tests/test_end_users.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/tests/test_exceptions.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/tests/test_models.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/tests/test_parity.py +0 -0
- {quantumapi-0.21.0 → quantumapi-0.22.0}/tests/test_qrng.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quantumapi
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.22.0
|
|
4
4
|
Summary: Official Python SDK for QuantumAPI - Quantum-safe encryption and identity platform
|
|
5
5
|
Author-email: QuantumAPI Team <developers@quantumapi.eu>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -171,6 +171,27 @@ is_valid = await client.encryption.verify(
|
|
|
171
171
|
)
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
+
### Audit Client
|
|
175
|
+
|
|
176
|
+
Requires an API key with the `audit:read` scope (403 otherwise) or a JWT owner/admin.
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
logs = await client.audit.list(
|
|
180
|
+
category="keys",
|
|
181
|
+
action=["Encrypt", "Decrypt"], # or "Encrypt,Decrypt"
|
|
182
|
+
key_id="key-id",
|
|
183
|
+
from_="2026-10-01T00:00:00Z",
|
|
184
|
+
page=1,
|
|
185
|
+
page_size=100, # max 200
|
|
186
|
+
)
|
|
187
|
+
for e in logs.items:
|
|
188
|
+
print(e.timestamp, e.action, e.actor, e.outcome)
|
|
189
|
+
print(logs.total_count)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Creating or importing a key with a name already in use raises `ConflictError`
|
|
193
|
+
(`error_code == "key_name_conflict"`).
|
|
194
|
+
|
|
174
195
|
### Keys Client
|
|
175
196
|
|
|
176
197
|
```python
|
|
@@ -572,7 +593,7 @@ See [CHANGELOG.md](CHANGELOG.md) for a history of changes to this SDK.
|
|
|
572
593
|
|
|
573
594
|
## Security
|
|
574
595
|
|
|
575
|
-
For security concerns, please email
|
|
596
|
+
For security concerns, please email victorxata@icloud.com. Do not create public issues for security vulnerabilities.
|
|
576
597
|
|
|
577
598
|
## Links
|
|
578
599
|
|
|
@@ -130,6 +130,27 @@ is_valid = await client.encryption.verify(
|
|
|
130
130
|
)
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
### Audit Client
|
|
134
|
+
|
|
135
|
+
Requires an API key with the `audit:read` scope (403 otherwise) or a JWT owner/admin.
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
logs = await client.audit.list(
|
|
139
|
+
category="keys",
|
|
140
|
+
action=["Encrypt", "Decrypt"], # or "Encrypt,Decrypt"
|
|
141
|
+
key_id="key-id",
|
|
142
|
+
from_="2026-10-01T00:00:00Z",
|
|
143
|
+
page=1,
|
|
144
|
+
page_size=100, # max 200
|
|
145
|
+
)
|
|
146
|
+
for e in logs.items:
|
|
147
|
+
print(e.timestamp, e.action, e.actor, e.outcome)
|
|
148
|
+
print(logs.total_count)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Creating or importing a key with a name already in use raises `ConflictError`
|
|
152
|
+
(`error_code == "key_name_conflict"`).
|
|
153
|
+
|
|
133
154
|
### Keys Client
|
|
134
155
|
|
|
135
156
|
```python
|
|
@@ -531,7 +552,7 @@ See [CHANGELOG.md](CHANGELOG.md) for a history of changes to this SDK.
|
|
|
531
552
|
|
|
532
553
|
## Security
|
|
533
554
|
|
|
534
|
-
For security concerns, please email
|
|
555
|
+
For security concerns, please email victorxata@icloud.com. Do not create public issues for security vulnerabilities.
|
|
535
556
|
|
|
536
557
|
## Links
|
|
537
558
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "quantumapi"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.22.0"
|
|
8
8
|
description = "Official Python SDK for QuantumAPI - Quantum-safe encryption and identity platform"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -17,6 +17,7 @@ from quantumapi.client.async_client import QuantumAPIClient
|
|
|
17
17
|
from quantumapi.client.sync_client import QuantumAPISyncClient
|
|
18
18
|
from quantumapi.errors.exceptions import (
|
|
19
19
|
AuthenticationError,
|
|
20
|
+
ConflictError,
|
|
20
21
|
NetworkError,
|
|
21
22
|
NotFoundError,
|
|
22
23
|
PermissionError,
|
|
@@ -37,6 +38,7 @@ __all__ = [
|
|
|
37
38
|
"AuthenticationError",
|
|
38
39
|
"PermissionError",
|
|
39
40
|
"NotFoundError",
|
|
41
|
+
"ConflictError",
|
|
40
42
|
"RateLimitError",
|
|
41
43
|
"ValidationError",
|
|
42
44
|
"ServerError",
|
|
@@ -5,6 +5,7 @@ from quantumapi.client.async_client import QuantumAPIClient
|
|
|
5
5
|
from quantumapi.client.encryption import EncryptionClient
|
|
6
6
|
from quantumapi.client.end_users import EndUsersClient
|
|
7
7
|
from quantumapi.client.health import HealthClient
|
|
8
|
+
from quantumapi.client.audit import AuditClient
|
|
8
9
|
from quantumapi.client.keys import KeysClient
|
|
9
10
|
from quantumapi.client.qrng import QrngClient
|
|
10
11
|
from quantumapi.client.secrets import SecretsClient
|
|
@@ -17,6 +18,7 @@ __all__ = [
|
|
|
17
18
|
"EndUsersClient",
|
|
18
19
|
"EncryptionClient",
|
|
19
20
|
"KeysClient",
|
|
21
|
+
"AuditClient",
|
|
20
22
|
"QrngClient",
|
|
21
23
|
"SecretsClient",
|
|
22
24
|
"HealthClient",
|
|
@@ -8,6 +8,7 @@ from quantumapi.client.base import BaseClient
|
|
|
8
8
|
from quantumapi.client.encryption import EncryptionClient
|
|
9
9
|
from quantumapi.client.end_users import EndUsersClient
|
|
10
10
|
from quantumapi.client.health import HealthClient
|
|
11
|
+
from quantumapi.client.audit import AuditClient
|
|
11
12
|
from quantumapi.client.keys import KeysClient
|
|
12
13
|
from quantumapi.client.qrng import QrngClient
|
|
13
14
|
from quantumapi.client.resource_groups import ResourceGroupsClient
|
|
@@ -82,6 +83,7 @@ class QuantumAPIClient:
|
|
|
82
83
|
# Initialize service clients
|
|
83
84
|
self.encryption = EncryptionClient(self._base_client)
|
|
84
85
|
self.keys = KeysClient(self._base_client)
|
|
86
|
+
self.audit = AuditClient(self._base_client)
|
|
85
87
|
self.secrets = SecretsClient(self._base_client)
|
|
86
88
|
self.resource_groups = ResourceGroupsClient(self._base_client)
|
|
87
89
|
self.applications = ApplicationsClient(self._base_client)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Audit logs client for QuantumAPI SDK."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import Optional, Sequence, Union
|
|
5
|
+
from uuid import UUID
|
|
6
|
+
|
|
7
|
+
from quantumapi.client.base import BaseClient
|
|
8
|
+
from quantumapi.models.audit import AuditLogListResponse
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _iso(value: Union[str, datetime]) -> str:
|
|
12
|
+
return value.isoformat() if isinstance(value, datetime) else value
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AuditClient:
|
|
16
|
+
"""Client for the tenant audit log (requires the ``audit:read`` API-key scope)."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, base_client: BaseClient) -> None:
|
|
19
|
+
self._client = base_client
|
|
20
|
+
|
|
21
|
+
async def list(
|
|
22
|
+
self,
|
|
23
|
+
category: Optional[str] = None,
|
|
24
|
+
action: Optional[Union[str, Sequence[str]]] = None,
|
|
25
|
+
key_id: Optional[Union[str, UUID]] = None,
|
|
26
|
+
actor: Optional[str] = None,
|
|
27
|
+
from_: Optional[Union[str, datetime]] = None,
|
|
28
|
+
to: Optional[Union[str, datetime]] = None,
|
|
29
|
+
page: int = 1,
|
|
30
|
+
page_size: int = 50,
|
|
31
|
+
) -> AuditLogListResponse:
|
|
32
|
+
"""
|
|
33
|
+
List the tenant's audit log, newest first.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
category: Filter by category (e.g. ``"keys"``)
|
|
37
|
+
action: One action or a list (Encrypt, Decrypt, Sign, Verify, Rewrap,
|
|
38
|
+
Hmac, GenerateDataKey, KeyCreated, ...)
|
|
39
|
+
key_id: Only events for this key
|
|
40
|
+
actor: Case-insensitive substring match on the actor
|
|
41
|
+
from_: Only events at or after this time (ISO-8601 string or datetime)
|
|
42
|
+
to: Only events at or before this time (ISO-8601 string or datetime)
|
|
43
|
+
page: Page number (1-based)
|
|
44
|
+
page_size: Items per page (max 200)
|
|
45
|
+
|
|
46
|
+
Raises:
|
|
47
|
+
PermissionError: The API key lacks the ``audit:read`` scope (403)
|
|
48
|
+
|
|
49
|
+
Example:
|
|
50
|
+
>>> logs = await client.audit.list(category="keys", action=["Encrypt", "Decrypt"])
|
|
51
|
+
"""
|
|
52
|
+
params: dict = {"page": page, "pageSize": page_size}
|
|
53
|
+
if category:
|
|
54
|
+
params["category"] = category
|
|
55
|
+
if action:
|
|
56
|
+
params["action"] = action if isinstance(action, str) else ",".join(action)
|
|
57
|
+
if key_id:
|
|
58
|
+
params["keyId"] = str(key_id)
|
|
59
|
+
if actor:
|
|
60
|
+
params["actor"] = actor
|
|
61
|
+
if from_:
|
|
62
|
+
params["from"] = _iso(from_)
|
|
63
|
+
if to:
|
|
64
|
+
params["to"] = _iso(to)
|
|
65
|
+
response = await self._client.get("/api/v1/audit-logs", params=params)
|
|
66
|
+
return AuditLogListResponse(**response)
|
|
@@ -9,6 +9,7 @@ from httpx import Response
|
|
|
9
9
|
|
|
10
10
|
from quantumapi.errors import (
|
|
11
11
|
AuthenticationError,
|
|
12
|
+
ConflictError,
|
|
12
13
|
NetworkError,
|
|
13
14
|
NotFoundError,
|
|
14
15
|
PermissionError,
|
|
@@ -141,6 +142,13 @@ class BaseClient:
|
|
|
141
142
|
details=error_details,
|
|
142
143
|
status_code=404,
|
|
143
144
|
)
|
|
145
|
+
elif response.status_code == 409:
|
|
146
|
+
raise ConflictError(
|
|
147
|
+
message=error_message,
|
|
148
|
+
error_code=error_code,
|
|
149
|
+
details=error_details,
|
|
150
|
+
status_code=409,
|
|
151
|
+
)
|
|
144
152
|
elif response.status_code == 400 or response.status_code == 422:
|
|
145
153
|
raise ValidationError(
|
|
146
154
|
message=error_message,
|
|
@@ -100,6 +100,7 @@ class QuantumAPISyncClient:
|
|
|
100
100
|
|
|
101
101
|
self.encryption = _SyncProxy(self._async_client.encryption)
|
|
102
102
|
self.keys = _SyncProxy(self._async_client.keys)
|
|
103
|
+
self.audit = _SyncProxy(self._async_client.audit)
|
|
103
104
|
self.secrets = _SyncProxy(self._async_client.secrets)
|
|
104
105
|
self.resource_groups = _SyncProxy(self._async_client.resource_groups)
|
|
105
106
|
self.applications = _SyncProxy(self._async_client.applications)
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from quantumapi.errors.exceptions import (
|
|
4
4
|
AuthenticationError,
|
|
5
|
+
ConflictError,
|
|
5
6
|
InvalidRequestError,
|
|
6
7
|
NetworkError,
|
|
7
8
|
NotFoundError,
|
|
@@ -18,6 +19,7 @@ __all__ = [
|
|
|
18
19
|
"AuthenticationError",
|
|
19
20
|
"PermissionError",
|
|
20
21
|
"NotFoundError",
|
|
22
|
+
"ConflictError",
|
|
21
23
|
"ValidationError",
|
|
22
24
|
"RateLimitError",
|
|
23
25
|
"ServerError",
|
|
@@ -59,6 +59,15 @@ class NotFoundError(QuantumAPIError):
|
|
|
59
59
|
super().__init__(message, status_code=404, **kwargs)
|
|
60
60
|
|
|
61
61
|
|
|
62
|
+
class ConflictError(QuantumAPIError):
|
|
63
|
+
"""Raised on HTTP 409, e.g. ``key_name_conflict`` when a key name is already in use."""
|
|
64
|
+
|
|
65
|
+
def __init__(self, message: str = "Conflict", **kwargs: Any) -> None:
|
|
66
|
+
"""Initialize ConflictError."""
|
|
67
|
+
kwargs.setdefault("status_code", 409)
|
|
68
|
+
super().__init__(message, **kwargs)
|
|
69
|
+
|
|
70
|
+
|
|
62
71
|
class ValidationError(QuantumAPIError):
|
|
63
72
|
"""Raised when request validation fails (400)."""
|
|
64
73
|
|
|
@@ -9,6 +9,7 @@ from quantumapi.models.applications import (
|
|
|
9
9
|
RotateSecretResponse,
|
|
10
10
|
UpdateApplicationRequest,
|
|
11
11
|
)
|
|
12
|
+
from quantumapi.models.audit import AUDIT_READ_SCOPE, AuditLogEntry, AuditLogListResponse
|
|
12
13
|
from quantumapi.models.end_users import (
|
|
13
14
|
CreateEndUserRequest,
|
|
14
15
|
EndUser,
|
|
@@ -75,6 +76,10 @@ from quantumapi.models.secrets import (
|
|
|
75
76
|
)
|
|
76
77
|
|
|
77
78
|
__all__ = [
|
|
79
|
+
# Audit
|
|
80
|
+
"AUDIT_READ_SCOPE",
|
|
81
|
+
"AuditLogEntry",
|
|
82
|
+
"AuditLogListResponse",
|
|
78
83
|
# Applications
|
|
79
84
|
"Application",
|
|
80
85
|
"ApplicationType",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Pydantic models for the tenant audit log (GET /api/v1/audit-logs)."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from typing import List, Optional
|
|
5
|
+
from uuid import UUID
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, Field
|
|
8
|
+
|
|
9
|
+
#: API-key scope required to read the audit log with an API key.
|
|
10
|
+
AUDIT_READ_SCOPE = "audit:read"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AuditLogEntry(BaseModel):
|
|
14
|
+
"""One entry of the tenant audit log."""
|
|
15
|
+
|
|
16
|
+
id: UUID = Field(..., description="Entry ID")
|
|
17
|
+
timestamp: datetime = Field(..., description="When the event happened")
|
|
18
|
+
action: str = Field(..., description="Audit action, e.g. Encrypt, Decrypt, Sign, Verify, KeyCreated")
|
|
19
|
+
category: str = Field(..., description="'keys' for key events, 'other' otherwise")
|
|
20
|
+
actor: str = Field(..., description="User e-mail, 'apikey:{name}' or another principal marker")
|
|
21
|
+
actor_type: str = Field(..., alias="actorType", description="'user', 'apiKey' or 'other'")
|
|
22
|
+
resource_type: str = Field(..., alias="resourceType", description="Resource type, e.g. CryptoKey")
|
|
23
|
+
resource_id: UUID = Field(..., alias="resourceId", description="Resource ID")
|
|
24
|
+
resource_name: Optional[str] = Field(default=None, alias="resourceName", description="Resource name")
|
|
25
|
+
outcome: str = Field(..., description="'success', 'failure' or 'denied'")
|
|
26
|
+
valid: Optional[bool] = Field(default=None, description="Verify only: whether the signature was valid")
|
|
27
|
+
error: Optional[str] = Field(default=None, description="Error code for failures")
|
|
28
|
+
algorithm: Optional[str] = Field(default=None, description="Algorithm used")
|
|
29
|
+
key_version: Optional[int] = Field(default=None, alias="keyVersion", description="Key version used")
|
|
30
|
+
channel: Optional[str] = Field(default=None, description="'eaas' or 'transit' for key usage events")
|
|
31
|
+
ip_address: Optional[str] = Field(default=None, alias="ipAddress", description="Caller IP address")
|
|
32
|
+
user_agent: Optional[str] = Field(default=None, alias="userAgent", description="Caller user agent")
|
|
33
|
+
batch_size: Optional[int] = Field(default=None, alias="batchSize", description="Batch size, if a batch call")
|
|
34
|
+
failed_items: Optional[int] = Field(default=None, alias="failedItems", description="Failed items in a batch")
|
|
35
|
+
|
|
36
|
+
model_config = {"populate_by_name": True}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class AuditLogListResponse(BaseModel):
|
|
40
|
+
"""Paginated tenant audit log."""
|
|
41
|
+
|
|
42
|
+
items: List[AuditLogEntry] = Field(default_factory=list, description="Entries, newest first")
|
|
43
|
+
total_count: int = Field(..., alias="totalCount", description="Total entries matching the filters")
|
|
44
|
+
page: int = Field(..., description="Current page (1-based)")
|
|
45
|
+
page_size: int = Field(..., alias="pageSize", description="Page size used by the server")
|
|
46
|
+
|
|
47
|
+
model_config = {"populate_by_name": True}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quantumapi
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.22.0
|
|
4
4
|
Summary: Official Python SDK for QuantumAPI - Quantum-safe encryption and identity platform
|
|
5
5
|
Author-email: QuantumAPI Team <developers@quantumapi.eu>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -171,6 +171,27 @@ is_valid = await client.encryption.verify(
|
|
|
171
171
|
)
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
+
### Audit Client
|
|
175
|
+
|
|
176
|
+
Requires an API key with the `audit:read` scope (403 otherwise) or a JWT owner/admin.
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
logs = await client.audit.list(
|
|
180
|
+
category="keys",
|
|
181
|
+
action=["Encrypt", "Decrypt"], # or "Encrypt,Decrypt"
|
|
182
|
+
key_id="key-id",
|
|
183
|
+
from_="2026-10-01T00:00:00Z",
|
|
184
|
+
page=1,
|
|
185
|
+
page_size=100, # max 200
|
|
186
|
+
)
|
|
187
|
+
for e in logs.items:
|
|
188
|
+
print(e.timestamp, e.action, e.actor, e.outcome)
|
|
189
|
+
print(logs.total_count)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Creating or importing a key with a name already in use raises `ConflictError`
|
|
193
|
+
(`error_code == "key_name_conflict"`).
|
|
194
|
+
|
|
174
195
|
### Keys Client
|
|
175
196
|
|
|
176
197
|
```python
|
|
@@ -572,7 +593,7 @@ See [CHANGELOG.md](CHANGELOG.md) for a history of changes to this SDK.
|
|
|
572
593
|
|
|
573
594
|
## Security
|
|
574
595
|
|
|
575
|
-
For security concerns, please email
|
|
596
|
+
For security concerns, please email victorxata@icloud.com. Do not create public issues for security vulnerabilities.
|
|
576
597
|
|
|
577
598
|
## Links
|
|
578
599
|
|
|
@@ -11,6 +11,7 @@ quantumapi.egg-info/top_level.txt
|
|
|
11
11
|
quantumapi/client/__init__.py
|
|
12
12
|
quantumapi/client/applications.py
|
|
13
13
|
quantumapi/client/async_client.py
|
|
14
|
+
quantumapi/client/audit.py
|
|
14
15
|
quantumapi/client/base.py
|
|
15
16
|
quantumapi/client/encryption.py
|
|
16
17
|
quantumapi/client/end_users.py
|
|
@@ -25,6 +26,7 @@ quantumapi/errors/__init__.py
|
|
|
25
26
|
quantumapi/errors/exceptions.py
|
|
26
27
|
quantumapi/models/__init__.py
|
|
27
28
|
quantumapi/models/applications.py
|
|
29
|
+
quantumapi/models/audit.py
|
|
28
30
|
quantumapi/models/encryption.py
|
|
29
31
|
quantumapi/models/end_users.py
|
|
30
32
|
quantumapi/models/health.py
|
|
@@ -33,6 +35,7 @@ quantumapi/models/qrng.py
|
|
|
33
35
|
quantumapi/models/resource_groups.py
|
|
34
36
|
quantumapi/models/roles.py
|
|
35
37
|
quantumapi/models/secrets.py
|
|
38
|
+
tests/test_audit.py
|
|
36
39
|
tests/test_end_users.py
|
|
37
40
|
tests/test_exceptions.py
|
|
38
41
|
tests/test_models.py
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""Tests for AuditClient and 409 key_name_conflict mapping."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, timezone
|
|
4
|
+
from unittest.mock import AsyncMock, MagicMock
|
|
5
|
+
from uuid import uuid4
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from quantumapi.client.audit import AuditClient
|
|
10
|
+
from quantumapi.client.base import BaseClient
|
|
11
|
+
from quantumapi.errors import ConflictError
|
|
12
|
+
from quantumapi.models.audit import AUDIT_READ_SCOPE, AuditLogListResponse
|
|
13
|
+
|
|
14
|
+
ENTRY = {
|
|
15
|
+
"id": str(uuid4()),
|
|
16
|
+
"timestamp": "2026-10-20T10:00:00+00:00",
|
|
17
|
+
"action": "Encrypt",
|
|
18
|
+
"category": "keys",
|
|
19
|
+
"actor": "apikey:ci",
|
|
20
|
+
"actorType": "apiKey",
|
|
21
|
+
"resourceType": "CryptoKey",
|
|
22
|
+
"resourceId": str(uuid4()),
|
|
23
|
+
"resourceName": "k1",
|
|
24
|
+
"outcome": "success",
|
|
25
|
+
"channel": "transit",
|
|
26
|
+
"keyVersion": 2,
|
|
27
|
+
"batchSize": 3,
|
|
28
|
+
}
|
|
29
|
+
PAYLOAD = {"items": [ENTRY], "totalCount": 1, "page": 1, "pageSize": 50}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_scope_constant():
|
|
33
|
+
assert AUDIT_READ_SCOPE == "audit:read"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_parses_response():
|
|
37
|
+
resp = AuditLogListResponse(**PAYLOAD)
|
|
38
|
+
assert resp.total_count == 1 and resp.page_size == 50
|
|
39
|
+
e = resp.items[0]
|
|
40
|
+
assert e.actor_type == "apiKey" and e.key_version == 2 and e.batch_size == 3
|
|
41
|
+
assert e.valid is None and e.error is None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@pytest.mark.asyncio
|
|
45
|
+
async def test_list_default_params():
|
|
46
|
+
base = AsyncMock()
|
|
47
|
+
base.get.return_value = PAYLOAD
|
|
48
|
+
resp = await AuditClient(base).list()
|
|
49
|
+
base.get.assert_awaited_once_with("/api/v1/audit-logs", params={"page": 1, "pageSize": 50})
|
|
50
|
+
assert len(resp.items) == 1
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@pytest.mark.asyncio
|
|
54
|
+
async def test_list_all_filters():
|
|
55
|
+
base = AsyncMock()
|
|
56
|
+
base.get.return_value = PAYLOAD
|
|
57
|
+
key_id = uuid4()
|
|
58
|
+
start = datetime(2026, 10, 1, tzinfo=timezone.utc)
|
|
59
|
+
await AuditClient(base).list(
|
|
60
|
+
category="keys",
|
|
61
|
+
action=["Encrypt", "Rewrap"],
|
|
62
|
+
key_id=key_id,
|
|
63
|
+
actor="ci",
|
|
64
|
+
from_=start,
|
|
65
|
+
to="2026-10-20T00:00:00Z",
|
|
66
|
+
page=2,
|
|
67
|
+
page_size=200,
|
|
68
|
+
)
|
|
69
|
+
params = base.get.call_args.kwargs["params"]
|
|
70
|
+
assert params == {
|
|
71
|
+
"page": 2,
|
|
72
|
+
"pageSize": 200,
|
|
73
|
+
"category": "keys",
|
|
74
|
+
"action": "Encrypt,Rewrap",
|
|
75
|
+
"keyId": str(key_id),
|
|
76
|
+
"actor": "ci",
|
|
77
|
+
"from": start.isoformat(),
|
|
78
|
+
"to": "2026-10-20T00:00:00Z",
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@pytest.mark.asyncio
|
|
83
|
+
async def test_list_action_string_passthrough():
|
|
84
|
+
base = AsyncMock()
|
|
85
|
+
base.get.return_value = PAYLOAD
|
|
86
|
+
await AuditClient(base).list(action="Sign,Verify")
|
|
87
|
+
assert base.get.call_args.kwargs["params"]["action"] == "Sign,Verify"
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@pytest.mark.asyncio
|
|
91
|
+
async def test_409_maps_to_conflict_error():
|
|
92
|
+
client = BaseClient(api_key="qapi_x", base_url="https://example.test")
|
|
93
|
+
resp = MagicMock()
|
|
94
|
+
resp.status_code = 409
|
|
95
|
+
resp.json.return_value = {"error": "key_name_conflict", "message": "Key name in use"}
|
|
96
|
+
with pytest.raises(ConflictError) as exc:
|
|
97
|
+
await client._handle_response(resp)
|
|
98
|
+
assert exc.value.error_code == "key_name_conflict"
|
|
99
|
+
assert exc.value.status_code == 409
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|