quantumapi 0.20.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.20.0/quantumapi.egg-info → quantumapi-0.22.0}/PKG-INFO +40 -2
- {quantumapi-0.20.0 → quantumapi-0.22.0}/README.md +39 -1
- {quantumapi-0.20.0 → quantumapi-0.22.0}/pyproject.toml +1 -1
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/__init__.py +2 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/client/__init__.py +4 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/client/async_client.py +4 -0
- quantumapi-0.22.0/quantumapi/client/audit.py +66 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/client/base.py +8 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/client/end_users.py +42 -0
- quantumapi-0.22.0/quantumapi/client/qrng.py +81 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/client/secrets.py +46 -8
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/client/sync_client.py +2 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/errors/__init__.py +2 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/errors/exceptions.py +9 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/models/__init__.py +20 -0
- quantumapi-0.22.0/quantumapi/models/audit.py +47 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/models/end_users.py +16 -0
- quantumapi-0.22.0/quantumapi/models/qrng.py +82 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0/quantumapi.egg-info}/PKG-INFO +40 -2
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi.egg-info/SOURCES.txt +8 -1
- quantumapi-0.22.0/tests/test_audit.py +99 -0
- quantumapi-0.22.0/tests/test_end_users.py +61 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/tests/test_parity.py +19 -7
- quantumapi-0.22.0/tests/test_qrng.py +118 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/LICENSE +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/client/applications.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/client/encryption.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/client/health.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/client/keys.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/client/resource_groups.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/client/roles.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/models/applications.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/models/encryption.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/models/health.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/models/keys.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/models/resource_groups.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/models/roles.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/models/secrets.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi/py.typed +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi.egg-info/dependency_links.txt +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi.egg-info/requires.txt +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/quantumapi.egg-info/top_level.txt +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/setup.cfg +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/tests/test_exceptions.py +0 -0
- {quantumapi-0.20.0 → quantumapi-0.22.0}/tests/test_models.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
|
|
@@ -265,6 +286,23 @@ await client.users.update(
|
|
|
265
286
|
await client.users.deactivate(user_id="user-id")
|
|
266
287
|
```
|
|
267
288
|
|
|
289
|
+
### End-Users Client
|
|
290
|
+
|
|
291
|
+
End-users are the people who sign in through one of your OIDC applications (not your tenant's team members).
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
# List the users in an application's pool
|
|
295
|
+
pool = await client.end_users.list(app_id)
|
|
296
|
+
|
|
297
|
+
# Clear the automatic sign-in lockout (distinct from an administrative block)
|
|
298
|
+
await client.end_users.unlock(app_id, user_id)
|
|
299
|
+
|
|
300
|
+
# Generate a one-time temporary password; the user must change it at next login
|
|
301
|
+
temp = await client.end_users.generate_temporary_password(app_id, user_id)
|
|
302
|
+
print(f"Hand this to {temp.email} over a secure channel: {temp.temporary_password}")
|
|
303
|
+
# The plaintext is returned once and is never stored in clear text.
|
|
304
|
+
```
|
|
305
|
+
|
|
268
306
|
### Applications Client
|
|
269
307
|
|
|
270
308
|
```python
|
|
@@ -555,7 +593,7 @@ See [CHANGELOG.md](CHANGELOG.md) for a history of changes to this SDK.
|
|
|
555
593
|
|
|
556
594
|
## Security
|
|
557
595
|
|
|
558
|
-
For security concerns, please email
|
|
596
|
+
For security concerns, please email victorxata@icloud.com. Do not create public issues for security vulnerabilities.
|
|
559
597
|
|
|
560
598
|
## Links
|
|
561
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
|
|
@@ -224,6 +245,23 @@ await client.users.update(
|
|
|
224
245
|
await client.users.deactivate(user_id="user-id")
|
|
225
246
|
```
|
|
226
247
|
|
|
248
|
+
### End-Users Client
|
|
249
|
+
|
|
250
|
+
End-users are the people who sign in through one of your OIDC applications (not your tenant's team members).
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
# List the users in an application's pool
|
|
254
|
+
pool = await client.end_users.list(app_id)
|
|
255
|
+
|
|
256
|
+
# Clear the automatic sign-in lockout (distinct from an administrative block)
|
|
257
|
+
await client.end_users.unlock(app_id, user_id)
|
|
258
|
+
|
|
259
|
+
# Generate a one-time temporary password; the user must change it at next login
|
|
260
|
+
temp = await client.end_users.generate_temporary_password(app_id, user_id)
|
|
261
|
+
print(f"Hand this to {temp.email} over a secure channel: {temp.temporary_password}")
|
|
262
|
+
# The plaintext is returned once and is never stored in clear text.
|
|
263
|
+
```
|
|
264
|
+
|
|
227
265
|
### Applications Client
|
|
228
266
|
|
|
229
267
|
```python
|
|
@@ -514,7 +552,7 @@ See [CHANGELOG.md](CHANGELOG.md) for a history of changes to this SDK.
|
|
|
514
552
|
|
|
515
553
|
## Security
|
|
516
554
|
|
|
517
|
-
For security concerns, please email
|
|
555
|
+
For security concerns, please email victorxata@icloud.com. Do not create public issues for security vulnerabilities.
|
|
518
556
|
|
|
519
557
|
## Links
|
|
520
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,7 +5,9 @@ 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
|
|
10
|
+
from quantumapi.client.qrng import QrngClient
|
|
9
11
|
from quantumapi.client.secrets import SecretsClient
|
|
10
12
|
from quantumapi.client.sync_client import QuantumAPISyncClient
|
|
11
13
|
|
|
@@ -16,6 +18,8 @@ __all__ = [
|
|
|
16
18
|
"EndUsersClient",
|
|
17
19
|
"EncryptionClient",
|
|
18
20
|
"KeysClient",
|
|
21
|
+
"AuditClient",
|
|
22
|
+
"QrngClient",
|
|
19
23
|
"SecretsClient",
|
|
20
24
|
"HealthClient",
|
|
21
25
|
]
|
|
@@ -8,7 +8,9 @@ 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
|
|
13
|
+
from quantumapi.client.qrng import QrngClient
|
|
12
14
|
from quantumapi.client.resource_groups import ResourceGroupsClient
|
|
13
15
|
from quantumapi.client.roles import RolesClient
|
|
14
16
|
from quantumapi.client.secrets import SecretsClient
|
|
@@ -81,12 +83,14 @@ class QuantumAPIClient:
|
|
|
81
83
|
# Initialize service clients
|
|
82
84
|
self.encryption = EncryptionClient(self._base_client)
|
|
83
85
|
self.keys = KeysClient(self._base_client)
|
|
86
|
+
self.audit = AuditClient(self._base_client)
|
|
84
87
|
self.secrets = SecretsClient(self._base_client)
|
|
85
88
|
self.resource_groups = ResourceGroupsClient(self._base_client)
|
|
86
89
|
self.applications = ApplicationsClient(self._base_client)
|
|
87
90
|
self.end_users = EndUsersClient(self._base_client)
|
|
88
91
|
self.roles = RolesClient(self._base_client)
|
|
89
92
|
self.health = HealthClient(self._base_client)
|
|
93
|
+
self.qrng = QrngClient(self._base_client)
|
|
90
94
|
|
|
91
95
|
async def close(self) -> None:
|
|
92
96
|
"""
|
|
@@ -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,
|
|
@@ -9,6 +9,7 @@ from quantumapi.models.end_users import (
|
|
|
9
9
|
EndUser,
|
|
10
10
|
EndUserListResponse,
|
|
11
11
|
EndUserRole,
|
|
12
|
+
EndUserTemporaryPasswordResponse,
|
|
12
13
|
UpdateEndUserRequest,
|
|
13
14
|
)
|
|
14
15
|
|
|
@@ -218,6 +219,47 @@ class EndUsersClient:
|
|
|
218
219
|
"""
|
|
219
220
|
await self._client.post(f"{self._base_url(app_id)}/{user_id}/unblock")
|
|
220
221
|
|
|
222
|
+
async def unlock(self, app_id: UUID, user_id: UUID) -> None:
|
|
223
|
+
"""
|
|
224
|
+
Clear the automatic sign-in lockout for an end-user.
|
|
225
|
+
|
|
226
|
+
Distinct from :meth:`unblock`, which lifts an administrative block.
|
|
227
|
+
|
|
228
|
+
Args:
|
|
229
|
+
app_id: Application ID
|
|
230
|
+
user_id: End-user ID
|
|
231
|
+
|
|
232
|
+
Example:
|
|
233
|
+
>>> await client.end_users.unlock(app_id, user_id)
|
|
234
|
+
"""
|
|
235
|
+
await self._client.post(f"{self._base_url(app_id)}/{user_id}/unlock")
|
|
236
|
+
|
|
237
|
+
async def generate_temporary_password(
|
|
238
|
+
self, app_id: UUID, user_id: UUID
|
|
239
|
+
) -> EndUserTemporaryPasswordResponse:
|
|
240
|
+
"""
|
|
241
|
+
Generate a one-time temporary password for an end-user.
|
|
242
|
+
|
|
243
|
+
The plaintext is returned once and the user must change it at next
|
|
244
|
+
login. Hand it over through a secure channel; it cannot be retrieved
|
|
245
|
+
again.
|
|
246
|
+
|
|
247
|
+
Args:
|
|
248
|
+
app_id: Application ID
|
|
249
|
+
user_id: End-user ID
|
|
250
|
+
|
|
251
|
+
Returns:
|
|
252
|
+
The temporary password and the end-user's email
|
|
253
|
+
|
|
254
|
+
Example:
|
|
255
|
+
>>> result = await client.end_users.generate_temporary_password(app_id, user_id)
|
|
256
|
+
>>> print(result.temporary_password)
|
|
257
|
+
"""
|
|
258
|
+
response = await self._client.post(
|
|
259
|
+
f"{self._base_url(app_id)}/{user_id}/generate-temporary-password"
|
|
260
|
+
)
|
|
261
|
+
return EndUserTemporaryPasswordResponse(**response)
|
|
262
|
+
|
|
221
263
|
async def delete(self, app_id: UUID, user_id: UUID) -> None:
|
|
222
264
|
"""
|
|
223
265
|
Delete an end-user permanently.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""QRNG bridge client for QuantumAPI SDK (#719)."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from quantumapi.client.base import BaseClient
|
|
6
|
+
from quantumapi.models.qrng import (
|
|
7
|
+
QRNG_FORMAT_BLOCK_SIZE,
|
|
8
|
+
QrngEntropyRequest,
|
|
9
|
+
QrngEntropyResponse,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
ALLOW_CSPRNG_HEADER = "X-Allow-Csprng"
|
|
13
|
+
"""Request header that opts in to CSPRNG bytes when every quantum provider is down."""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class QrngClient:
|
|
17
|
+
"""
|
|
18
|
+
Client for the QRNG bridge: draws quantum entropy from the platform's pooled
|
|
19
|
+
providers (Quantum Blockchains, then ANU) through ``POST /api/v1/qrng/entropy``.
|
|
20
|
+
|
|
21
|
+
Requires an API key with the ``qrng:read`` scope. Bytes are charged against the
|
|
22
|
+
tenant's monthly quota and each key is limited to 100 requests per minute. SaaS only.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, base_client: BaseClient) -> None:
|
|
26
|
+
"""
|
|
27
|
+
Initialize QrngClient.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
base_client: Base HTTP client
|
|
31
|
+
"""
|
|
32
|
+
self._client = base_client
|
|
33
|
+
|
|
34
|
+
async def get_entropy(
|
|
35
|
+
self,
|
|
36
|
+
bytes_count: int,
|
|
37
|
+
format: str = "raw",
|
|
38
|
+
allow_csprng: bool = False,
|
|
39
|
+
) -> QrngEntropyResponse:
|
|
40
|
+
"""
|
|
41
|
+
Draw entropy from the pooled quantum providers.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
bytes_count: Entropy bytes to draw, 1..65536 (server default limit). Must be a
|
|
45
|
+
multiple of 16, 4 or 8 for the ``uuid``, ``int32`` and ``int64`` formats.
|
|
46
|
+
format: ``raw`` (base64, default), ``hex``, ``uuid``, ``int32`` or ``int64``.
|
|
47
|
+
allow_csprng: Send ``X-Allow-Csprng: true`` so the server may return CSPRNG
|
|
48
|
+
bytes (source ``csprng``) instead of failing with 503 when no quantum
|
|
49
|
+
provider is available.
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
The entropy plus source, quota and request metadata.
|
|
53
|
+
|
|
54
|
+
Raises:
|
|
55
|
+
ValueError: ``bytes_count`` is below 1 or not a multiple of the format's block size.
|
|
56
|
+
PermissionError: The API key lacks the ``qrng:read`` scope (403 insufficient_scope).
|
|
57
|
+
ValidationError: 400 invalid_request / invalid_format.
|
|
58
|
+
RateLimitError: 429 quota_exceeded (Retry-After = first day of next month,
|
|
59
|
+
``details['resetsAt']``) or rate_limit_exceeded.
|
|
60
|
+
ServerError: 503 qrng_unavailable (Retry-After: 30).
|
|
61
|
+
|
|
62
|
+
Example:
|
|
63
|
+
>>> entropy = await client.qrng.get_entropy(32, format="hex")
|
|
64
|
+
>>> key = entropy.as_bytes()
|
|
65
|
+
>>> print(entropy.source, entropy.quota_remaining_mb)
|
|
66
|
+
"""
|
|
67
|
+
if bytes_count < 1:
|
|
68
|
+
raise ValueError("bytes_count must be at least 1.")
|
|
69
|
+
normalized = (format or "raw").strip().lower()
|
|
70
|
+
block = QRNG_FORMAT_BLOCK_SIZE.get(normalized, 1)
|
|
71
|
+
if bytes_count % block != 0:
|
|
72
|
+
raise ValueError(f"bytes_count must be a multiple of {block} for format '{normalized}'.")
|
|
73
|
+
|
|
74
|
+
request = QrngEntropyRequest(bytes_count=bytes_count, format=normalized)
|
|
75
|
+
headers: Optional[dict] = {ALLOW_CSPRNG_HEADER: "true"} if allow_csprng else None
|
|
76
|
+
response = await self._client.post(
|
|
77
|
+
"/api/v1/qrng/entropy",
|
|
78
|
+
json_data=request.model_dump(by_alias=True, exclude_none=True),
|
|
79
|
+
headers=headers,
|
|
80
|
+
)
|
|
81
|
+
return QrngEntropyResponse(**response)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Secrets client for QuantumAPI SDK."""
|
|
2
2
|
|
|
3
|
+
import warnings
|
|
3
4
|
from typing import Any, Dict, List, Optional
|
|
4
5
|
from uuid import UUID
|
|
5
6
|
|
|
@@ -238,6 +239,9 @@ class SecretsClient:
|
|
|
238
239
|
"""
|
|
239
240
|
Update secret value (creates new version).
|
|
240
241
|
|
|
242
|
+
The secret keeps its id across versions, so a stored id stays valid
|
|
243
|
+
after rotation (#747).
|
|
244
|
+
|
|
241
245
|
Args:
|
|
242
246
|
secret_id: Secret ID
|
|
243
247
|
value: New secret value
|
|
@@ -260,7 +264,10 @@ class SecretsClient:
|
|
|
260
264
|
|
|
261
265
|
async def delete(self, secret_id: UUID) -> None:
|
|
262
266
|
"""
|
|
263
|
-
|
|
267
|
+
Permanently delete a secret.
|
|
268
|
+
|
|
269
|
+
This is irreversible and cannot be undone by :meth:`activate` — use
|
|
270
|
+
:meth:`deactivate` for a recoverable delete.
|
|
264
271
|
|
|
265
272
|
Args:
|
|
266
273
|
secret_id: Secret ID
|
|
@@ -270,21 +277,52 @@ class SecretsClient:
|
|
|
270
277
|
"""
|
|
271
278
|
await self._client.delete(f"/api/v1/secrets/{secret_id}")
|
|
272
279
|
|
|
273
|
-
async def
|
|
280
|
+
async def deactivate(self, secret_id: UUID) -> None:
|
|
274
281
|
"""
|
|
275
|
-
|
|
282
|
+
Soft-delete a secret.
|
|
283
|
+
|
|
284
|
+
Its value can no longer be retrieved and it drops out of :meth:`list`
|
|
285
|
+
unless ``include_inactive=True``, but the record is kept for audit and
|
|
286
|
+
:meth:`activate` brings it back.
|
|
276
287
|
|
|
277
288
|
Args:
|
|
278
289
|
secret_id: Secret ID
|
|
279
290
|
|
|
280
|
-
|
|
281
|
-
|
|
291
|
+
Example:
|
|
292
|
+
>>> await client.secrets.deactivate(secret_id)
|
|
293
|
+
"""
|
|
294
|
+
await self._client.post(f"/api/v1/secrets/{secret_id}/deactivate")
|
|
295
|
+
|
|
296
|
+
async def activate(self, secret_id: UUID) -> None:
|
|
297
|
+
"""
|
|
298
|
+
Restore a secret that was soft-deleted with :meth:`deactivate`.
|
|
299
|
+
|
|
300
|
+
Args:
|
|
301
|
+
secret_id: Secret ID
|
|
282
302
|
|
|
283
303
|
Example:
|
|
284
|
-
>>>
|
|
304
|
+
>>> await client.secrets.activate(secret_id)
|
|
285
305
|
"""
|
|
286
|
-
|
|
287
|
-
|
|
306
|
+
await self._client.post(f"/api/v1/secrets/{secret_id}/activate")
|
|
307
|
+
|
|
308
|
+
async def restore(self, secret_id: UUID) -> None:
|
|
309
|
+
"""
|
|
310
|
+
Restore a soft-deleted secret.
|
|
311
|
+
|
|
312
|
+
.. deprecated::
|
|
313
|
+
Use :meth:`activate`. This method targeted a ``/restore`` route the API
|
|
314
|
+
has never served, so it 404ed for every secret. See issue #746.
|
|
315
|
+
|
|
316
|
+
Args:
|
|
317
|
+
secret_id: Secret ID
|
|
318
|
+
"""
|
|
319
|
+
warnings.warn(
|
|
320
|
+
"secrets.restore() is deprecated; use secrets.activate(). The /restore "
|
|
321
|
+
"route it called does not exist. See issue #746.",
|
|
322
|
+
DeprecationWarning,
|
|
323
|
+
stacklevel=2,
|
|
324
|
+
)
|
|
325
|
+
await self.activate(secret_id)
|
|
288
326
|
|
|
289
327
|
async def list_versions(self, secret_id: UUID) -> SecretVersionListResponse:
|
|
290
328
|
"""
|
|
@@ -100,12 +100,14 @@ 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)
|
|
106
107
|
self.end_users = _SyncProxy(self._async_client.end_users)
|
|
107
108
|
self.roles = _SyncProxy(self._async_client.roles)
|
|
108
109
|
self.health = _SyncProxy(self._async_client.health)
|
|
110
|
+
self.qrng = _SyncProxy(self._async_client.qrng)
|
|
109
111
|
|
|
110
112
|
def close(self) -> None:
|
|
111
113
|
"""Close HTTP client connections."""
|
|
@@ -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,12 +9,14 @@ 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,
|
|
15
16
|
EndUserConnection,
|
|
16
17
|
EndUserListResponse,
|
|
17
18
|
EndUserRole,
|
|
19
|
+
EndUserTemporaryPasswordResponse,
|
|
18
20
|
UpdateEndUserRequest,
|
|
19
21
|
)
|
|
20
22
|
from quantumapi.models.encryption import (
|
|
@@ -40,6 +42,13 @@ from quantumapi.models.keys import (
|
|
|
40
42
|
RotateKeyRequest,
|
|
41
43
|
UpdateKeyRequest,
|
|
42
44
|
)
|
|
45
|
+
from quantumapi.models.qrng import (
|
|
46
|
+
QRNG_FORMAT_BLOCK_SIZE,
|
|
47
|
+
QrngEntropyFormat,
|
|
48
|
+
QrngEntropyRequest,
|
|
49
|
+
QrngEntropyResponse,
|
|
50
|
+
QrngSourceDetails,
|
|
51
|
+
)
|
|
43
52
|
from quantumapi.models.resource_groups import (
|
|
44
53
|
AddResourceGroupItemRequest,
|
|
45
54
|
CreateResourceGroupRequest,
|
|
@@ -67,6 +76,10 @@ from quantumapi.models.secrets import (
|
|
|
67
76
|
)
|
|
68
77
|
|
|
69
78
|
__all__ = [
|
|
79
|
+
# Audit
|
|
80
|
+
"AUDIT_READ_SCOPE",
|
|
81
|
+
"AuditLogEntry",
|
|
82
|
+
"AuditLogListResponse",
|
|
70
83
|
# Applications
|
|
71
84
|
"Application",
|
|
72
85
|
"ApplicationType",
|
|
@@ -78,6 +91,7 @@ __all__ = [
|
|
|
78
91
|
# End Users
|
|
79
92
|
"EndUser",
|
|
80
93
|
"EndUserRole",
|
|
94
|
+
"EndUserTemporaryPasswordResponse",
|
|
81
95
|
"EndUserConnection",
|
|
82
96
|
"EndUserListResponse",
|
|
83
97
|
"CreateEndUserRequest",
|
|
@@ -117,6 +131,12 @@ __all__ = [
|
|
|
117
131
|
"ImportSecretItem",
|
|
118
132
|
"ImportSecretsRequest",
|
|
119
133
|
"ImportSecretsResponse",
|
|
134
|
+
# QRNG bridge
|
|
135
|
+
"QRNG_FORMAT_BLOCK_SIZE",
|
|
136
|
+
"QrngEntropyFormat",
|
|
137
|
+
"QrngEntropyRequest",
|
|
138
|
+
"QrngEntropyResponse",
|
|
139
|
+
"QrngSourceDetails",
|
|
120
140
|
# Resource Groups
|
|
121
141
|
"ResourceGroup",
|
|
122
142
|
"ResourceGroupDetail",
|
|
@@ -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}
|
|
@@ -50,6 +50,7 @@ class EndUser(BaseModel):
|
|
|
50
50
|
)
|
|
51
51
|
metadata: Optional[str] = Field(default=None, description="Custom metadata (JSON)")
|
|
52
52
|
is_blocked: bool = Field(..., alias="isBlocked", description="Whether the user is blocked")
|
|
53
|
+
is_locked_out: bool = Field(default=False, alias="isLockedOut", description="Whether the account is auto-locked after repeated failed sign-ins")
|
|
53
54
|
blocked_reason: Optional[str] = Field(default=None, alias="blockedReason", description="Block reason")
|
|
54
55
|
blocked_at: Optional[datetime] = Field(default=None, alias="blockedAt", description="Block timestamp")
|
|
55
56
|
last_login_at: Optional[datetime] = Field(default=None, alias="lastLoginAt", description="Last login")
|
|
@@ -74,6 +75,21 @@ class EndUserListResponse(BaseModel):
|
|
|
74
75
|
model_config = {"populate_by_name": True}
|
|
75
76
|
|
|
76
77
|
|
|
78
|
+
class EndUserTemporaryPasswordResponse(BaseModel):
|
|
79
|
+
"""Result of generating a temporary password for an end-user.
|
|
80
|
+
|
|
81
|
+
The plaintext password is returned exactly once and never persisted in
|
|
82
|
+
clear text; the end-user is forced to change it at next login.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
temporary_password: str = Field(
|
|
86
|
+
..., alias="temporaryPassword", description="Generated temporary password (shown once)"
|
|
87
|
+
)
|
|
88
|
+
email: str = Field(..., description="Email of the end-user the password belongs to")
|
|
89
|
+
|
|
90
|
+
model_config = {"populate_by_name": True}
|
|
91
|
+
|
|
92
|
+
|
|
77
93
|
class CreateEndUserRequest(BaseModel):
|
|
78
94
|
"""Request to create an end-user."""
|
|
79
95
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""Pydantic models for the QRNG bridge (POST /api/v1/qrng/entropy, #719)."""
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
from typing import List, Literal, Optional, Union
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, Field
|
|
8
|
+
|
|
9
|
+
QrngEntropyFormat = Literal["raw", "hex", "uuid", "int32", "int64"]
|
|
10
|
+
"""Output formats accepted by the QRNG bridge. Matched case-insensitively by the server."""
|
|
11
|
+
|
|
12
|
+
QRNG_FORMAT_BLOCK_SIZE = {"raw": 1, "hex": 1, "uuid": 16, "int32": 4, "int64": 8}
|
|
13
|
+
"""Entropy bytes consumed per output element of each format."""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class QrngEntropyRequest(BaseModel):
|
|
17
|
+
"""Request body for ``POST /api/v1/qrng/entropy``."""
|
|
18
|
+
|
|
19
|
+
bytes_count: int = Field(
|
|
20
|
+
...,
|
|
21
|
+
alias="bytes",
|
|
22
|
+
ge=1,
|
|
23
|
+
description="Entropy bytes to draw, 1..65536 (server default limit). Must be a multiple of 16/4/8 for uuid/int32/int64.",
|
|
24
|
+
)
|
|
25
|
+
format: Optional[str] = Field(
|
|
26
|
+
default=None,
|
|
27
|
+
description="Output format: raw (base64, default), hex, uuid, int32 or int64",
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
model_config = {"populate_by_name": True}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class QrngSourceDetails(BaseModel):
|
|
34
|
+
"""Provider metadata attached to a QRNG bridge response."""
|
|
35
|
+
|
|
36
|
+
provider: str = Field(..., description="Internal provider name (QuantumBlockchains, ANU, SystemRandom)")
|
|
37
|
+
is_quantum: bool = Field(..., alias="isQuantum", description="True when the bytes came from quantum hardware")
|
|
38
|
+
served_at: datetime = Field(..., alias="servedAt", description="UTC time at which the entropy was served")
|
|
39
|
+
|
|
40
|
+
model_config = {"populate_by_name": True}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class QrngEntropyResponse(BaseModel):
|
|
44
|
+
"""
|
|
45
|
+
Response of ``POST /api/v1/qrng/entropy``.
|
|
46
|
+
|
|
47
|
+
``entropy`` keeps the payload exactly as the server encoded it: a base64 string for
|
|
48
|
+
``raw``, a lowercase hex string for ``hex``, a list of UUID strings for ``uuid`` and a
|
|
49
|
+
list of signed little-endian integers for ``int32`` / ``int64``. Use :meth:`as_bytes`
|
|
50
|
+
to decode the ``raw`` and ``hex`` formats.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
entropy: Union[str, List[str], List[int]] = Field(..., description="Entropy in the requested format")
|
|
54
|
+
format: str = Field(..., description="Canonical name of the format used for entropy")
|
|
55
|
+
source: str = Field(..., description="quantum-blockchains, anu or csprng")
|
|
56
|
+
source_details: QrngSourceDetails = Field(..., alias="sourceDetails", description="Provider metadata")
|
|
57
|
+
consumed_bytes: int = Field(..., alias="consumedBytes", description="Bytes charged against the monthly quota")
|
|
58
|
+
quota_limit_mb: float = Field(..., alias="quotaLimitMb", description="Monthly quota in MB")
|
|
59
|
+
quota_remaining_mb: float = Field(..., alias="quotaRemainingMb", description="MB still available this month")
|
|
60
|
+
request_id: str = Field(..., alias="requestId", description="Request id, also recorded in the audit log")
|
|
61
|
+
|
|
62
|
+
model_config = {"populate_by_name": True}
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def is_quantum(self) -> bool:
|
|
66
|
+
"""True when the bytes came from a quantum provider rather than the CSPRNG fallback."""
|
|
67
|
+
return self.source_details.is_quantum
|
|
68
|
+
|
|
69
|
+
def as_bytes(self) -> bytes:
|
|
70
|
+
"""
|
|
71
|
+
Decode the entropy of a ``raw`` (base64) or ``hex`` response.
|
|
72
|
+
|
|
73
|
+
Raises:
|
|
74
|
+
ValueError: The response is in the uuid, int32 or int64 format.
|
|
75
|
+
"""
|
|
76
|
+
if not isinstance(self.entropy, str):
|
|
77
|
+
raise ValueError(f"Entropy in format '{self.format}' is not a byte string; read .entropy directly.")
|
|
78
|
+
if self.format == "hex":
|
|
79
|
+
return bytes.fromhex(self.entropy)
|
|
80
|
+
if self.format == "raw":
|
|
81
|
+
return base64.b64decode(self.entropy)
|
|
82
|
+
raise ValueError(f"Cannot decode entropy in format '{self.format}' to bytes.")
|
|
@@ -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
|
|
@@ -265,6 +286,23 @@ await client.users.update(
|
|
|
265
286
|
await client.users.deactivate(user_id="user-id")
|
|
266
287
|
```
|
|
267
288
|
|
|
289
|
+
### End-Users Client
|
|
290
|
+
|
|
291
|
+
End-users are the people who sign in through one of your OIDC applications (not your tenant's team members).
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
# List the users in an application's pool
|
|
295
|
+
pool = await client.end_users.list(app_id)
|
|
296
|
+
|
|
297
|
+
# Clear the automatic sign-in lockout (distinct from an administrative block)
|
|
298
|
+
await client.end_users.unlock(app_id, user_id)
|
|
299
|
+
|
|
300
|
+
# Generate a one-time temporary password; the user must change it at next login
|
|
301
|
+
temp = await client.end_users.generate_temporary_password(app_id, user_id)
|
|
302
|
+
print(f"Hand this to {temp.email} over a secure channel: {temp.temporary_password}")
|
|
303
|
+
# The plaintext is returned once and is never stored in clear text.
|
|
304
|
+
```
|
|
305
|
+
|
|
268
306
|
### Applications Client
|
|
269
307
|
|
|
270
308
|
```python
|
|
@@ -555,7 +593,7 @@ See [CHANGELOG.md](CHANGELOG.md) for a history of changes to this SDK.
|
|
|
555
593
|
|
|
556
594
|
## Security
|
|
557
595
|
|
|
558
|
-
For security concerns, please email
|
|
596
|
+
For security concerns, please email victorxata@icloud.com. Do not create public issues for security vulnerabilities.
|
|
559
597
|
|
|
560
598
|
## Links
|
|
561
599
|
|
|
@@ -11,11 +11,13 @@ 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
|
|
17
18
|
quantumapi/client/health.py
|
|
18
19
|
quantumapi/client/keys.py
|
|
20
|
+
quantumapi/client/qrng.py
|
|
19
21
|
quantumapi/client/resource_groups.py
|
|
20
22
|
quantumapi/client/roles.py
|
|
21
23
|
quantumapi/client/secrets.py
|
|
@@ -24,13 +26,18 @@ quantumapi/errors/__init__.py
|
|
|
24
26
|
quantumapi/errors/exceptions.py
|
|
25
27
|
quantumapi/models/__init__.py
|
|
26
28
|
quantumapi/models/applications.py
|
|
29
|
+
quantumapi/models/audit.py
|
|
27
30
|
quantumapi/models/encryption.py
|
|
28
31
|
quantumapi/models/end_users.py
|
|
29
32
|
quantumapi/models/health.py
|
|
30
33
|
quantumapi/models/keys.py
|
|
34
|
+
quantumapi/models/qrng.py
|
|
31
35
|
quantumapi/models/resource_groups.py
|
|
32
36
|
quantumapi/models/roles.py
|
|
33
37
|
quantumapi/models/secrets.py
|
|
38
|
+
tests/test_audit.py
|
|
39
|
+
tests/test_end_users.py
|
|
34
40
|
tests/test_exceptions.py
|
|
35
41
|
tests/test_models.py
|
|
36
|
-
tests/test_parity.py
|
|
42
|
+
tests/test_parity.py
|
|
43
|
+
tests/test_qrng.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
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Tests for EndUsersClient: temporary-password and unlock parity (#733)."""
|
|
2
|
+
|
|
3
|
+
from unittest.mock import AsyncMock
|
|
4
|
+
from uuid import uuid4
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from quantumapi.client.end_users import EndUsersClient
|
|
9
|
+
from quantumapi.models.end_users import EndUserTemporaryPasswordResponse
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TestEndUserTemporaryPasswordResponse:
|
|
13
|
+
"""Tests for the EndUserTemporaryPasswordResponse model."""
|
|
14
|
+
|
|
15
|
+
def test_parses_camel_case_payload(self):
|
|
16
|
+
resp = EndUserTemporaryPasswordResponse(
|
|
17
|
+
**{"temporaryPassword": "Xk9#mP2vQ7wL4nRt", "email": "alice@example.com"}
|
|
18
|
+
)
|
|
19
|
+
assert resp.temporary_password == "Xk9#mP2vQ7wL4nRt"
|
|
20
|
+
assert resp.email == "alice@example.com"
|
|
21
|
+
|
|
22
|
+
def test_accepts_snake_case_by_name(self):
|
|
23
|
+
resp = EndUserTemporaryPasswordResponse(
|
|
24
|
+
temporary_password="Xk9#mP2vQ7wL4nRt", email="alice@example.com"
|
|
25
|
+
)
|
|
26
|
+
assert resp.temporary_password == "Xk9#mP2vQ7wL4nRt"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TestEndUsersClientGenerateTemporaryPassword:
|
|
30
|
+
"""Tests for EndUsersClient.generate_temporary_password."""
|
|
31
|
+
|
|
32
|
+
@pytest.mark.asyncio
|
|
33
|
+
async def test_posts_to_generate_temporary_password_route(self):
|
|
34
|
+
base = AsyncMock()
|
|
35
|
+
base.post.return_value = {
|
|
36
|
+
"temporaryPassword": "Xk9#mP2vQ7wL4nRt",
|
|
37
|
+
"email": "alice@example.com",
|
|
38
|
+
}
|
|
39
|
+
client = EndUsersClient(base)
|
|
40
|
+
app_id, user_id = uuid4(), uuid4()
|
|
41
|
+
|
|
42
|
+
result = await client.generate_temporary_password(app_id, user_id)
|
|
43
|
+
|
|
44
|
+
base.post.assert_awaited_once_with(
|
|
45
|
+
f"/api/v1/applications/{app_id}/end-users/{user_id}/generate-temporary-password"
|
|
46
|
+
)
|
|
47
|
+
assert result.temporary_password == "Xk9#mP2vQ7wL4nRt"
|
|
48
|
+
assert result.email == "alice@example.com"
|
|
49
|
+
|
|
50
|
+
@pytest.mark.asyncio
|
|
51
|
+
async def test_unlock_posts_to_unlock_route(self):
|
|
52
|
+
base = AsyncMock()
|
|
53
|
+
base.post.return_value = {}
|
|
54
|
+
client = EndUsersClient(base)
|
|
55
|
+
app_id, user_id = uuid4(), uuid4()
|
|
56
|
+
|
|
57
|
+
await client.unlock(app_id, user_id)
|
|
58
|
+
|
|
59
|
+
base.post.assert_awaited_once_with(
|
|
60
|
+
f"/api/v1/applications/{app_id}/end-users/{user_id}/unlock"
|
|
61
|
+
)
|
|
@@ -434,23 +434,35 @@ class TestImportSecretsModels:
|
|
|
434
434
|
# ---------------------------------------------------------------------------
|
|
435
435
|
|
|
436
436
|
class TestSecretsClientRestore:
|
|
437
|
-
"""Tests for SecretsClient.restore method."""
|
|
437
|
+
"""Tests for the deprecated SecretsClient.restore method (#746)."""
|
|
438
438
|
|
|
439
439
|
@pytest.fixture
|
|
440
440
|
def base_client(self):
|
|
441
441
|
client = MagicMock()
|
|
442
|
-
client.post = AsyncMock()
|
|
442
|
+
client.post = AsyncMock(return_value=None)
|
|
443
443
|
return client
|
|
444
444
|
|
|
445
|
-
async def
|
|
445
|
+
async def test_restore_secret_delegates_to_activate(self, base_client):
|
|
446
446
|
secret_id = uuid4()
|
|
447
|
-
base_client.post.return_value = _make_secret_response(id=secret_id)
|
|
448
447
|
|
|
449
448
|
secrets_client = SecretsClient(base_client)
|
|
450
|
-
|
|
449
|
+
with pytest.warns(DeprecationWarning, match="secrets.activate"):
|
|
450
|
+
result = await secrets_client.restore(secret_id)
|
|
451
451
|
|
|
452
|
-
base_client.post.assert_called_once_with(f"/api/v1/secrets/{secret_id}/
|
|
453
|
-
assert
|
|
452
|
+
base_client.post.assert_called_once_with(f"/api/v1/secrets/{secret_id}/activate")
|
|
453
|
+
assert result is None
|
|
454
|
+
|
|
455
|
+
async def test_activate_and_deactivate_routes(self, base_client):
|
|
456
|
+
secret_id = uuid4()
|
|
457
|
+
secrets_client = SecretsClient(base_client)
|
|
458
|
+
|
|
459
|
+
await secrets_client.deactivate(secret_id)
|
|
460
|
+
await secrets_client.activate(secret_id)
|
|
461
|
+
|
|
462
|
+
assert [c.args[0] for c in base_client.post.call_args_list] == [
|
|
463
|
+
f"/api/v1/secrets/{secret_id}/deactivate",
|
|
464
|
+
f"/api/v1/secrets/{secret_id}/activate",
|
|
465
|
+
]
|
|
454
466
|
|
|
455
467
|
|
|
456
468
|
class TestSecretsClientListVersions:
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""Tests for QrngClient and the QRNG bridge models (#719)."""
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
from unittest.mock import AsyncMock
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from quantumapi.client.qrng import ALLOW_CSPRNG_HEADER, QrngClient
|
|
9
|
+
from quantumapi.client.sync_client import QuantumAPISyncClient
|
|
10
|
+
from quantumapi.models.qrng import QrngEntropyRequest, QrngEntropyResponse
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _envelope(entropy, fmt, source="quantum-blockchains", is_quantum=True):
|
|
14
|
+
return {
|
|
15
|
+
"entropy": entropy,
|
|
16
|
+
"format": fmt,
|
|
17
|
+
"source": source,
|
|
18
|
+
"sourceDetails": {
|
|
19
|
+
"provider": "QuantumBlockchains" if is_quantum else "SystemRandom",
|
|
20
|
+
"isQuantum": is_quantum,
|
|
21
|
+
"servedAt": "2026-09-02T10:00:00+00:00",
|
|
22
|
+
},
|
|
23
|
+
"consumedBytes": 32,
|
|
24
|
+
"quotaLimitMb": 100.0,
|
|
25
|
+
"quotaRemainingMb": 99.997,
|
|
26
|
+
"requestId": "3f1a2b4c-5d6e-4f70-8a9b-0c1d2e3f4a5b",
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class TestQrngModels:
|
|
31
|
+
def test_request_serializes_bytes_alias(self):
|
|
32
|
+
req = QrngEntropyRequest(bytes_count=32, format="hex")
|
|
33
|
+
assert req.model_dump(by_alias=True, exclude_none=True) == {"bytes": 32, "format": "hex"}
|
|
34
|
+
|
|
35
|
+
def test_request_rejects_zero_bytes(self):
|
|
36
|
+
with pytest.raises(Exception):
|
|
37
|
+
QrngEntropyRequest(bytes_count=0)
|
|
38
|
+
|
|
39
|
+
def test_response_parses_camel_case_and_decodes_raw(self):
|
|
40
|
+
raw = bytes(range(32))
|
|
41
|
+
resp = QrngEntropyResponse(**_envelope(base64.b64encode(raw).decode(), "raw"))
|
|
42
|
+
assert resp.as_bytes() == raw
|
|
43
|
+
assert resp.is_quantum is True
|
|
44
|
+
assert resp.source_details.provider == "QuantumBlockchains"
|
|
45
|
+
assert resp.quota_remaining_mb == 99.997
|
|
46
|
+
assert resp.request_id == "3f1a2b4c-5d6e-4f70-8a9b-0c1d2e3f4a5b"
|
|
47
|
+
|
|
48
|
+
def test_response_decodes_hex(self):
|
|
49
|
+
resp = QrngEntropyResponse(**_envelope("deadbeef", "hex"))
|
|
50
|
+
assert resp.as_bytes() == b"\xde\xad\xbe\xef"
|
|
51
|
+
|
|
52
|
+
def test_response_keeps_int64_precision_and_refuses_as_bytes(self):
|
|
53
|
+
values = [-(2**63), -1, 2**63 - 1]
|
|
54
|
+
resp = QrngEntropyResponse(**_envelope(values, "int64"))
|
|
55
|
+
assert resp.entropy == values
|
|
56
|
+
with pytest.raises(ValueError):
|
|
57
|
+
resp.as_bytes()
|
|
58
|
+
|
|
59
|
+
def test_response_keeps_uuid_list(self):
|
|
60
|
+
resp = QrngEntropyResponse(**_envelope(["0f1e2d3c-4b5a-4978-8695-a4b3c2d1e0f0"], "uuid"))
|
|
61
|
+
assert resp.entropy == ["0f1e2d3c-4b5a-4978-8695-a4b3c2d1e0f0"]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class TestQrngClientGetEntropy:
|
|
65
|
+
@pytest.mark.asyncio
|
|
66
|
+
async def test_posts_to_entropy_route_without_csprng_header(self):
|
|
67
|
+
base = AsyncMock()
|
|
68
|
+
base.post.return_value = _envelope(base64.b64encode(bytes(32)).decode(), "raw")
|
|
69
|
+
client = QrngClient(base)
|
|
70
|
+
|
|
71
|
+
result = await client.get_entropy(32)
|
|
72
|
+
|
|
73
|
+
base.post.assert_awaited_once_with(
|
|
74
|
+
"/api/v1/qrng/entropy",
|
|
75
|
+
json_data={"bytes": 32, "format": "raw"},
|
|
76
|
+
headers=None,
|
|
77
|
+
)
|
|
78
|
+
assert result.format == "raw"
|
|
79
|
+
assert result.as_bytes() == bytes(32)
|
|
80
|
+
|
|
81
|
+
@pytest.mark.asyncio
|
|
82
|
+
async def test_sends_allow_csprng_header_and_normalizes_format(self):
|
|
83
|
+
base = AsyncMock()
|
|
84
|
+
base.post.return_value = _envelope("00ff", "hex", source="csprng", is_quantum=False)
|
|
85
|
+
client = QrngClient(base)
|
|
86
|
+
|
|
87
|
+
result = await client.get_entropy(2, format=" HEX ", allow_csprng=True)
|
|
88
|
+
|
|
89
|
+
base.post.assert_awaited_once_with(
|
|
90
|
+
"/api/v1/qrng/entropy",
|
|
91
|
+
json_data={"bytes": 2, "format": "hex"},
|
|
92
|
+
headers={ALLOW_CSPRNG_HEADER: "true"},
|
|
93
|
+
)
|
|
94
|
+
assert result.source == "csprng"
|
|
95
|
+
assert result.is_quantum is False
|
|
96
|
+
|
|
97
|
+
@pytest.mark.asyncio
|
|
98
|
+
@pytest.mark.parametrize(
|
|
99
|
+
"bytes_count,fmt",
|
|
100
|
+
[(0, "raw"), (15, "uuid"), (6, "int32"), (12, "int64")],
|
|
101
|
+
)
|
|
102
|
+
async def test_rejects_invalid_byte_counts_before_sending(self, bytes_count, fmt):
|
|
103
|
+
base = AsyncMock()
|
|
104
|
+
client = QrngClient(base)
|
|
105
|
+
|
|
106
|
+
with pytest.raises(ValueError):
|
|
107
|
+
await client.get_entropy(bytes_count, format=fmt)
|
|
108
|
+
|
|
109
|
+
base.post.assert_not_awaited()
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class TestSyncProxy:
|
|
113
|
+
def test_sync_client_exposes_qrng(self):
|
|
114
|
+
client = QuantumAPISyncClient(api_key="qapi_test")
|
|
115
|
+
try:
|
|
116
|
+
assert hasattr(client.qrng, "get_entropy")
|
|
117
|
+
finally:
|
|
118
|
+
client.close()
|
|
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
|