quantumapi 0.23.0__tar.gz → 0.24.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. {quantumapi-0.23.0/quantumapi.egg-info → quantumapi-0.24.0}/PKG-INFO +40 -1
  2. {quantumapi-0.23.0 → quantumapi-0.24.0}/README.md +39 -0
  3. {quantumapi-0.23.0 → quantumapi-0.24.0}/pyproject.toml +1 -1
  4. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/base.py +25 -0
  5. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/secrets.py +219 -37
  6. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/models/__init__.py +12 -0
  7. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/models/secrets.py +127 -12
  8. {quantumapi-0.23.0 → quantumapi-0.24.0/quantumapi.egg-info}/PKG-INFO +40 -1
  9. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi.egg-info/SOURCES.txt +1 -0
  10. {quantumapi-0.23.0 → quantumapi-0.24.0}/tests/test_parity.py +0 -150
  11. quantumapi-0.24.0/tests/test_secret_history_share.py +382 -0
  12. {quantumapi-0.23.0 → quantumapi-0.24.0}/LICENSE +0 -0
  13. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/__init__.py +0 -0
  14. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/__init__.py +0 -0
  15. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/applications.py +0 -0
  16. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/async_client.py +0 -0
  17. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/audit.py +0 -0
  18. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/encryption.py +0 -0
  19. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/end_users.py +0 -0
  20. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/health.py +0 -0
  21. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/keys.py +0 -0
  22. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/qrng.py +0 -0
  23. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/resource_groups.py +0 -0
  24. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/roles.py +0 -0
  25. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/sync_client.py +0 -0
  26. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/client/transit.py +0 -0
  27. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/errors/__init__.py +0 -0
  28. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/errors/exceptions.py +0 -0
  29. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/models/applications.py +0 -0
  30. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/models/audit.py +0 -0
  31. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/models/encryption.py +0 -0
  32. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/models/end_users.py +0 -0
  33. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/models/health.py +0 -0
  34. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/models/keys.py +0 -0
  35. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/models/qrng.py +0 -0
  36. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/models/resource_groups.py +0 -0
  37. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/models/roles.py +0 -0
  38. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/models/transit.py +0 -0
  39. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi/py.typed +0 -0
  40. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi.egg-info/dependency_links.txt +0 -0
  41. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi.egg-info/requires.txt +0 -0
  42. {quantumapi-0.23.0 → quantumapi-0.24.0}/quantumapi.egg-info/top_level.txt +0 -0
  43. {quantumapi-0.23.0 → quantumapi-0.24.0}/setup.cfg +0 -0
  44. {quantumapi-0.23.0 → quantumapi-0.24.0}/tests/test_audit.py +0 -0
  45. {quantumapi-0.23.0 → quantumapi-0.24.0}/tests/test_data_keys.py +0 -0
  46. {quantumapi-0.23.0 → quantumapi-0.24.0}/tests/test_end_users.py +0 -0
  47. {quantumapi-0.23.0 → quantumapi-0.24.0}/tests/test_exceptions.py +0 -0
  48. {quantumapi-0.23.0 → quantumapi-0.24.0}/tests/test_models.py +0 -0
  49. {quantumapi-0.23.0 → quantumapi-0.24.0}/tests/test_qrng.py +0 -0
  50. {quantumapi-0.23.0 → quantumapi-0.24.0}/tests/test_transit.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quantumapi
3
- Version: 0.23.0
3
+ Version: 0.24.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
@@ -260,6 +260,45 @@ await client.secrets.update(
260
260
 
261
261
  # Delete secret
262
262
  await client.secrets.delete(secret_id="secret-id")
263
+
264
+ # Version history, newest first. Values are included, so this needs reveal
265
+ # permission. max_versions is 1-20 (None = the API default of 5).
266
+ history = await client.secrets.list_versions(secret_id, max_versions=10)
267
+ for v in history.versions:
268
+ print(v.version, v.changed_by, v.created_at)
269
+
270
+ # The secret as it was at version 1
271
+ v1 = await client.secrets.get_version(secret_id, 1)
272
+
273
+ # Roll back to version 1: reads it and writes its value back as a new version,
274
+ # audited as a restore. Two requests (not atomic); only the value is restored.
275
+ await client.secrets.rollback(secret_id, 1)
276
+ ```
277
+
278
+ #### Share links
279
+
280
+ ```python
281
+ # Encrypted, time-limited link for someone outside the tenant
282
+ link = await client.secrets.create_shared_link(
283
+ secret_id,
284
+ expires_in_hours=48, # 1-720, default 24
285
+ max_access_count=5, # None = unlimited until it expires
286
+ password="optional-password",
287
+ )
288
+ # The token is returned only now: the server does not store it.
289
+ print(client.secrets.share_url(link.token))
290
+ # -> https://portal.quantumapi.eu/share/<token> (derived from base_url, or pass your portal URL)
291
+
292
+ # Links of a secret. status is a string (Active, Revoked, Expired, Exhausted, Retired, ...);
293
+ # token is always "" here.
294
+ links = await client.secrets.list_shared_links(secret_id)
295
+ await client.secrets.revoke_shared_link(links.links[0].id)
296
+
297
+ # Open a link as the recipient (public endpoint: no API key sent, never retried,
298
+ # counts one access). Errors: NotFoundError (unknown or expired), ValidationError with
299
+ # error_code password_required / invalid_password / link_exhausted, QuantumAPIError
300
+ # with error_code link_retired (HTTP 410).
301
+ opened = await client.secrets.open_shared_link(link.token, password="optional-password")
263
302
  ```
264
303
 
265
304
  ### Users Client
@@ -219,6 +219,45 @@ await client.secrets.update(
219
219
 
220
220
  # Delete secret
221
221
  await client.secrets.delete(secret_id="secret-id")
222
+
223
+ # Version history, newest first. Values are included, so this needs reveal
224
+ # permission. max_versions is 1-20 (None = the API default of 5).
225
+ history = await client.secrets.list_versions(secret_id, max_versions=10)
226
+ for v in history.versions:
227
+ print(v.version, v.changed_by, v.created_at)
228
+
229
+ # The secret as it was at version 1
230
+ v1 = await client.secrets.get_version(secret_id, 1)
231
+
232
+ # Roll back to version 1: reads it and writes its value back as a new version,
233
+ # audited as a restore. Two requests (not atomic); only the value is restored.
234
+ await client.secrets.rollback(secret_id, 1)
235
+ ```
236
+
237
+ #### Share links
238
+
239
+ ```python
240
+ # Encrypted, time-limited link for someone outside the tenant
241
+ link = await client.secrets.create_shared_link(
242
+ secret_id,
243
+ expires_in_hours=48, # 1-720, default 24
244
+ max_access_count=5, # None = unlimited until it expires
245
+ password="optional-password",
246
+ )
247
+ # The token is returned only now: the server does not store it.
248
+ print(client.secrets.share_url(link.token))
249
+ # -> https://portal.quantumapi.eu/share/<token> (derived from base_url, or pass your portal URL)
250
+
251
+ # Links of a secret. status is a string (Active, Revoked, Expired, Exhausted, Retired, ...);
252
+ # token is always "" here.
253
+ links = await client.secrets.list_shared_links(secret_id)
254
+ await client.secrets.revoke_shared_link(links.links[0].id)
255
+
256
+ # Open a link as the recipient (public endpoint: no API key sent, never retried,
257
+ # counts one access). Errors: NotFoundError (unknown or expired), ValidationError with
258
+ # error_code password_required / invalid_password / link_exhausted, QuantumAPIError
259
+ # with error_code link_retired (HTTP 410).
260
+ opened = await client.secrets.open_shared_link(link.token, password="optional-password")
222
261
  ```
223
262
 
224
263
  ### Users Client
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "quantumapi"
7
- version = "0.23.0"
7
+ version = "0.24.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"
@@ -344,6 +344,31 @@ class BaseClient:
344
344
  """Make DELETE request."""
345
345
  return await self._request("DELETE", endpoint, params=params, headers=headers)
346
346
 
347
+ async def post_anonymous(
348
+ self,
349
+ endpoint: str,
350
+ json_data: Optional[Dict[str, Any]] = None,
351
+ ) -> Dict[str, Any]:
352
+ """
353
+ Make a single POST request without the ``X-Api-Key`` header.
354
+
355
+ For public endpoints such as ``POST /api/v1/share/{token}``. It is never
356
+ retried, because each call can have a side effect (opening a share link
357
+ counts one access).
358
+ """
359
+ url = self._build_url(endpoint)
360
+ if self.enable_logging:
361
+ logger.debug(f"Request (anonymous): POST {url}")
362
+ request = self._client.build_request("POST", url, json=json_data)
363
+ request.headers.pop("X-Api-Key", None)
364
+ try:
365
+ response = await self._client.send(request)
366
+ except httpx.TimeoutException as e:
367
+ raise TimeoutError("Request timed out") from e
368
+ except httpx.NetworkError as e:
369
+ raise NetworkError("Network error occurred", original_error=e) from e
370
+ return await self._handle_response(response)
371
+
347
372
  async def close(self) -> None:
348
373
  """Close HTTP client connection."""
349
374
  await self._client.aclose()
@@ -1,26 +1,63 @@
1
1
  """Secrets client for QuantumAPI SDK."""
2
2
 
3
3
  import warnings
4
- from typing import Any, Dict, List, Optional
4
+ from typing import Any, Dict, List, Optional, Union
5
+ from urllib.parse import quote, urlparse
5
6
  from uuid import UUID
6
7
 
7
8
  from quantumapi.client.base import BaseClient
8
9
  from quantumapi.models.secrets import (
10
+ MAX_SECRET_HISTORY_VERSIONS,
9
11
  CreateSecretRequest,
12
+ CreateSharedLinkRequest,
10
13
  ImportSecretsRequest,
11
14
  ImportSecretsResponse,
12
15
  ImportSecretItem,
13
16
  SecretInsightResponse,
17
+ OpenedSharedLinkResponse,
14
18
  SecretListResponse,
19
+ SecretResponse,
15
20
  SecretVersionListResponse,
16
21
  SecretWithValueResponse,
22
+ SharedLinkListResponse,
17
23
  SharedLinkResponse,
18
- ShareSecretRequest,
19
24
  UpdateSecretRequest,
20
25
  UpdateSecretValueRequest,
21
26
  )
22
27
 
23
28
 
29
+ #: Default tenant portal, where share links are opened.
30
+ DEFAULT_PORTAL_URL = "https://portal.quantumapi.eu"
31
+
32
+
33
+ def build_share_url(token: str, portal_base_url: str = DEFAULT_PORTAL_URL) -> str:
34
+ """Viewer URL of a share link: ``<portal_base_url>/share/<token>``."""
35
+ return f"{portal_base_url.rstrip('/')}/share/{quote(token, safe='')}"
36
+
37
+
38
+ def portal_url_from_api_base(api_base_url: str) -> str:
39
+ """Portal origin for an API base URL, the way the ``qapi`` CLI derives it.
40
+
41
+ ``https://api.<domain>`` becomes ``https://portal.<domain>``; anything else
42
+ gives :data:`DEFAULT_PORTAL_URL`.
43
+ """
44
+ parsed = urlparse(api_base_url)
45
+ if not parsed.scheme or not parsed.netloc.startswith("api."):
46
+ return DEFAULT_PORTAL_URL
47
+ return f"{parsed.scheme}://portal.{parsed.netloc[4:]}"
48
+
49
+
50
+ def _ttl_to_hours(ttl: Optional[str]) -> Optional[int]:
51
+ if not ttl:
52
+ return None
53
+ t = ttl.strip().lower()
54
+ factor = 24 if t.endswith("d") else 1
55
+ digits = t.rstrip("dh")
56
+ if not digits.isdigit():
57
+ raise ValueError(f"Unsupported ttl {ttl!r}: use hours ('24h') or days ('7d')")
58
+ return int(digits) * factor
59
+
60
+
24
61
  class SecretsClient:
25
62
  """Client for secrets vault operations."""
26
63
 
@@ -141,6 +178,7 @@ class SecretsClient:
141
178
  self,
142
179
  secret_id: UUID,
143
180
  include: Optional[List[str]] = None,
181
+ version: Optional[int] = None,
144
182
  ) -> SecretWithValueResponse:
145
183
  """
146
184
  Get secret by ID (includes value).
@@ -154,6 +192,7 @@ class SecretsClient:
154
192
  ``notes``, ``labels``, ``expiresAt``, ``folderId``, ``isActive``,
155
193
  ``isFavorite``, ``hasTotp``, ``isTravelSafe``, ``createdAt``,
156
194
  ``updatedAt``, ``createdBy``, ``updatedBy``.
195
+ version: Optional version number; returns that version's value.
157
196
 
158
197
  Returns:
159
198
  Secret metadata and decrypted value.
@@ -164,9 +203,11 @@ class SecretsClient:
164
203
  >>> with_meta = await client.secrets.get(secret_id, include=["customFields", "notes"])
165
204
  >>> print(with_meta.custom_fields)
166
205
  """
167
- params: Dict[str, str] = {}
206
+ params: Dict[str, Union[str, int]] = {}
168
207
  if include:
169
208
  params["include"] = ",".join(include)
209
+ if version is not None:
210
+ params["version"] = version
170
211
  response = await self._client.get(f"/api/v1/secrets/{secret_id}", params=params or None)
171
212
  return SecretWithValueResponse(**response)
172
213
 
@@ -184,7 +225,7 @@ class SecretsClient:
184
225
  custom_fields: Optional[List[Dict[str, Any]]] = None,
185
226
  is_favorite: Optional[bool] = None,
186
227
  totp_secret: Optional[str] = None,
187
- ) -> SecretWithValueResponse:
228
+ ) -> SecretResponse:
188
229
  """
189
230
  Update secret metadata.
190
231
 
@@ -229,13 +270,13 @@ class SecretsClient:
229
270
  f"/api/v1/secrets/{secret_id}",
230
271
  json_data=request.model_dump(exclude_none=True)
231
272
  )
232
- return SecretWithValueResponse(**response)
273
+ return SecretResponse(**response)
233
274
 
234
275
  async def update_value(
235
276
  self,
236
277
  secret_id: UUID,
237
278
  value: str,
238
- ) -> SecretWithValueResponse:
279
+ ) -> SecretResponse:
239
280
  """
240
281
  Update secret value (creates new version).
241
282
 
@@ -247,7 +288,8 @@ class SecretsClient:
247
288
  value: New secret value
248
289
 
249
290
  Returns:
250
- Updated secret metadata
291
+ Updated secret metadata (the new ``version``). The API does not echo
292
+ the value back; call :meth:`get` to read it.
251
293
 
252
294
  Example:
253
295
  >>> secret = await client.secrets.update_value(
@@ -258,9 +300,9 @@ class SecretsClient:
258
300
  request = UpdateSecretValueRequest(value=value)
259
301
  response = await self._client.put(
260
302
  f"/api/v1/secrets/{secret_id}/value",
261
- json_data=request.model_dump()
303
+ json_data=request.model_dump(by_alias=True, exclude_none=True)
262
304
  )
263
- return SecretWithValueResponse(**response)
305
+ return SecretResponse(**response)
264
306
 
265
307
  async def delete(self, secret_id: UUID) -> None:
266
308
  """
@@ -324,45 +366,130 @@ class SecretsClient:
324
366
  )
325
367
  await self.activate(secret_id)
326
368
 
327
- async def list_versions(self, secret_id: UUID) -> SecretVersionListResponse:
369
+ async def list_versions(
370
+ self,
371
+ secret_id: UUID,
372
+ max_versions: Optional[int] = None,
373
+ ) -> SecretVersionListResponse:
328
374
  """
329
- List all versions of a secret.
375
+ Version history of a secret, newest first (``GET /secrets/{id}/history``).
376
+
377
+ Every entry includes its decrypted value, so the caller needs reveal
378
+ permission on the secret.
330
379
 
331
380
  Args:
332
381
  secret_id: Secret ID
382
+ max_versions: 1-20 versions; ``None`` uses the API default (5)
333
383
 
334
384
  Returns:
335
- List of secret versions
385
+ The secret ID and its versions, newest first
386
+
387
+ Raises:
388
+ ValueError: ``max_versions`` is outside 1-20 (no request is sent)
336
389
 
337
390
  Example:
338
- >>> versions = await client.secrets.list_versions(secret_id)
339
- >>> for v in versions.versions:
340
- ... print(v.version)
391
+ >>> history = await client.secrets.list_versions(secret_id, max_versions=10)
392
+ >>> for v in history.versions:
393
+ ... print(v.version, v.changed_by, v.created_at)
341
394
  """
342
- response = await self._client.get(f"/api/v1/secrets/{secret_id}/versions")
395
+ params: Optional[Dict[str, int]] = None
396
+ if max_versions is not None:
397
+ if (
398
+ isinstance(max_versions, bool)
399
+ or not isinstance(max_versions, int)
400
+ or not 1 <= max_versions <= MAX_SECRET_HISTORY_VERSIONS
401
+ ):
402
+ raise ValueError(
403
+ f"max_versions must be an integer between 1 and {MAX_SECRET_HISTORY_VERSIONS}"
404
+ )
405
+ params = {"maxVersions": max_versions}
406
+ response = await self._client.get(
407
+ f"/api/v1/secrets/{secret_id}/history", params=params
408
+ )
343
409
  return SecretVersionListResponse(**response)
344
410
 
345
- async def rollback(self, secret_id: UUID, version: int) -> SecretWithValueResponse:
411
+ async def get_version(self, secret_id: UUID, version: int) -> SecretWithValueResponse:
346
412
  """
347
- Roll back a secret to a previous version.
413
+ The secret as it was at ``version``, with that version's value
414
+ (``GET /secrets/{id}?version=N``).
348
415
 
349
- Creates a new version with the value from the specified version.
416
+ Args:
417
+ secret_id: Secret ID
418
+ version: Version number (positive)
419
+ """
420
+ _check_version(version)
421
+ return await self.get(secret_id, version=version)
422
+
423
+ async def rollback(self, secret_id: UUID, version: int) -> SecretResponse:
424
+ """
425
+ Restore the value of an earlier version.
426
+
427
+ Reads ``version`` and writes its value back as a new version with
428
+ ``restoredFromVersion``, so the API audits it as a restore. The API has no
429
+ rollback endpoint: this is two requests, not one atomic step, and only the
430
+ value is restored (metadata keeps its current state).
350
431
 
351
432
  Args:
352
433
  secret_id: Secret ID
353
- version: Version number to roll back to
434
+ version: Version number to roll back to (positive)
354
435
 
355
436
  Returns:
356
- Updated secret metadata
437
+ The secret's metadata after the write (the new version)
438
+
439
+ Raises:
440
+ ValueError: ``version`` is not positive (no request is sent)
357
441
 
358
442
  Example:
359
443
  >>> secret = await client.secrets.rollback(secret_id, version=2)
360
444
  """
445
+ _check_version(version)
446
+ old = await self._client.get(
447
+ f"/api/v1/secrets/{secret_id}", params={"version": version}
448
+ )
449
+ request = UpdateSecretValueRequest(value=old["value"], restored_from_version=version)
450
+ response = await self._client.put(
451
+ f"/api/v1/secrets/{secret_id}/value",
452
+ json_data=request.model_dump(by_alias=True, exclude_none=True),
453
+ )
454
+ return SecretResponse(**response)
455
+
456
+ async def create_shared_link(
457
+ self,
458
+ secret_id: UUID,
459
+ expires_in_hours: Optional[int] = None,
460
+ max_access_count: Optional[int] = None,
461
+ password: Optional[str] = None,
462
+ ) -> SharedLinkResponse:
463
+ """
464
+ Create an encrypted, time-limited share link (``POST /api/v1/vault/share``).
465
+
466
+ The response carries the link ``token`` only this once: the server does not
467
+ store it. Build the viewer URL with :meth:`share_url`.
468
+
469
+ Args:
470
+ secret_id: Secret to share
471
+ expires_in_hours: Lifetime, 1-720 hours (``None`` = API default, 24)
472
+ max_access_count: How many times it can be opened (``None`` = unlimited)
473
+ password: Password the recipient must enter (optional)
474
+
475
+ Raises:
476
+ pydantic.ValidationError: ``expires_in_hours`` is outside 1-720
477
+
478
+ Example:
479
+ >>> link = await client.secrets.create_shared_link(secret_id, expires_in_hours=48)
480
+ >>> print(client.secrets.share_url(link.token))
481
+ """
482
+ request = CreateSharedLinkRequest(
483
+ secret_id=secret_id,
484
+ expires_in_hours=expires_in_hours,
485
+ max_access_count=max_access_count,
486
+ password=password or None,
487
+ )
361
488
  response = await self._client.post(
362
- f"/api/v1/secrets/{secret_id}/rollback",
363
- json_data={"version": version},
489
+ "/api/v1/vault/share",
490
+ json_data=request.model_dump(mode="json", by_alias=True, exclude_none=True),
364
491
  )
365
- return SecretWithValueResponse(**response)
492
+ return SharedLinkResponse(**response)
366
493
 
367
494
  async def share(
368
495
  self,
@@ -373,24 +500,74 @@ class SecretsClient:
373
500
  """
374
501
  Create a shareable link for a secret.
375
502
 
376
- Args:
377
- secret_id: Secret ID
378
- max_views: Maximum number of views (0 = unlimited)
379
- ttl: Time-to-live string (e.g., "24h", "7d")
503
+ .. deprecated::
504
+ Use :meth:`create_shared_link`. This posted to ``/secrets/{id}/share``,
505
+ which the API never served; it now forwards to ``POST /api/v1/vault/share``
506
+ (``max_views`` -> ``max_access_count``, ``ttl`` "24h"/"7d" -> hours).
507
+ """
508
+ warnings.warn(
509
+ "secrets.share() is deprecated; use secrets.create_shared_link(). See issue #854.",
510
+ DeprecationWarning,
511
+ stacklevel=2,
512
+ )
513
+ return await self.create_shared_link(
514
+ secret_id,
515
+ expires_in_hours=_ttl_to_hours(ttl),
516
+ max_access_count=max_views if max_views > 0 else None,
517
+ )
518
+
519
+ async def list_shared_links(self, secret_id: UUID) -> SharedLinkListResponse:
520
+ """
521
+ Share links of a secret, newest first
522
+ (``GET /api/v1/vault/share/by-secret/{secretId}``).
523
+
524
+ ``token`` is always empty in this list (the server no longer stores tokens)
525
+ and ``status`` is a plain string (``Active``, ``Revoked``, ``Expired``,
526
+ ``Exhausted``, ``Retired`` or any newer status).
527
+ """
528
+ response = await self._client.get(f"/api/v1/vault/share/by-secret/{secret_id}")
529
+ return SharedLinkListResponse(**response)
530
+
531
+ async def revoke_shared_link(self, link_id: UUID) -> bool:
532
+ """
533
+ Revoke a share link (``DELETE /api/v1/vault/share/{linkId}``).
380
534
 
381
535
  Returns:
382
- Shareable link response with URL and expiry
536
+ ``True`` when the API confirms the revocation
537
+ """
538
+ response = await self._client.delete(f"/api/v1/vault/share/{link_id}")
539
+ return bool(response.get("revoked", False))
383
540
 
384
- Example:
385
- >>> link = await client.secrets.share(secret_id, max_views=5, ttl="24h")
386
- >>> print(link.url)
541
+ async def open_shared_link(
542
+ self, token: str, password: Optional[str] = None
543
+ ) -> OpenedSharedLinkResponse:
387
544
  """
388
- request = ShareSecretRequest(max_views=max_views, ttl=ttl)
389
- response = await self._client.post(
390
- f"/api/v1/secrets/{secret_id}/share",
391
- json_data=request.model_dump(exclude_none=True),
545
+ Open a share link as its recipient would (public ``POST /api/v1/share/{token}``).
546
+
547
+ Sent without the API key and never retried: each call counts as one access.
548
+
549
+ Raises:
550
+ NotFoundError: unknown or expired link (``link_not_found``)
551
+ ValidationError: ``error_code`` ``link_exhausted``, ``password_required``
552
+ or ``invalid_password`` (HTTP 400)
553
+ QuantumAPIError: ``error_code`` ``link_retired`` (HTTP 410)
554
+ """
555
+ body: Dict[str, Any] = {"password": password} if password else {}
556
+ response = await self._client.post_anonymous(
557
+ f"/api/v1/share/{quote(token, safe='')}", json_data=body
392
558
  )
393
- return SharedLinkResponse(**response)
559
+ return OpenedSharedLinkResponse(**response)
560
+
561
+ def share_url(self, token: str, portal_base_url: Optional[str] = None) -> str:
562
+ """
563
+ Viewer URL of a share link: ``<portal>/share/<token>``.
564
+
565
+ Without ``portal_base_url`` the portal is derived from the API base URL
566
+ (``https://api.example.com`` -> ``https://portal.example.com``), falling
567
+ back to ``https://portal.quantumapi.eu``.
568
+ """
569
+ portal = portal_base_url or portal_url_from_api_base(self._client.base_url)
570
+ return build_share_url(token, portal)
394
571
 
395
572
  async def insights(self, secret_id: UUID) -> SecretInsightResponse:
396
573
  """
@@ -442,3 +619,8 @@ class SecretsClient:
442
619
  json_data=request.model_dump(exclude_none=True),
443
620
  )
444
621
  return ImportSecretsResponse(**response)
622
+
623
+
624
+ def _check_version(version: int) -> None:
625
+ if isinstance(version, bool) or not isinstance(version, int) or version < 1:
626
+ raise ValueError("version must be a positive integer")
@@ -60,6 +60,7 @@ from quantumapi.models.resource_groups import (
60
60
  )
61
61
  from quantumapi.models.secrets import (
62
62
  CreateSecretRequest,
63
+ CreateSharedLinkRequest,
63
64
  ImportSecretItem,
64
65
  ImportSecretsRequest,
65
66
  ImportSecretsResponse,
@@ -69,7 +70,12 @@ from quantumapi.models.secrets import (
69
70
  SecretVersion,
70
71
  SecretVersionListResponse,
71
72
  SecretWithValueResponse,
73
+ MAX_SECRET_HISTORY_VERSIONS,
74
+ OpenedSharedLinkResponse,
75
+ SHARED_LINK_STATUSES,
76
+ SharedLinkListResponse,
72
77
  SharedLinkResponse,
78
+ SharedLinkSummary,
73
79
  ShareSecretRequest,
74
80
  UpdateSecretRequest,
75
81
  UpdateSecretValueRequest,
@@ -127,6 +133,12 @@ __all__ = [
127
133
  "SecretVersionListResponse",
128
134
  "ShareSecretRequest",
129
135
  "SharedLinkResponse",
136
+ "CreateSharedLinkRequest",
137
+ "SharedLinkSummary",
138
+ "SharedLinkListResponse",
139
+ "OpenedSharedLinkResponse",
140
+ "MAX_SECRET_HISTORY_VERSIONS",
141
+ "SHARED_LINK_STATUSES",
130
142
  "SecretInsightResponse",
131
143
  "ImportSecretItem",
132
144
  "ImportSecretsRequest",