Skip to content

Commit 60b62c3

Browse files
authored
feat(key_manager): add api to list algorithms (#1178)
1 parent 6bda4a8 commit 60b62c3

File tree

8 files changed

+274
-0
lines changed

8 files changed

+274
-0
lines changed

scaleway-async/scaleway_async/key_manager/v1alpha1/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
from .types import KeyAlgorithmSymmetricEncryption
77
from .types import KeyOrigin
88
from .types import KeyState
9+
from .types import ListAlgorithmsRequestUsage
910
from .types import ListKeysRequestOrderBy
1011
from .types import ListKeysRequestUsage
1112
from .types import KeyRotationPolicy
1213
from .types import KeyUsage
14+
from .types import ListAlgorithmsResponseAlgorithm
1315
from .types import Key
1416
from .types import CreateKeyRequest
1517
from .types import DataKey
@@ -25,6 +27,8 @@
2527
from .types import GetKeyRequest
2628
from .types import GetPublicKeyRequest
2729
from .types import ImportKeyMaterialRequest
30+
from .types import ListAlgorithmsRequest
31+
from .types import ListAlgorithmsResponse
2832
from .types import ListKeysRequest
2933
from .types import ListKeysResponse
3034
from .types import ProtectKeyRequest
@@ -46,10 +50,12 @@
4650
"KeyAlgorithmSymmetricEncryption",
4751
"KeyOrigin",
4852
"KeyState",
53+
"ListAlgorithmsRequestUsage",
4954
"ListKeysRequestOrderBy",
5055
"ListKeysRequestUsage",
5156
"KeyRotationPolicy",
5257
"KeyUsage",
58+
"ListAlgorithmsResponseAlgorithm",
5359
"Key",
5460
"CreateKeyRequest",
5561
"DataKey",
@@ -65,6 +71,8 @@
6571
"GetKeyRequest",
6672
"GetPublicKeyRequest",
6773
"ImportKeyMaterialRequest",
74+
"ListAlgorithmsRequest",
75+
"ListAlgorithmsResponse",
6876
"ListKeysRequest",
6977
"ListKeysResponse",
7078
"ProtectKeyRequest",

scaleway-async/scaleway_async/key_manager/v1alpha1/api.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .types import (
1515
DataKeyAlgorithmSymmetricEncryption,
1616
KeyOrigin,
17+
ListAlgorithmsRequestUsage,
1718
ListKeysRequestOrderBy,
1819
ListKeysRequestUsage,
1920
CreateKeyRequest,
@@ -27,6 +28,7 @@
2728
Key,
2829
KeyRotationPolicy,
2930
KeyUsage,
31+
ListAlgorithmsResponse,
3032
ListKeysResponse,
3133
PublicKey,
3234
SignRequest,
@@ -40,6 +42,7 @@
4042
unmarshal_DataKey,
4143
unmarshal_DecryptResponse,
4244
unmarshal_EncryptResponse,
45+
unmarshal_ListAlgorithmsResponse,
4346
unmarshal_ListKeysResponse,
4447
unmarshal_PublicKey,
4548
unmarshal_SignResponse,
@@ -921,3 +924,37 @@ async def restore_key(
921924

922925
self._throw_on_error(res)
923926
return unmarshal_Key(res.json())
927+
928+
async def list_algorithms(
929+
self,
930+
*,
931+
region: Optional[ScwRegion] = None,
932+
usages: Optional[List[ListAlgorithmsRequestUsage]] = None,
933+
) -> ListAlgorithmsResponse:
934+
"""
935+
List all available algorithms.
936+
Lists all cryptographic algorithms supported by the Key Manager service.
937+
:param region: Region to target. If none is passed will use default region from the config.
938+
:param usages: Filter by key usage.
939+
:return: :class:`ListAlgorithmsResponse <ListAlgorithmsResponse>`
940+
941+
Usage:
942+
::
943+
944+
result = await api.list_algorithms()
945+
"""
946+
947+
param_region = validate_path_param(
948+
"region", region or self.client.default_region
949+
)
950+
951+
res = self._request(
952+
"GET",
953+
f"/key-manager/v1alpha1/regions/{param_region}/algorithms",
954+
params={
955+
"usages": usages,
956+
},
957+
)
958+
959+
self._throw_on_error(res)
960+
return unmarshal_ListAlgorithmsResponse(res.json())

scaleway-async/scaleway_async/key_manager/v1alpha1/marshalling.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
DataKey,
2121
DecryptResponse,
2222
EncryptResponse,
23+
ListAlgorithmsResponseAlgorithm,
24+
ListAlgorithmsResponse,
2325
ListKeysResponse,
2426
PublicKey,
2527
SignResponse,
@@ -301,6 +303,58 @@ def unmarshal_EncryptResponse(data: Any) -> EncryptResponse:
301303
return EncryptResponse(**args)
302304

303305

306+
def unmarshal_ListAlgorithmsResponseAlgorithm(
307+
data: Any,
308+
) -> ListAlgorithmsResponseAlgorithm:
309+
if not isinstance(data, dict):
310+
raise TypeError(
311+
"Unmarshalling the type 'ListAlgorithmsResponseAlgorithm' failed as data isn't a dictionary."
312+
)
313+
314+
args: Dict[str, Any] = {}
315+
316+
field = data.get("usage", None)
317+
if field is not None:
318+
args["usage"] = field
319+
else:
320+
args["usage"] = None
321+
322+
field = data.get("name", None)
323+
if field is not None:
324+
args["name"] = field
325+
else:
326+
args["name"] = None
327+
328+
field = data.get("recommended", None)
329+
if field is not None:
330+
args["recommended"] = field
331+
else:
332+
args["recommended"] = None
333+
334+
return ListAlgorithmsResponseAlgorithm(**args)
335+
336+
337+
def unmarshal_ListAlgorithmsResponse(data: Any) -> ListAlgorithmsResponse:
338+
if not isinstance(data, dict):
339+
raise TypeError(
340+
"Unmarshalling the type 'ListAlgorithmsResponse' failed as data isn't a dictionary."
341+
)
342+
343+
args: Dict[str, Any] = {}
344+
345+
field = data.get("algorithms", None)
346+
if field is not None:
347+
args["algorithms"] = (
348+
[unmarshal_ListAlgorithmsResponseAlgorithm(v) for v in field]
349+
if field is not None
350+
else None
351+
)
352+
else:
353+
args["algorithms"] = []
354+
355+
return ListAlgorithmsResponse(**args)
356+
357+
304358
def unmarshal_ListKeysResponse(data: Any) -> ListKeysResponse:
305359
if not isinstance(data, dict):
306360
raise TypeError(

scaleway-async/scaleway_async/key_manager/v1alpha1/types.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ def __str__(self) -> str:
7676
return str(self.value)
7777

7878

79+
class ListAlgorithmsRequestUsage(str, Enum, metaclass=StrEnumMeta):
80+
UNKNOWN_USAGE = "unknown_usage"
81+
SYMMETRIC_ENCRYPTION = "symmetric_encryption"
82+
ASYMMETRIC_ENCRYPTION = "asymmetric_encryption"
83+
ASYMMETRIC_SIGNING = "asymmetric_signing"
84+
85+
def __str__(self) -> str:
86+
return str(self.value)
87+
88+
7989
class ListKeysRequestOrderBy(str, Enum, metaclass=StrEnumMeta):
8090
NAME_ASC = "name_asc"
8191
NAME_DESC = "name_desc"
@@ -122,6 +132,13 @@ class KeyUsage:
122132
asymmetric_signing: Optional[KeyAlgorithmAsymmetricSigning] = None
123133

124134

135+
@dataclass
136+
class ListAlgorithmsResponseAlgorithm:
137+
usage: str
138+
name: str
139+
recommended: bool
140+
141+
125142
@dataclass
126143
class Key:
127144
id: str
@@ -490,6 +507,27 @@ class ImportKeyMaterialRequest:
490507
"""
491508

492509

510+
@dataclass
511+
class ListAlgorithmsRequest:
512+
region: Optional[ScwRegion] = None
513+
"""
514+
Region to target. If none is passed will use default region from the config.
515+
"""
516+
517+
usages: Optional[List[ListAlgorithmsRequestUsage]] = field(default_factory=list)
518+
"""
519+
Filter by key usage.
520+
"""
521+
522+
523+
@dataclass
524+
class ListAlgorithmsResponse:
525+
algorithms: List[ListAlgorithmsResponseAlgorithm]
526+
"""
527+
Returns a list of algorithms matching the requested criteria.
528+
"""
529+
530+
493531
@dataclass
494532
class ListKeysRequest:
495533
scheduled_for_deletion: bool

scaleway/scaleway/key_manager/v1alpha1/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
from .types import KeyAlgorithmSymmetricEncryption
77
from .types import KeyOrigin
88
from .types import KeyState
9+
from .types import ListAlgorithmsRequestUsage
910
from .types import ListKeysRequestOrderBy
1011
from .types import ListKeysRequestUsage
1112
from .types import KeyRotationPolicy
1213
from .types import KeyUsage
14+
from .types import ListAlgorithmsResponseAlgorithm
1315
from .types import Key
1416
from .types import CreateKeyRequest
1517
from .types import DataKey
@@ -25,6 +27,8 @@
2527
from .types import GetKeyRequest
2628
from .types import GetPublicKeyRequest
2729
from .types import ImportKeyMaterialRequest
30+
from .types import ListAlgorithmsRequest
31+
from .types import ListAlgorithmsResponse
2832
from .types import ListKeysRequest
2933
from .types import ListKeysResponse
3034
from .types import ProtectKeyRequest
@@ -46,10 +50,12 @@
4650
"KeyAlgorithmSymmetricEncryption",
4751
"KeyOrigin",
4852
"KeyState",
53+
"ListAlgorithmsRequestUsage",
4954
"ListKeysRequestOrderBy",
5055
"ListKeysRequestUsage",
5156
"KeyRotationPolicy",
5257
"KeyUsage",
58+
"ListAlgorithmsResponseAlgorithm",
5359
"Key",
5460
"CreateKeyRequest",
5561
"DataKey",
@@ -65,6 +71,8 @@
6571
"GetKeyRequest",
6672
"GetPublicKeyRequest",
6773
"ImportKeyMaterialRequest",
74+
"ListAlgorithmsRequest",
75+
"ListAlgorithmsResponse",
6876
"ListKeysRequest",
6977
"ListKeysResponse",
7078
"ProtectKeyRequest",

scaleway/scaleway/key_manager/v1alpha1/api.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .types import (
1515
DataKeyAlgorithmSymmetricEncryption,
1616
KeyOrigin,
17+
ListAlgorithmsRequestUsage,
1718
ListKeysRequestOrderBy,
1819
ListKeysRequestUsage,
1920
CreateKeyRequest,
@@ -27,6 +28,7 @@
2728
Key,
2829
KeyRotationPolicy,
2930
KeyUsage,
31+
ListAlgorithmsResponse,
3032
ListKeysResponse,
3133
PublicKey,
3234
SignRequest,
@@ -40,6 +42,7 @@
4042
unmarshal_DataKey,
4143
unmarshal_DecryptResponse,
4244
unmarshal_EncryptResponse,
45+
unmarshal_ListAlgorithmsResponse,
4346
unmarshal_ListKeysResponse,
4447
unmarshal_PublicKey,
4548
unmarshal_SignResponse,
@@ -921,3 +924,37 @@ def restore_key(
921924

922925
self._throw_on_error(res)
923926
return unmarshal_Key(res.json())
927+
928+
def list_algorithms(
929+
self,
930+
*,
931+
region: Optional[ScwRegion] = None,
932+
usages: Optional[List[ListAlgorithmsRequestUsage]] = None,
933+
) -> ListAlgorithmsResponse:
934+
"""
935+
List all available algorithms.
936+
Lists all cryptographic algorithms supported by the Key Manager service.
937+
:param region: Region to target. If none is passed will use default region from the config.
938+
:param usages: Filter by key usage.
939+
:return: :class:`ListAlgorithmsResponse <ListAlgorithmsResponse>`
940+
941+
Usage:
942+
::
943+
944+
result = api.list_algorithms()
945+
"""
946+
947+
param_region = validate_path_param(
948+
"region", region or self.client.default_region
949+
)
950+
951+
res = self._request(
952+
"GET",
953+
f"/key-manager/v1alpha1/regions/{param_region}/algorithms",
954+
params={
955+
"usages": usages,
956+
},
957+
)
958+
959+
self._throw_on_error(res)
960+
return unmarshal_ListAlgorithmsResponse(res.json())

0 commit comments

Comments
 (0)