quantumapi 0.26.0__tar.gz → 0.27.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.26.0/quantumapi.egg-info → quantumapi-0.27.0}/PKG-INFO +139 -13
- {quantumapi-0.26.0 → quantumapi-0.27.0}/README.md +138 -12
- {quantumapi-0.26.0 → quantumapi-0.27.0}/pyproject.toml +1 -1
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/__init__.py +1 -1
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/__init__.py +6 -0
- quantumapi-0.27.0/quantumapi/client/api_keys.py +73 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/async_client.py +6 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/encryption.py +12 -5
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/keys.py +130 -74
- quantumapi-0.27.0/quantumapi/client/pki.py +132 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/secrets.py +35 -24
- quantumapi-0.27.0/quantumapi/client/ssh.py +108 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/sync_client.py +3 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/__init__.py +68 -0
- quantumapi-0.27.0/quantumapi/models/api_keys.py +134 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/encryption.py +27 -3
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/keys.py +95 -8
- quantumapi-0.27.0/quantumapi/models/pki.py +171 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/secrets.py +63 -12
- quantumapi-0.27.0/quantumapi/models/ssh.py +164 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0/quantumapi.egg-info}/PKG-INFO +139 -13
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi.egg-info/SOURCES.txt +8 -0
- quantumapi-0.27.0/tests/test_keys_encryption_secrets_contract.py +601 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_parity.py +2 -2
- quantumapi-0.27.0/tests/test_pki_ssh_api_keys.py +500 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/LICENSE +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/applications.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/audit.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/base.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/compliance.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/dynamic_secrets.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/end_users.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/external_key_stores.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/health.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/log_streams.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/qrng.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/resource_groups.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/roles.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/team.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/transit.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/client/usage.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/errors/__init__.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/errors/exceptions.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/applications.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/audit.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/compliance.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/dynamic_secrets.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/end_users.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/external_key_stores.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/health.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/log_streams.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/qrng.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/resource_groups.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/roles.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/team.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/transit.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/models/usage.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi/py.typed +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi.egg-info/dependency_links.txt +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi.egg-info/requires.txt +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/quantumapi.egg-info/top_level.txt +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/setup.cfg +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_applications.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_audit.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_compliance_logstreams_usage.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_data_keys.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_dynamic_secrets.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_end_users.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_exceptions.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_external_key_stores.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_models.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_qrng.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_secret_history_share.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_team.py +0 -0
- {quantumapi-0.26.0 → quantumapi-0.27.0}/tests/test_transit.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: quantumapi
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.27.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
|
|
@@ -56,6 +56,8 @@ Official Python SDK for [QuantumAPI](https://quantumapi.eu) - The European quant
|
|
|
56
56
|
- 👤 **User Management** - Create and manage end-users with roles
|
|
57
57
|
- 🔍 **Audit Logs** - Query comprehensive audit trails
|
|
58
58
|
- 📈 **Usage** - Read the tenant's storage usage (`client.usage`)
|
|
59
|
+
- 📜 **PKI and SSH CA** - Run X.509 and SSH certificate authorities (`client.pki`, `client.ssh`)
|
|
60
|
+
- 🗝️ **API Keys** - Create, restrict and revoke the tenant's API keys (`client.api_keys`)
|
|
59
61
|
- 🚀 **Async/Await Support** - Full async support with httpx
|
|
60
62
|
- ⚡ **Automatic Retries** - Exponential backoff for transient failures
|
|
61
63
|
- 📊 **Rate Limiting** - Client-side rate limit tracking
|
|
@@ -157,18 +159,21 @@ plaintext = await client.encryption.decrypt(
|
|
|
157
159
|
encrypted_payload=result.encrypted_payload
|
|
158
160
|
)
|
|
159
161
|
|
|
160
|
-
# Sign data
|
|
162
|
+
# Sign data (data is base64)
|
|
163
|
+
import base64
|
|
164
|
+
data = base64.b64encode(b"message to sign").decode()
|
|
161
165
|
signature = await client.encryption.sign(
|
|
162
|
-
data=
|
|
166
|
+
data=data,
|
|
163
167
|
key_id="signing-key-id"
|
|
164
168
|
)
|
|
165
169
|
|
|
166
170
|
# Verify signature
|
|
167
|
-
|
|
168
|
-
data=
|
|
171
|
+
result = await client.encryption.verify(
|
|
172
|
+
data=data,
|
|
169
173
|
signature=signature.signature,
|
|
170
174
|
key_id="signing-key-id"
|
|
171
175
|
)
|
|
176
|
+
print(result.is_valid)
|
|
172
177
|
```
|
|
173
178
|
|
|
174
179
|
### Audit Client
|
|
@@ -203,30 +208,40 @@ key = await client.keys.generate(
|
|
|
203
208
|
set_as_default=True
|
|
204
209
|
)
|
|
205
210
|
|
|
206
|
-
# List keys
|
|
211
|
+
# List keys (sent as ?type=encryption&page=1&pageSize=50)
|
|
207
212
|
keys = await client.keys.list(
|
|
208
213
|
key_type="encryption",
|
|
209
214
|
page=1,
|
|
210
|
-
page_size=50
|
|
215
|
+
page_size=50,
|
|
216
|
+
include_inactive=False,
|
|
211
217
|
)
|
|
218
|
+
print(keys.total_count, keys.has_more)
|
|
212
219
|
|
|
213
220
|
# Get key details
|
|
214
221
|
key = await client.keys.get(key_id="key-id")
|
|
215
222
|
|
|
216
|
-
# Rotate key
|
|
217
|
-
|
|
223
|
+
# Rotate key: new version, same key id
|
|
224
|
+
rotation = await client.keys.rotate(key_id="key-id")
|
|
225
|
+
print(rotation.previous_version, "->", rotation.new_version, rotation.rotated_at)
|
|
218
226
|
|
|
219
|
-
#
|
|
220
|
-
await client.keys.
|
|
227
|
+
# Update metadata (only the arguments you pass are sent)
|
|
228
|
+
await client.keys.update("key-id", description="Orders KEK", labels=["prod"], is_favorite=True)
|
|
229
|
+
|
|
230
|
+
# Export the public key (PEM by default)
|
|
231
|
+
pem = await client.keys.export_public_key("key-id")
|
|
232
|
+
|
|
233
|
+
# Schedule deletion after a 7-90 day grace period (default 30)
|
|
234
|
+
scheduled = await client.keys.delete(key_id="key-id", schedule_days=30)
|
|
235
|
+
print(scheduled.scheduled_deletion_date)
|
|
221
236
|
|
|
222
237
|
# Set default key
|
|
223
|
-
await client.keys.set_default(key_id="key-id"
|
|
238
|
+
await client.keys.set_default(key_id="key-id")
|
|
224
239
|
```
|
|
225
240
|
|
|
226
241
|
### Secrets Client
|
|
227
242
|
|
|
228
243
|
```python
|
|
229
|
-
# Create secret
|
|
244
|
+
# Create secret: returns the metadata (SecretResponse); the value is not echoed back
|
|
230
245
|
secret = await client.secrets.create(
|
|
231
246
|
name="api-key",
|
|
232
247
|
value="secret_value",
|
|
@@ -570,6 +585,117 @@ await client.external_key_stores.disconnect(store.id) # kill switch; reconnect(
|
|
|
570
585
|
A 409 `credential_limit` (too many access keys) raises `ConflictError`; a 400
|
|
571
586
|
`invalid_configuration` raises `ValidationError` with the reason in `message`.
|
|
572
587
|
|
|
588
|
+
### PKI Client (X.509)
|
|
589
|
+
|
|
590
|
+
Certificate authorities and certificates under `/api/v1/pki`. Keys are RSA (CA 4096 bits, certificates
|
|
591
|
+
2048 bits by default). The CA private key is encrypted at rest and never returned; a certificate's private
|
|
592
|
+
key is returned once, by `issue_certificate`.
|
|
593
|
+
|
|
594
|
+
```python
|
|
595
|
+
from quantumapi.models import CreateCertificateAuthorityRequest, IssueCertificateRequest
|
|
596
|
+
|
|
597
|
+
# Root CA (10 years by default). Set parent_ca_id for an intermediate CA (5 years by default).
|
|
598
|
+
ca = await client.pki.create_ca(
|
|
599
|
+
CreateCertificateAuthorityRequest(name="acme-root", organization="Acme", country="ES")
|
|
600
|
+
)
|
|
601
|
+
|
|
602
|
+
cert = await client.pki.issue_certificate(
|
|
603
|
+
IssueCertificateRequest(
|
|
604
|
+
ca_id=ca.id,
|
|
605
|
+
common_name="api.acme.eu",
|
|
606
|
+
dns_names=["api.acme.eu"],
|
|
607
|
+
ip_addresses=["10.0.0.5"],
|
|
608
|
+
validity_days=90, # default 365, capped at the CA's expiry
|
|
609
|
+
)
|
|
610
|
+
)
|
|
611
|
+
# The private key is shown ONLY ONCE, here.
|
|
612
|
+
open("api.crt", "w").write(cert.certificate_pem)
|
|
613
|
+
open("api.key", "w").write(cert.private_key_pem)
|
|
614
|
+
|
|
615
|
+
certs = await client.pki.list_certificates(ca_id=ca.id, status="Active") # both filters optional
|
|
616
|
+
for c in certs.certificates:
|
|
617
|
+
print(c.serial_number, c.common_name, c.status, c.not_after)
|
|
618
|
+
|
|
619
|
+
detail = await client.pki.get_certificate(cert.id) # PEM, SANs, revocation data
|
|
620
|
+
result = await client.pki.revoke_certificate(cert.id, reason="keyCompromise") # rebuilds the CA's CRL
|
|
621
|
+
print(result.revoked, result.serial_number)
|
|
622
|
+
|
|
623
|
+
ca_pem = await client.pki.get_ca_certificate(ca.id) # PEM text
|
|
624
|
+
crl_pem = await client.pki.get_crl(ca.id) # PEM text, or None before the first revocation
|
|
625
|
+
cas = await client.pki.list_cas() # cas.authorities
|
|
626
|
+
await client.pki.disable_ca(ca.id) # and enable_ca(ca.id); a disabled CA cannot issue
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
A duplicate CA name raises `ConflictError`; an unknown or disabled CA `NotFoundError`; an expired CA or
|
|
630
|
+
revoking twice raises `ValidationError` (`ca_expired`, `already_revoked`).
|
|
631
|
+
|
|
632
|
+
### SSH Client
|
|
633
|
+
|
|
634
|
+
SSH certificate authorities and user certificates under `/api/v1/ssh`. Servers trust the CA public key
|
|
635
|
+
(`TrustedUserCAKeys`); users get short-lived certificates for their own public keys.
|
|
636
|
+
|
|
637
|
+
```python
|
|
638
|
+
from quantumapi.models import CreateSshCaRequest, SignSshKeyRequest, UpdateSshCaRequest
|
|
639
|
+
|
|
640
|
+
# key_type: ed25519 (default), ecdsa-p256, ecdsa-p384 or rsa-4096 (SSH_CA_KEY_TYPES).
|
|
641
|
+
# TTLs default to 28800 s (8 h) and 86400 s (24 h).
|
|
642
|
+
ca = await client.ssh.create_ca(CreateSshCaRequest(name="prod-ssh", key_type="ed25519"))
|
|
643
|
+
open("trusted_user_ca_keys.pub", "w").write(await client.ssh.get_ca_public_key(ca.id))
|
|
644
|
+
|
|
645
|
+
cert = await client.ssh.sign(
|
|
646
|
+
SignSshKeyRequest(
|
|
647
|
+
ca_id=ca.id,
|
|
648
|
+
public_key=open("id_ed25519.pub").read(),
|
|
649
|
+
principals=["deploy"], # at least one username
|
|
650
|
+
ttl_seconds=3600, # default: the CA's default TTL, capped at its max TTL
|
|
651
|
+
)
|
|
652
|
+
)
|
|
653
|
+
open("id_ed25519-cert.pub", "w").write(cert.signed_certificate)
|
|
654
|
+
|
|
655
|
+
certs = await client.ssh.list_certificates(ca_id=ca.id) # ca_id optional
|
|
656
|
+
for c in certs.certificates:
|
|
657
|
+
print(c.serial_number, c.principal_list, c.valid_before, c.is_revoked, c.is_expired)
|
|
658
|
+
|
|
659
|
+
await client.ssh.revoke_certificate(cert.id)
|
|
660
|
+
await client.ssh.update_ca(ca.id, UpdateSshCaRequest(max_ttl_seconds=43200))
|
|
661
|
+
await client.ssh.disable_ca(ca.id) # and enable_ca(ca.id); also list_cas(), get_ca(ca.id)
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
In the list, `principals` is a comma-separated string (`principal_list` splits it); in the result of
|
|
665
|
+
`sign` it is a list.
|
|
666
|
+
|
|
667
|
+
### API Keys Client
|
|
668
|
+
|
|
669
|
+
The tenant's API keys under `/api/v1/api-keys`. The full key value is returned once, by `create`.
|
|
670
|
+
|
|
671
|
+
```python
|
|
672
|
+
from datetime import datetime, timezone
|
|
673
|
+
from quantumapi.models import ApiKeyLabelsItem, CreateApiKeyRequest, UpdateApiKeyRequest
|
|
674
|
+
|
|
675
|
+
created = await client.api_keys.create(
|
|
676
|
+
CreateApiKeyRequest(
|
|
677
|
+
name="ci-deploy",
|
|
678
|
+
scopes=["secrets:read"],
|
|
679
|
+
environment="production", # development, staging or production; None = no restriction
|
|
680
|
+
allowed_ips=["203.0.113.5/32"],
|
|
681
|
+
expires_at=datetime(2027, 6, 30, tzinfo=timezone.utc),
|
|
682
|
+
# no_vault=True skips the copy the platform stores as a vault secret (created.vault_secret_id)
|
|
683
|
+
)
|
|
684
|
+
)
|
|
685
|
+
print(created.api_key) # shown ONLY ONCE
|
|
686
|
+
|
|
687
|
+
keys = await client.api_keys.list()
|
|
688
|
+
for k in keys.api_keys:
|
|
689
|
+
print(k.prefix, k.name, k.is_active, k.last_used_at, k.request_count)
|
|
690
|
+
|
|
691
|
+
# Only the fields you set change. [] or "" removes a restriction.
|
|
692
|
+
await client.api_keys.update(created.id, UpdateApiKeyRequest(allowed_ips=[], labels=["ci"]))
|
|
693
|
+
await client.api_keys.bulk_update_labels([ApiKeyLabelsItem(api_key_id=created.id, labels=["prod"])])
|
|
694
|
+
tags = await client.api_keys.list_tags()
|
|
695
|
+
|
|
696
|
+
await client.api_keys.revoke(created.id) # cannot be undone; returns None
|
|
697
|
+
```
|
|
698
|
+
|
|
573
699
|
### Usage Client
|
|
574
700
|
|
|
575
701
|
Storage occupied by the tenant this month, in total and per category (`secrets`, `keys`,
|
|
@@ -15,6 +15,8 @@ Official Python SDK for [QuantumAPI](https://quantumapi.eu) - The European quant
|
|
|
15
15
|
- 👤 **User Management** - Create and manage end-users with roles
|
|
16
16
|
- 🔍 **Audit Logs** - Query comprehensive audit trails
|
|
17
17
|
- 📈 **Usage** - Read the tenant's storage usage (`client.usage`)
|
|
18
|
+
- 📜 **PKI and SSH CA** - Run X.509 and SSH certificate authorities (`client.pki`, `client.ssh`)
|
|
19
|
+
- 🗝️ **API Keys** - Create, restrict and revoke the tenant's API keys (`client.api_keys`)
|
|
18
20
|
- 🚀 **Async/Await Support** - Full async support with httpx
|
|
19
21
|
- ⚡ **Automatic Retries** - Exponential backoff for transient failures
|
|
20
22
|
- 📊 **Rate Limiting** - Client-side rate limit tracking
|
|
@@ -116,18 +118,21 @@ plaintext = await client.encryption.decrypt(
|
|
|
116
118
|
encrypted_payload=result.encrypted_payload
|
|
117
119
|
)
|
|
118
120
|
|
|
119
|
-
# Sign data
|
|
121
|
+
# Sign data (data is base64)
|
|
122
|
+
import base64
|
|
123
|
+
data = base64.b64encode(b"message to sign").decode()
|
|
120
124
|
signature = await client.encryption.sign(
|
|
121
|
-
data=
|
|
125
|
+
data=data,
|
|
122
126
|
key_id="signing-key-id"
|
|
123
127
|
)
|
|
124
128
|
|
|
125
129
|
# Verify signature
|
|
126
|
-
|
|
127
|
-
data=
|
|
130
|
+
result = await client.encryption.verify(
|
|
131
|
+
data=data,
|
|
128
132
|
signature=signature.signature,
|
|
129
133
|
key_id="signing-key-id"
|
|
130
134
|
)
|
|
135
|
+
print(result.is_valid)
|
|
131
136
|
```
|
|
132
137
|
|
|
133
138
|
### Audit Client
|
|
@@ -162,30 +167,40 @@ key = await client.keys.generate(
|
|
|
162
167
|
set_as_default=True
|
|
163
168
|
)
|
|
164
169
|
|
|
165
|
-
# List keys
|
|
170
|
+
# List keys (sent as ?type=encryption&page=1&pageSize=50)
|
|
166
171
|
keys = await client.keys.list(
|
|
167
172
|
key_type="encryption",
|
|
168
173
|
page=1,
|
|
169
|
-
page_size=50
|
|
174
|
+
page_size=50,
|
|
175
|
+
include_inactive=False,
|
|
170
176
|
)
|
|
177
|
+
print(keys.total_count, keys.has_more)
|
|
171
178
|
|
|
172
179
|
# Get key details
|
|
173
180
|
key = await client.keys.get(key_id="key-id")
|
|
174
181
|
|
|
175
|
-
# Rotate key
|
|
176
|
-
|
|
182
|
+
# Rotate key: new version, same key id
|
|
183
|
+
rotation = await client.keys.rotate(key_id="key-id")
|
|
184
|
+
print(rotation.previous_version, "->", rotation.new_version, rotation.rotated_at)
|
|
177
185
|
|
|
178
|
-
#
|
|
179
|
-
await client.keys.
|
|
186
|
+
# Update metadata (only the arguments you pass are sent)
|
|
187
|
+
await client.keys.update("key-id", description="Orders KEK", labels=["prod"], is_favorite=True)
|
|
188
|
+
|
|
189
|
+
# Export the public key (PEM by default)
|
|
190
|
+
pem = await client.keys.export_public_key("key-id")
|
|
191
|
+
|
|
192
|
+
# Schedule deletion after a 7-90 day grace period (default 30)
|
|
193
|
+
scheduled = await client.keys.delete(key_id="key-id", schedule_days=30)
|
|
194
|
+
print(scheduled.scheduled_deletion_date)
|
|
180
195
|
|
|
181
196
|
# Set default key
|
|
182
|
-
await client.keys.set_default(key_id="key-id"
|
|
197
|
+
await client.keys.set_default(key_id="key-id")
|
|
183
198
|
```
|
|
184
199
|
|
|
185
200
|
### Secrets Client
|
|
186
201
|
|
|
187
202
|
```python
|
|
188
|
-
# Create secret
|
|
203
|
+
# Create secret: returns the metadata (SecretResponse); the value is not echoed back
|
|
189
204
|
secret = await client.secrets.create(
|
|
190
205
|
name="api-key",
|
|
191
206
|
value="secret_value",
|
|
@@ -529,6 +544,117 @@ await client.external_key_stores.disconnect(store.id) # kill switch; reconnect(
|
|
|
529
544
|
A 409 `credential_limit` (too many access keys) raises `ConflictError`; a 400
|
|
530
545
|
`invalid_configuration` raises `ValidationError` with the reason in `message`.
|
|
531
546
|
|
|
547
|
+
### PKI Client (X.509)
|
|
548
|
+
|
|
549
|
+
Certificate authorities and certificates under `/api/v1/pki`. Keys are RSA (CA 4096 bits, certificates
|
|
550
|
+
2048 bits by default). The CA private key is encrypted at rest and never returned; a certificate's private
|
|
551
|
+
key is returned once, by `issue_certificate`.
|
|
552
|
+
|
|
553
|
+
```python
|
|
554
|
+
from quantumapi.models import CreateCertificateAuthorityRequest, IssueCertificateRequest
|
|
555
|
+
|
|
556
|
+
# Root CA (10 years by default). Set parent_ca_id for an intermediate CA (5 years by default).
|
|
557
|
+
ca = await client.pki.create_ca(
|
|
558
|
+
CreateCertificateAuthorityRequest(name="acme-root", organization="Acme", country="ES")
|
|
559
|
+
)
|
|
560
|
+
|
|
561
|
+
cert = await client.pki.issue_certificate(
|
|
562
|
+
IssueCertificateRequest(
|
|
563
|
+
ca_id=ca.id,
|
|
564
|
+
common_name="api.acme.eu",
|
|
565
|
+
dns_names=["api.acme.eu"],
|
|
566
|
+
ip_addresses=["10.0.0.5"],
|
|
567
|
+
validity_days=90, # default 365, capped at the CA's expiry
|
|
568
|
+
)
|
|
569
|
+
)
|
|
570
|
+
# The private key is shown ONLY ONCE, here.
|
|
571
|
+
open("api.crt", "w").write(cert.certificate_pem)
|
|
572
|
+
open("api.key", "w").write(cert.private_key_pem)
|
|
573
|
+
|
|
574
|
+
certs = await client.pki.list_certificates(ca_id=ca.id, status="Active") # both filters optional
|
|
575
|
+
for c in certs.certificates:
|
|
576
|
+
print(c.serial_number, c.common_name, c.status, c.not_after)
|
|
577
|
+
|
|
578
|
+
detail = await client.pki.get_certificate(cert.id) # PEM, SANs, revocation data
|
|
579
|
+
result = await client.pki.revoke_certificate(cert.id, reason="keyCompromise") # rebuilds the CA's CRL
|
|
580
|
+
print(result.revoked, result.serial_number)
|
|
581
|
+
|
|
582
|
+
ca_pem = await client.pki.get_ca_certificate(ca.id) # PEM text
|
|
583
|
+
crl_pem = await client.pki.get_crl(ca.id) # PEM text, or None before the first revocation
|
|
584
|
+
cas = await client.pki.list_cas() # cas.authorities
|
|
585
|
+
await client.pki.disable_ca(ca.id) # and enable_ca(ca.id); a disabled CA cannot issue
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
A duplicate CA name raises `ConflictError`; an unknown or disabled CA `NotFoundError`; an expired CA or
|
|
589
|
+
revoking twice raises `ValidationError` (`ca_expired`, `already_revoked`).
|
|
590
|
+
|
|
591
|
+
### SSH Client
|
|
592
|
+
|
|
593
|
+
SSH certificate authorities and user certificates under `/api/v1/ssh`. Servers trust the CA public key
|
|
594
|
+
(`TrustedUserCAKeys`); users get short-lived certificates for their own public keys.
|
|
595
|
+
|
|
596
|
+
```python
|
|
597
|
+
from quantumapi.models import CreateSshCaRequest, SignSshKeyRequest, UpdateSshCaRequest
|
|
598
|
+
|
|
599
|
+
# key_type: ed25519 (default), ecdsa-p256, ecdsa-p384 or rsa-4096 (SSH_CA_KEY_TYPES).
|
|
600
|
+
# TTLs default to 28800 s (8 h) and 86400 s (24 h).
|
|
601
|
+
ca = await client.ssh.create_ca(CreateSshCaRequest(name="prod-ssh", key_type="ed25519"))
|
|
602
|
+
open("trusted_user_ca_keys.pub", "w").write(await client.ssh.get_ca_public_key(ca.id))
|
|
603
|
+
|
|
604
|
+
cert = await client.ssh.sign(
|
|
605
|
+
SignSshKeyRequest(
|
|
606
|
+
ca_id=ca.id,
|
|
607
|
+
public_key=open("id_ed25519.pub").read(),
|
|
608
|
+
principals=["deploy"], # at least one username
|
|
609
|
+
ttl_seconds=3600, # default: the CA's default TTL, capped at its max TTL
|
|
610
|
+
)
|
|
611
|
+
)
|
|
612
|
+
open("id_ed25519-cert.pub", "w").write(cert.signed_certificate)
|
|
613
|
+
|
|
614
|
+
certs = await client.ssh.list_certificates(ca_id=ca.id) # ca_id optional
|
|
615
|
+
for c in certs.certificates:
|
|
616
|
+
print(c.serial_number, c.principal_list, c.valid_before, c.is_revoked, c.is_expired)
|
|
617
|
+
|
|
618
|
+
await client.ssh.revoke_certificate(cert.id)
|
|
619
|
+
await client.ssh.update_ca(ca.id, UpdateSshCaRequest(max_ttl_seconds=43200))
|
|
620
|
+
await client.ssh.disable_ca(ca.id) # and enable_ca(ca.id); also list_cas(), get_ca(ca.id)
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
In the list, `principals` is a comma-separated string (`principal_list` splits it); in the result of
|
|
624
|
+
`sign` it is a list.
|
|
625
|
+
|
|
626
|
+
### API Keys Client
|
|
627
|
+
|
|
628
|
+
The tenant's API keys under `/api/v1/api-keys`. The full key value is returned once, by `create`.
|
|
629
|
+
|
|
630
|
+
```python
|
|
631
|
+
from datetime import datetime, timezone
|
|
632
|
+
from quantumapi.models import ApiKeyLabelsItem, CreateApiKeyRequest, UpdateApiKeyRequest
|
|
633
|
+
|
|
634
|
+
created = await client.api_keys.create(
|
|
635
|
+
CreateApiKeyRequest(
|
|
636
|
+
name="ci-deploy",
|
|
637
|
+
scopes=["secrets:read"],
|
|
638
|
+
environment="production", # development, staging or production; None = no restriction
|
|
639
|
+
allowed_ips=["203.0.113.5/32"],
|
|
640
|
+
expires_at=datetime(2027, 6, 30, tzinfo=timezone.utc),
|
|
641
|
+
# no_vault=True skips the copy the platform stores as a vault secret (created.vault_secret_id)
|
|
642
|
+
)
|
|
643
|
+
)
|
|
644
|
+
print(created.api_key) # shown ONLY ONCE
|
|
645
|
+
|
|
646
|
+
keys = await client.api_keys.list()
|
|
647
|
+
for k in keys.api_keys:
|
|
648
|
+
print(k.prefix, k.name, k.is_active, k.last_used_at, k.request_count)
|
|
649
|
+
|
|
650
|
+
# Only the fields you set change. [] or "" removes a restriction.
|
|
651
|
+
await client.api_keys.update(created.id, UpdateApiKeyRequest(allowed_ips=[], labels=["ci"]))
|
|
652
|
+
await client.api_keys.bulk_update_labels([ApiKeyLabelsItem(api_key_id=created.id, labels=["prod"])])
|
|
653
|
+
tags = await client.api_keys.list_tags()
|
|
654
|
+
|
|
655
|
+
await client.api_keys.revoke(created.id) # cannot be undone; returns None
|
|
656
|
+
```
|
|
657
|
+
|
|
532
658
|
### Usage Client
|
|
533
659
|
|
|
534
660
|
Storage occupied by the tenant this month, in total and per category (`secrets`, `keys`,
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "quantumapi"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.27.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"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Client package for QuantumAPI SDK."""
|
|
2
2
|
|
|
3
|
+
from quantumapi.client.api_keys import ApiKeysClient
|
|
3
4
|
from quantumapi.client.applications import ApplicationsClient
|
|
4
5
|
from quantumapi.client.async_client import QuantumAPIClient
|
|
5
6
|
from quantumapi.client.compliance import ComplianceClient
|
|
@@ -11,8 +12,10 @@ from quantumapi.client.audit import AuditClient
|
|
|
11
12
|
from quantumapi.client.keys import KeysClient
|
|
12
13
|
from quantumapi.client.dynamic_secrets import DynamicSecretsClient
|
|
13
14
|
from quantumapi.client.log_streams import LogStreamsClient
|
|
15
|
+
from quantumapi.client.pki import PkiClient
|
|
14
16
|
from quantumapi.client.qrng import QrngClient
|
|
15
17
|
from quantumapi.client.secrets import SecretsClient
|
|
18
|
+
from quantumapi.client.ssh import SshClient
|
|
16
19
|
from quantumapi.client.sync_client import QuantumAPISyncClient
|
|
17
20
|
from quantumapi.client.team import TeamClient
|
|
18
21
|
from quantumapi.client.usage import UsageClient
|
|
@@ -34,4 +37,7 @@ __all__ = [
|
|
|
34
37
|
"LogStreamsClient",
|
|
35
38
|
"UsageClient",
|
|
36
39
|
"ExternalKeyStoresClient",
|
|
40
|
+
"PkiClient",
|
|
41
|
+
"SshClient",
|
|
42
|
+
"ApiKeysClient",
|
|
37
43
|
]
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Tenant API key management client for QuantumAPI SDK."""
|
|
2
|
+
|
|
3
|
+
from typing import List, Sequence, Union
|
|
4
|
+
from uuid import UUID
|
|
5
|
+
|
|
6
|
+
from quantumapi.client.base import BaseClient
|
|
7
|
+
from quantumapi.models.api_keys import (
|
|
8
|
+
ApiKey,
|
|
9
|
+
ApiKeyLabelsItem,
|
|
10
|
+
ApiKeyList,
|
|
11
|
+
BulkApiKeyLabelsResult,
|
|
12
|
+
CreateApiKeyRequest,
|
|
13
|
+
CreatedApiKey,
|
|
14
|
+
UpdateApiKeyRequest,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
_BASE = "/api/v1/api-keys"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ApiKeysClient:
|
|
21
|
+
"""
|
|
22
|
+
The tenant's API keys (``/api/v1/api-keys``).
|
|
23
|
+
|
|
24
|
+
The full key value is returned once, by ``create``. Developer and Viewer roles only see the keys
|
|
25
|
+
their access policies allow.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(self, base_client: BaseClient) -> None:
|
|
29
|
+
self._client = base_client
|
|
30
|
+
|
|
31
|
+
async def list(self) -> ApiKeyList:
|
|
32
|
+
"""List the tenant's API keys (``GET /api/v1/api-keys``)."""
|
|
33
|
+
return ApiKeyList(**await self._client.get(_BASE))
|
|
34
|
+
|
|
35
|
+
async def list_tags(self) -> List[str]:
|
|
36
|
+
"""Distinct labels used on the tenant's API keys (``GET /api/v1/api-keys/tags``)."""
|
|
37
|
+
response = await self._client.get(f"{_BASE}/tags")
|
|
38
|
+
return [str(tag) for tag in response.get("tags") or []]
|
|
39
|
+
|
|
40
|
+
async def get(self, api_key_id: Union[UUID, str]) -> ApiKey:
|
|
41
|
+
"""Get an API key's metadata (``GET /api/v1/api-keys/{id}``)."""
|
|
42
|
+
return ApiKey(**await self._client.get(f"{_BASE}/{api_key_id}"))
|
|
43
|
+
|
|
44
|
+
async def create(self, request: CreateApiKeyRequest) -> CreatedApiKey:
|
|
45
|
+
"""
|
|
46
|
+
Create an API key (``POST /api/v1/api-keys``, 201). ``api_key`` in the result is the full
|
|
47
|
+
value, shown only now.
|
|
48
|
+
|
|
49
|
+
Example:
|
|
50
|
+
>>> created = await client.api_keys.create(
|
|
51
|
+
... CreateApiKeyRequest(name="ci", scopes=["secrets:read"], environment="production")
|
|
52
|
+
... )
|
|
53
|
+
>>> print(created.api_key)
|
|
54
|
+
"""
|
|
55
|
+
return CreatedApiKey(**await self._client.post(_BASE, json_data=request.to_payload()))
|
|
56
|
+
|
|
57
|
+
async def update(self, api_key_id: Union[UUID, str], request: UpdateApiKeyRequest) -> ApiKey:
|
|
58
|
+
"""Change an API key's metadata or restrictions (``PATCH /api/v1/api-keys/{id}``)."""
|
|
59
|
+
response = await self._client.patch(f"{_BASE}/{api_key_id}", json_data=request.to_payload())
|
|
60
|
+
return ApiKey(**response)
|
|
61
|
+
|
|
62
|
+
async def bulk_update_labels(self, items: Sequence[ApiKeyLabelsItem]) -> BulkApiKeyLabelsResult:
|
|
63
|
+
"""
|
|
64
|
+
Merge labels into several keys' labels (``PATCH /api/v1/api-keys/labels/bulk``).
|
|
65
|
+
1 to 500 items; keys that are unknown or fail are skipped and not counted in ``updated``.
|
|
66
|
+
"""
|
|
67
|
+
body = {"items": [item.model_dump(mode="json", by_alias=True) for item in items]}
|
|
68
|
+
response = await self._client.patch(f"{_BASE}/labels/bulk", json_data=body)
|
|
69
|
+
return BulkApiKeyLabelsResult(**response)
|
|
70
|
+
|
|
71
|
+
async def revoke(self, api_key_id: Union[UUID, str]) -> None:
|
|
72
|
+
"""Deactivate an API key; this cannot be undone (``POST /api/v1/api-keys/{id}/revoke``, 204)."""
|
|
73
|
+
await self._client.post(f"{_BASE}/{api_key_id}/revoke")
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import os
|
|
4
4
|
from typing import Optional
|
|
5
5
|
|
|
6
|
+
from quantumapi.client.api_keys import ApiKeysClient
|
|
6
7
|
from quantumapi.client.applications import ApplicationsClient
|
|
7
8
|
from quantumapi.client.base import BaseClient
|
|
8
9
|
from quantumapi.client.compliance import ComplianceClient
|
|
@@ -14,11 +15,13 @@ from quantumapi.client.audit import AuditClient
|
|
|
14
15
|
from quantumapi.client.keys import KeysClient
|
|
15
16
|
from quantumapi.client.dynamic_secrets import DynamicSecretsClient
|
|
16
17
|
from quantumapi.client.log_streams import LogStreamsClient
|
|
18
|
+
from quantumapi.client.pki import PkiClient
|
|
17
19
|
from quantumapi.client.qrng import QrngClient
|
|
18
20
|
from quantumapi.client.resource_groups import ResourceGroupsClient
|
|
19
21
|
from quantumapi.client.roles import RolesClient
|
|
20
22
|
from quantumapi.client.team import TeamClient
|
|
21
23
|
from quantumapi.client.secrets import SecretsClient
|
|
24
|
+
from quantumapi.client.ssh import SshClient
|
|
22
25
|
from quantumapi.client.transit import TransitClient
|
|
23
26
|
from quantumapi.client.usage import UsageClient
|
|
24
27
|
|
|
@@ -105,6 +108,9 @@ class QuantumAPIClient:
|
|
|
105
108
|
self.usage = UsageClient(self._base_client)
|
|
106
109
|
self.dynamic_secrets = DynamicSecretsClient(self._base_client)
|
|
107
110
|
self.external_key_stores = ExternalKeyStoresClient(self._base_client)
|
|
111
|
+
self.pki = PkiClient(self._base_client)
|
|
112
|
+
self.ssh = SshClient(self._base_client)
|
|
113
|
+
self.api_keys = ApiKeysClient(self._base_client)
|
|
108
114
|
|
|
109
115
|
async def close(self) -> None:
|
|
110
116
|
"""
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"""Encryption client for QuantumAPI SDK."""
|
|
2
2
|
|
|
3
|
-
from typing import Optional
|
|
3
|
+
from typing import Any, Dict, Optional
|
|
4
4
|
from uuid import UUID
|
|
5
5
|
|
|
6
|
+
from pydantic import BaseModel
|
|
7
|
+
|
|
6
8
|
from quantumapi.client.base import BaseClient
|
|
7
9
|
from quantumapi.models.encryption import (
|
|
8
10
|
DecryptRequest,
|
|
@@ -16,6 +18,11 @@ from quantumapi.models.encryption import (
|
|
|
16
18
|
)
|
|
17
19
|
|
|
18
20
|
|
|
21
|
+
def _body(request: BaseModel) -> Dict[str, Any]:
|
|
22
|
+
"""Request body in the API's camelCase JSON (``keyId``, ``encryptedPayload``)."""
|
|
23
|
+
return request.model_dump(mode="json", by_alias=True, exclude_none=True)
|
|
24
|
+
|
|
25
|
+
|
|
19
26
|
class EncryptionClient:
|
|
20
27
|
"""Client for encryption, decryption, signing, and verification operations."""
|
|
21
28
|
|
|
@@ -60,7 +67,7 @@ class EncryptionClient:
|
|
|
60
67
|
algorithm=algorithm,
|
|
61
68
|
additional_data=additional_data,
|
|
62
69
|
)
|
|
63
|
-
response = await self._client.post("/api/v1/encrypt", json_data=request
|
|
70
|
+
response = await self._client.post("/api/v1/encrypt", json_data=_body(request))
|
|
64
71
|
return EncryptResponse(**response)
|
|
65
72
|
|
|
66
73
|
async def decrypt(
|
|
@@ -106,7 +113,7 @@ class EncryptionClient:
|
|
|
106
113
|
key_version=key_version,
|
|
107
114
|
additional_data=additional_data,
|
|
108
115
|
)
|
|
109
|
-
response = await self._client.post("/api/v1/decrypt", json_data=request
|
|
116
|
+
response = await self._client.post("/api/v1/decrypt", json_data=_body(request))
|
|
110
117
|
return DecryptResponse(**response)
|
|
111
118
|
|
|
112
119
|
async def sign(
|
|
@@ -136,7 +143,7 @@ class EncryptionClient:
|
|
|
136
143
|
key_id=key_id,
|
|
137
144
|
algorithm=algorithm,
|
|
138
145
|
)
|
|
139
|
-
response = await self._client.post("/api/v1/sign", json_data=request
|
|
146
|
+
response = await self._client.post("/api/v1/sign", json_data=_body(request))
|
|
140
147
|
return SignResponse(**response)
|
|
141
148
|
|
|
142
149
|
async def verify(
|
|
@@ -165,5 +172,5 @@ class EncryptionClient:
|
|
|
165
172
|
signature=signature,
|
|
166
173
|
key_id=key_id,
|
|
167
174
|
)
|
|
168
|
-
response = await self._client.post("/api/v1/verify", json_data=request
|
|
175
|
+
response = await self._client.post("/api/v1/verify", json_data=_body(request))
|
|
169
176
|
return VerifyResponse(**response)
|