diff --git a/scaleway-async/scaleway_async/key_manager/v1alpha1/__init__.py b/scaleway-async/scaleway_async/key_manager/v1alpha1/__init__.py index 37f05108..6e853a23 100644 --- a/scaleway-async/scaleway_async/key_manager/v1alpha1/__init__.py +++ b/scaleway-async/scaleway_async/key_manager/v1alpha1/__init__.py @@ -6,10 +6,12 @@ from .types import KeyAlgorithmSymmetricEncryption from .types import KeyOrigin from .types import KeyState +from .types import ListAlgorithmsRequestUsage from .types import ListKeysRequestOrderBy from .types import ListKeysRequestUsage from .types import KeyRotationPolicy from .types import KeyUsage +from .types import ListAlgorithmsResponseAlgorithm from .types import Key from .types import CreateKeyRequest from .types import DataKey @@ -25,6 +27,8 @@ from .types import GetKeyRequest from .types import GetPublicKeyRequest from .types import ImportKeyMaterialRequest +from .types import ListAlgorithmsRequest +from .types import ListAlgorithmsResponse from .types import ListKeysRequest from .types import ListKeysResponse from .types import ProtectKeyRequest @@ -46,10 +50,12 @@ "KeyAlgorithmSymmetricEncryption", "KeyOrigin", "KeyState", + "ListAlgorithmsRequestUsage", "ListKeysRequestOrderBy", "ListKeysRequestUsage", "KeyRotationPolicy", "KeyUsage", + "ListAlgorithmsResponseAlgorithm", "Key", "CreateKeyRequest", "DataKey", @@ -65,6 +71,8 @@ "GetKeyRequest", "GetPublicKeyRequest", "ImportKeyMaterialRequest", + "ListAlgorithmsRequest", + "ListAlgorithmsResponse", "ListKeysRequest", "ListKeysResponse", "ProtectKeyRequest", diff --git a/scaleway-async/scaleway_async/key_manager/v1alpha1/api.py b/scaleway-async/scaleway_async/key_manager/v1alpha1/api.py index ca75da13..4edec028 100644 --- a/scaleway-async/scaleway_async/key_manager/v1alpha1/api.py +++ b/scaleway-async/scaleway_async/key_manager/v1alpha1/api.py @@ -14,6 +14,7 @@ from .types import ( DataKeyAlgorithmSymmetricEncryption, KeyOrigin, + ListAlgorithmsRequestUsage, ListKeysRequestOrderBy, ListKeysRequestUsage, CreateKeyRequest, @@ -27,6 +28,7 @@ Key, KeyRotationPolicy, KeyUsage, + ListAlgorithmsResponse, ListKeysResponse, PublicKey, SignRequest, @@ -40,6 +42,7 @@ unmarshal_DataKey, unmarshal_DecryptResponse, unmarshal_EncryptResponse, + unmarshal_ListAlgorithmsResponse, unmarshal_ListKeysResponse, unmarshal_PublicKey, unmarshal_SignResponse, @@ -921,3 +924,37 @@ async def restore_key( self._throw_on_error(res) return unmarshal_Key(res.json()) + + async def list_algorithms( + self, + *, + region: Optional[ScwRegion] = None, + usages: Optional[List[ListAlgorithmsRequestUsage]] = None, + ) -> ListAlgorithmsResponse: + """ + List all available algorithms. + Lists all cryptographic algorithms supported by the Key Manager service. + :param region: Region to target. If none is passed will use default region from the config. + :param usages: Filter by key usage. + :return: :class:`ListAlgorithmsResponse ` + + Usage: + :: + + result = await api.list_algorithms() + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/key-manager/v1alpha1/regions/{param_region}/algorithms", + params={ + "usages": usages, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListAlgorithmsResponse(res.json()) diff --git a/scaleway-async/scaleway_async/key_manager/v1alpha1/marshalling.py b/scaleway-async/scaleway_async/key_manager/v1alpha1/marshalling.py index 69c8b037..4d709d56 100644 --- a/scaleway-async/scaleway_async/key_manager/v1alpha1/marshalling.py +++ b/scaleway-async/scaleway_async/key_manager/v1alpha1/marshalling.py @@ -20,6 +20,8 @@ DataKey, DecryptResponse, EncryptResponse, + ListAlgorithmsResponseAlgorithm, + ListAlgorithmsResponse, ListKeysResponse, PublicKey, SignResponse, @@ -301,6 +303,58 @@ def unmarshal_EncryptResponse(data: Any) -> EncryptResponse: return EncryptResponse(**args) +def unmarshal_ListAlgorithmsResponseAlgorithm( + data: Any, +) -> ListAlgorithmsResponseAlgorithm: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListAlgorithmsResponseAlgorithm' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("usage", None) + if field is not None: + args["usage"] = field + else: + args["usage"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + field = data.get("recommended", None) + if field is not None: + args["recommended"] = field + else: + args["recommended"] = None + + return ListAlgorithmsResponseAlgorithm(**args) + + +def unmarshal_ListAlgorithmsResponse(data: Any) -> ListAlgorithmsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListAlgorithmsResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("algorithms", None) + if field is not None: + args["algorithms"] = ( + [unmarshal_ListAlgorithmsResponseAlgorithm(v) for v in field] + if field is not None + else None + ) + else: + args["algorithms"] = [] + + return ListAlgorithmsResponse(**args) + + def unmarshal_ListKeysResponse(data: Any) -> ListKeysResponse: if not isinstance(data, dict): raise TypeError( diff --git a/scaleway-async/scaleway_async/key_manager/v1alpha1/types.py b/scaleway-async/scaleway_async/key_manager/v1alpha1/types.py index fdadc54d..407fa369 100644 --- a/scaleway-async/scaleway_async/key_manager/v1alpha1/types.py +++ b/scaleway-async/scaleway_async/key_manager/v1alpha1/types.py @@ -76,6 +76,16 @@ def __str__(self) -> str: return str(self.value) +class ListAlgorithmsRequestUsage(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_USAGE = "unknown_usage" + SYMMETRIC_ENCRYPTION = "symmetric_encryption" + ASYMMETRIC_ENCRYPTION = "asymmetric_encryption" + ASYMMETRIC_SIGNING = "asymmetric_signing" + + def __str__(self) -> str: + return str(self.value) + + class ListKeysRequestOrderBy(str, Enum, metaclass=StrEnumMeta): NAME_ASC = "name_asc" NAME_DESC = "name_desc" @@ -122,6 +132,13 @@ class KeyUsage: asymmetric_signing: Optional[KeyAlgorithmAsymmetricSigning] = None +@dataclass +class ListAlgorithmsResponseAlgorithm: + usage: str + name: str + recommended: bool + + @dataclass class Key: id: str @@ -490,6 +507,27 @@ class ImportKeyMaterialRequest: """ +@dataclass +class ListAlgorithmsRequest: + region: Optional[ScwRegion] = None + """ + Region to target. If none is passed will use default region from the config. + """ + + usages: Optional[List[ListAlgorithmsRequestUsage]] = field(default_factory=list) + """ + Filter by key usage. + """ + + +@dataclass +class ListAlgorithmsResponse: + algorithms: List[ListAlgorithmsResponseAlgorithm] + """ + Returns a list of algorithms matching the requested criteria. + """ + + @dataclass class ListKeysRequest: scheduled_for_deletion: bool diff --git a/scaleway/scaleway/key_manager/v1alpha1/__init__.py b/scaleway/scaleway/key_manager/v1alpha1/__init__.py index 37f05108..6e853a23 100644 --- a/scaleway/scaleway/key_manager/v1alpha1/__init__.py +++ b/scaleway/scaleway/key_manager/v1alpha1/__init__.py @@ -6,10 +6,12 @@ from .types import KeyAlgorithmSymmetricEncryption from .types import KeyOrigin from .types import KeyState +from .types import ListAlgorithmsRequestUsage from .types import ListKeysRequestOrderBy from .types import ListKeysRequestUsage from .types import KeyRotationPolicy from .types import KeyUsage +from .types import ListAlgorithmsResponseAlgorithm from .types import Key from .types import CreateKeyRequest from .types import DataKey @@ -25,6 +27,8 @@ from .types import GetKeyRequest from .types import GetPublicKeyRequest from .types import ImportKeyMaterialRequest +from .types import ListAlgorithmsRequest +from .types import ListAlgorithmsResponse from .types import ListKeysRequest from .types import ListKeysResponse from .types import ProtectKeyRequest @@ -46,10 +50,12 @@ "KeyAlgorithmSymmetricEncryption", "KeyOrigin", "KeyState", + "ListAlgorithmsRequestUsage", "ListKeysRequestOrderBy", "ListKeysRequestUsage", "KeyRotationPolicy", "KeyUsage", + "ListAlgorithmsResponseAlgorithm", "Key", "CreateKeyRequest", "DataKey", @@ -65,6 +71,8 @@ "GetKeyRequest", "GetPublicKeyRequest", "ImportKeyMaterialRequest", + "ListAlgorithmsRequest", + "ListAlgorithmsResponse", "ListKeysRequest", "ListKeysResponse", "ProtectKeyRequest", diff --git a/scaleway/scaleway/key_manager/v1alpha1/api.py b/scaleway/scaleway/key_manager/v1alpha1/api.py index 8dfaa94e..d22caef0 100644 --- a/scaleway/scaleway/key_manager/v1alpha1/api.py +++ b/scaleway/scaleway/key_manager/v1alpha1/api.py @@ -14,6 +14,7 @@ from .types import ( DataKeyAlgorithmSymmetricEncryption, KeyOrigin, + ListAlgorithmsRequestUsage, ListKeysRequestOrderBy, ListKeysRequestUsage, CreateKeyRequest, @@ -27,6 +28,7 @@ Key, KeyRotationPolicy, KeyUsage, + ListAlgorithmsResponse, ListKeysResponse, PublicKey, SignRequest, @@ -40,6 +42,7 @@ unmarshal_DataKey, unmarshal_DecryptResponse, unmarshal_EncryptResponse, + unmarshal_ListAlgorithmsResponse, unmarshal_ListKeysResponse, unmarshal_PublicKey, unmarshal_SignResponse, @@ -921,3 +924,37 @@ def restore_key( self._throw_on_error(res) return unmarshal_Key(res.json()) + + def list_algorithms( + self, + *, + region: Optional[ScwRegion] = None, + usages: Optional[List[ListAlgorithmsRequestUsage]] = None, + ) -> ListAlgorithmsResponse: + """ + List all available algorithms. + Lists all cryptographic algorithms supported by the Key Manager service. + :param region: Region to target. If none is passed will use default region from the config. + :param usages: Filter by key usage. + :return: :class:`ListAlgorithmsResponse ` + + Usage: + :: + + result = api.list_algorithms() + """ + + param_region = validate_path_param( + "region", region or self.client.default_region + ) + + res = self._request( + "GET", + f"/key-manager/v1alpha1/regions/{param_region}/algorithms", + params={ + "usages": usages, + }, + ) + + self._throw_on_error(res) + return unmarshal_ListAlgorithmsResponse(res.json()) diff --git a/scaleway/scaleway/key_manager/v1alpha1/marshalling.py b/scaleway/scaleway/key_manager/v1alpha1/marshalling.py index 69c8b037..4d709d56 100644 --- a/scaleway/scaleway/key_manager/v1alpha1/marshalling.py +++ b/scaleway/scaleway/key_manager/v1alpha1/marshalling.py @@ -20,6 +20,8 @@ DataKey, DecryptResponse, EncryptResponse, + ListAlgorithmsResponseAlgorithm, + ListAlgorithmsResponse, ListKeysResponse, PublicKey, SignResponse, @@ -301,6 +303,58 @@ def unmarshal_EncryptResponse(data: Any) -> EncryptResponse: return EncryptResponse(**args) +def unmarshal_ListAlgorithmsResponseAlgorithm( + data: Any, +) -> ListAlgorithmsResponseAlgorithm: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListAlgorithmsResponseAlgorithm' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("usage", None) + if field is not None: + args["usage"] = field + else: + args["usage"] = None + + field = data.get("name", None) + if field is not None: + args["name"] = field + else: + args["name"] = None + + field = data.get("recommended", None) + if field is not None: + args["recommended"] = field + else: + args["recommended"] = None + + return ListAlgorithmsResponseAlgorithm(**args) + + +def unmarshal_ListAlgorithmsResponse(data: Any) -> ListAlgorithmsResponse: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'ListAlgorithmsResponse' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("algorithms", None) + if field is not None: + args["algorithms"] = ( + [unmarshal_ListAlgorithmsResponseAlgorithm(v) for v in field] + if field is not None + else None + ) + else: + args["algorithms"] = [] + + return ListAlgorithmsResponse(**args) + + def unmarshal_ListKeysResponse(data: Any) -> ListKeysResponse: if not isinstance(data, dict): raise TypeError( diff --git a/scaleway/scaleway/key_manager/v1alpha1/types.py b/scaleway/scaleway/key_manager/v1alpha1/types.py index fdadc54d..407fa369 100644 --- a/scaleway/scaleway/key_manager/v1alpha1/types.py +++ b/scaleway/scaleway/key_manager/v1alpha1/types.py @@ -76,6 +76,16 @@ def __str__(self) -> str: return str(self.value) +class ListAlgorithmsRequestUsage(str, Enum, metaclass=StrEnumMeta): + UNKNOWN_USAGE = "unknown_usage" + SYMMETRIC_ENCRYPTION = "symmetric_encryption" + ASYMMETRIC_ENCRYPTION = "asymmetric_encryption" + ASYMMETRIC_SIGNING = "asymmetric_signing" + + def __str__(self) -> str: + return str(self.value) + + class ListKeysRequestOrderBy(str, Enum, metaclass=StrEnumMeta): NAME_ASC = "name_asc" NAME_DESC = "name_desc" @@ -122,6 +132,13 @@ class KeyUsage: asymmetric_signing: Optional[KeyAlgorithmAsymmetricSigning] = None +@dataclass +class ListAlgorithmsResponseAlgorithm: + usage: str + name: str + recommended: bool + + @dataclass class Key: id: str @@ -490,6 +507,27 @@ class ImportKeyMaterialRequest: """ +@dataclass +class ListAlgorithmsRequest: + region: Optional[ScwRegion] = None + """ + Region to target. If none is passed will use default region from the config. + """ + + usages: Optional[List[ListAlgorithmsRequestUsage]] = field(default_factory=list) + """ + Filter by key usage. + """ + + +@dataclass +class ListAlgorithmsResponse: + algorithms: List[ListAlgorithmsResponseAlgorithm] + """ + Returns a list of algorithms matching the requested criteria. + """ + + @dataclass class ListKeysRequest: scheduled_for_deletion: bool