Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -46,10 +50,12 @@
"KeyAlgorithmSymmetricEncryption",
"KeyOrigin",
"KeyState",
"ListAlgorithmsRequestUsage",
"ListKeysRequestOrderBy",
"ListKeysRequestUsage",
"KeyRotationPolicy",
"KeyUsage",
"ListAlgorithmsResponseAlgorithm",
"Key",
"CreateKeyRequest",
"DataKey",
Expand All @@ -65,6 +71,8 @@
"GetKeyRequest",
"GetPublicKeyRequest",
"ImportKeyMaterialRequest",
"ListAlgorithmsRequest",
"ListAlgorithmsResponse",
"ListKeysRequest",
"ListKeysResponse",
"ProtectKeyRequest",
Expand Down
37 changes: 37 additions & 0 deletions scaleway-async/scaleway_async/key_manager/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .types import (
DataKeyAlgorithmSymmetricEncryption,
KeyOrigin,
ListAlgorithmsRequestUsage,
ListKeysRequestOrderBy,
ListKeysRequestUsage,
CreateKeyRequest,
Expand All @@ -27,6 +28,7 @@
Key,
KeyRotationPolicy,
KeyUsage,
ListAlgorithmsResponse,
ListKeysResponse,
PublicKey,
SignRequest,
Expand All @@ -40,6 +42,7 @@
unmarshal_DataKey,
unmarshal_DecryptResponse,
unmarshal_EncryptResponse,
unmarshal_ListAlgorithmsResponse,
unmarshal_ListKeysResponse,
unmarshal_PublicKey,
unmarshal_SignResponse,
Expand Down Expand Up @@ -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 <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())
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
DataKey,
DecryptResponse,
EncryptResponse,
ListAlgorithmsResponseAlgorithm,
ListAlgorithmsResponse,
ListKeysResponse,
PublicKey,
SignResponse,
Expand Down Expand Up @@ -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(
Expand Down
38 changes: 38 additions & 0 deletions scaleway-async/scaleway_async/key_manager/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions scaleway/scaleway/key_manager/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -46,10 +50,12 @@
"KeyAlgorithmSymmetricEncryption",
"KeyOrigin",
"KeyState",
"ListAlgorithmsRequestUsage",
"ListKeysRequestOrderBy",
"ListKeysRequestUsage",
"KeyRotationPolicy",
"KeyUsage",
"ListAlgorithmsResponseAlgorithm",
"Key",
"CreateKeyRequest",
"DataKey",
Expand All @@ -65,6 +71,8 @@
"GetKeyRequest",
"GetPublicKeyRequest",
"ImportKeyMaterialRequest",
"ListAlgorithmsRequest",
"ListAlgorithmsResponse",
"ListKeysRequest",
"ListKeysResponse",
"ProtectKeyRequest",
Expand Down
37 changes: 37 additions & 0 deletions scaleway/scaleway/key_manager/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .types import (
DataKeyAlgorithmSymmetricEncryption,
KeyOrigin,
ListAlgorithmsRequestUsage,
ListKeysRequestOrderBy,
ListKeysRequestUsage,
CreateKeyRequest,
Expand All @@ -27,6 +28,7 @@
Key,
KeyRotationPolicy,
KeyUsage,
ListAlgorithmsResponse,
ListKeysResponse,
PublicKey,
SignRequest,
Expand All @@ -40,6 +42,7 @@
unmarshal_DataKey,
unmarshal_DecryptResponse,
unmarshal_EncryptResponse,
unmarshal_ListAlgorithmsResponse,
unmarshal_ListKeysResponse,
unmarshal_PublicKey,
unmarshal_SignResponse,
Expand Down Expand Up @@ -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 <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())
Loading
Loading