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 @@ -20,10 +20,12 @@
from .types import EncryptResponse
from .types import GenerateDataKeyRequest
from .types import GetKeyRequest
from .types import GetPublicKeyRequest
from .types import ImportKeyMaterialRequest
from .types import ListKeysRequest
from .types import ListKeysResponse
from .types import ProtectKeyRequest
from .types import PublicKey
from .types import RotateKeyRequest
from .types import UnprotectKeyRequest
from .types import UpdateKeyRequest
Expand All @@ -50,10 +52,12 @@
"EncryptResponse",
"GenerateDataKeyRequest",
"GetKeyRequest",
"GetPublicKeyRequest",
"ImportKeyMaterialRequest",
"ListKeysRequest",
"ListKeysResponse",
"ProtectKeyRequest",
"PublicKey",
"RotateKeyRequest",
"UnprotectKeyRequest",
"UpdateKeyRequest",
Expand Down
36 changes: 36 additions & 0 deletions scaleway-async/scaleway_async/key_manager/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
KeyRotationPolicy,
KeyUsage,
ListKeysResponse,
PublicKey,
UpdateKeyRequest,
)
from .marshalling import (
Expand All @@ -35,6 +36,7 @@
unmarshal_DecryptResponse,
unmarshal_EncryptResponse,
unmarshal_ListKeysResponse,
unmarshal_PublicKey,
marshal_CreateKeyRequest,
marshal_DecryptRequest,
marshal_EncryptRequest,
Expand Down Expand Up @@ -144,6 +146,40 @@ async def get_key(
self._throw_on_error(res)
return unmarshal_Key(res.json())

async def get_public_key(
self,
*,
key_id: str,
region: Optional[ScwRegion] = None,
) -> PublicKey:
"""
Get the public key in PEM format.
Retrieves the public portion of an asymmetric cryptographic key in PEM format.
:param key_id: ID of the key.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`PublicKey <PublicKey>`

Usage:
::

result = await api.get_public_key(
key_id="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_key_id = validate_path_param("key_id", key_id)

res = self._request(
"GET",
f"/key-manager/v1alpha1/regions/{param_region}/keys/{param_key_id}/public-key",
)

self._throw_on_error(res)
return unmarshal_PublicKey(res.json())

async def update_key(
self,
*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
DecryptResponse,
EncryptResponse,
ListKeysResponse,
PublicKey,
CreateKeyRequest,
DecryptRequest,
EncryptRequest,
Expand Down Expand Up @@ -253,6 +254,21 @@ def unmarshal_ListKeysResponse(data: Any) -> ListKeysResponse:
return ListKeysResponse(**args)


def unmarshal_PublicKey(data: Any) -> PublicKey:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'PublicKey' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("pem", None)
if field is not None:
args["pem"] = field

return PublicKey(**args)


def marshal_KeyRotationPolicy(
request: KeyRotationPolicy,
defaults: ProfileDefaults,
Expand Down
18 changes: 18 additions & 0 deletions scaleway-async/scaleway_async/key_manager/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,19 @@ class GetKeyRequest:
"""


@dataclass
class GetPublicKeyRequest:
key_id: str
"""
ID of the key.
"""

region: Optional[ScwRegion]
"""
Region to target. If none is passed will use default region from the config.
"""


@dataclass
class ImportKeyMaterialRequest:
key_id: str
Expand Down Expand Up @@ -488,6 +501,11 @@ class ProtectKeyRequest:
"""


@dataclass
class PublicKey:
pem: str


@dataclass
class RotateKeyRequest:
key_id: str
Expand Down
4 changes: 4 additions & 0 deletions scaleway/scaleway/key_manager/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
from .types import EncryptResponse
from .types import GenerateDataKeyRequest
from .types import GetKeyRequest
from .types import GetPublicKeyRequest
from .types import ImportKeyMaterialRequest
from .types import ListKeysRequest
from .types import ListKeysResponse
from .types import ProtectKeyRequest
from .types import PublicKey
from .types import RotateKeyRequest
from .types import UnprotectKeyRequest
from .types import UpdateKeyRequest
Expand All @@ -50,10 +52,12 @@
"EncryptResponse",
"GenerateDataKeyRequest",
"GetKeyRequest",
"GetPublicKeyRequest",
"ImportKeyMaterialRequest",
"ListKeysRequest",
"ListKeysResponse",
"ProtectKeyRequest",
"PublicKey",
"RotateKeyRequest",
"UnprotectKeyRequest",
"UpdateKeyRequest",
Expand Down
36 changes: 36 additions & 0 deletions scaleway/scaleway/key_manager/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
KeyRotationPolicy,
KeyUsage,
ListKeysResponse,
PublicKey,
UpdateKeyRequest,
)
from .marshalling import (
Expand All @@ -35,6 +36,7 @@
unmarshal_DecryptResponse,
unmarshal_EncryptResponse,
unmarshal_ListKeysResponse,
unmarshal_PublicKey,
marshal_CreateKeyRequest,
marshal_DecryptRequest,
marshal_EncryptRequest,
Expand Down Expand Up @@ -144,6 +146,40 @@ def get_key(
self._throw_on_error(res)
return unmarshal_Key(res.json())

def get_public_key(
self,
*,
key_id: str,
region: Optional[ScwRegion] = None,
) -> PublicKey:
"""
Get the public key in PEM format.
Retrieves the public portion of an asymmetric cryptographic key in PEM format.
:param key_id: ID of the key.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`PublicKey <PublicKey>`

Usage:
::

result = api.get_public_key(
key_id="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_key_id = validate_path_param("key_id", key_id)

res = self._request(
"GET",
f"/key-manager/v1alpha1/regions/{param_region}/keys/{param_key_id}/public-key",
)

self._throw_on_error(res)
return unmarshal_PublicKey(res.json())

def update_key(
self,
*,
Expand Down
16 changes: 16 additions & 0 deletions scaleway/scaleway/key_manager/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
DecryptResponse,
EncryptResponse,
ListKeysResponse,
PublicKey,
CreateKeyRequest,
DecryptRequest,
EncryptRequest,
Expand Down Expand Up @@ -253,6 +254,21 @@ def unmarshal_ListKeysResponse(data: Any) -> ListKeysResponse:
return ListKeysResponse(**args)


def unmarshal_PublicKey(data: Any) -> PublicKey:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'PublicKey' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("pem", None)
if field is not None:
args["pem"] = field

return PublicKey(**args)


def marshal_KeyRotationPolicy(
request: KeyRotationPolicy,
defaults: ProfileDefaults,
Expand Down
18 changes: 18 additions & 0 deletions scaleway/scaleway/key_manager/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,19 @@ class GetKeyRequest:
"""


@dataclass
class GetPublicKeyRequest:
key_id: str
"""
ID of the key.
"""

region: Optional[ScwRegion]
"""
Region to target. If none is passed will use default region from the config.
"""


@dataclass
class ImportKeyMaterialRequest:
key_id: str
Expand Down Expand Up @@ -488,6 +501,11 @@ class ProtectKeyRequest:
"""


@dataclass
class PublicKey:
pem: str


@dataclass
class RotateKeyRequest:
key_id: str
Expand Down