Skip to content

Commit f6ad8eb

Browse files
authored
feat(key_manager): add getpublickey endpoint (scaleway#975)
1 parent c1c8c0e commit f6ad8eb

File tree

8 files changed

+148
-0
lines changed

8 files changed

+148
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
from .types import EncryptResponse
2121
from .types import GenerateDataKeyRequest
2222
from .types import GetKeyRequest
23+
from .types import GetPublicKeyRequest
2324
from .types import ImportKeyMaterialRequest
2425
from .types import ListKeysRequest
2526
from .types import ListKeysResponse
2627
from .types import ProtectKeyRequest
28+
from .types import PublicKey
2729
from .types import RotateKeyRequest
2830
from .types import UnprotectKeyRequest
2931
from .types import UpdateKeyRequest
@@ -50,10 +52,12 @@
5052
"EncryptResponse",
5153
"GenerateDataKeyRequest",
5254
"GetKeyRequest",
55+
"GetPublicKeyRequest",
5356
"ImportKeyMaterialRequest",
5457
"ListKeysRequest",
5558
"ListKeysResponse",
5659
"ProtectKeyRequest",
60+
"PublicKey",
5761
"RotateKeyRequest",
5862
"UnprotectKeyRequest",
5963
"UpdateKeyRequest",

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
KeyRotationPolicy,
2828
KeyUsage,
2929
ListKeysResponse,
30+
PublicKey,
3031
UpdateKeyRequest,
3132
)
3233
from .marshalling import (
@@ -35,6 +36,7 @@
3536
unmarshal_DecryptResponse,
3637
unmarshal_EncryptResponse,
3738
unmarshal_ListKeysResponse,
39+
unmarshal_PublicKey,
3840
marshal_CreateKeyRequest,
3941
marshal_DecryptRequest,
4042
marshal_EncryptRequest,
@@ -144,6 +146,40 @@ async def get_key(
144146
self._throw_on_error(res)
145147
return unmarshal_Key(res.json())
146148

149+
async def get_public_key(
150+
self,
151+
*,
152+
key_id: str,
153+
region: Optional[ScwRegion] = None,
154+
) -> PublicKey:
155+
"""
156+
Get the public key in PEM format.
157+
Retrieves the public portion of an asymmetric cryptographic key in PEM format.
158+
:param key_id: ID of the key.
159+
:param region: Region to target. If none is passed will use default region from the config.
160+
:return: :class:`PublicKey <PublicKey>`
161+
162+
Usage:
163+
::
164+
165+
result = await api.get_public_key(
166+
key_id="example",
167+
)
168+
"""
169+
170+
param_region = validate_path_param(
171+
"region", region or self.client.default_region
172+
)
173+
param_key_id = validate_path_param("key_id", key_id)
174+
175+
res = self._request(
176+
"GET",
177+
f"/key-manager/v1alpha1/regions/{param_region}/keys/{param_key_id}/public-key",
178+
)
179+
180+
self._throw_on_error(res)
181+
return unmarshal_PublicKey(res.json())
182+
147183
async def update_key(
148184
self,
149185
*,

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
DecryptResponse,
1818
EncryptResponse,
1919
ListKeysResponse,
20+
PublicKey,
2021
CreateKeyRequest,
2122
DecryptRequest,
2223
EncryptRequest,
@@ -253,6 +254,21 @@ def unmarshal_ListKeysResponse(data: Any) -> ListKeysResponse:
253254
return ListKeysResponse(**args)
254255

255256

257+
def unmarshal_PublicKey(data: Any) -> PublicKey:
258+
if not isinstance(data, dict):
259+
raise TypeError(
260+
"Unmarshalling the type 'PublicKey' failed as data isn't a dictionary."
261+
)
262+
263+
args: Dict[str, Any] = {}
264+
265+
field = data.get("pem", None)
266+
if field is not None:
267+
args["pem"] = field
268+
269+
return PublicKey(**args)
270+
271+
256272
def marshal_KeyRotationPolicy(
257273
request: KeyRotationPolicy,
258274
defaults: ProfileDefaults,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,19 @@ class GetKeyRequest:
405405
"""
406406

407407

408+
@dataclass
409+
class GetPublicKeyRequest:
410+
key_id: str
411+
"""
412+
ID of the key.
413+
"""
414+
415+
region: Optional[ScwRegion]
416+
"""
417+
Region to target. If none is passed will use default region from the config.
418+
"""
419+
420+
408421
@dataclass
409422
class ImportKeyMaterialRequest:
410423
key_id: str
@@ -488,6 +501,11 @@ class ProtectKeyRequest:
488501
"""
489502

490503

504+
@dataclass
505+
class PublicKey:
506+
pem: str
507+
508+
491509
@dataclass
492510
class RotateKeyRequest:
493511
key_id: str

scaleway/scaleway/key_manager/v1alpha1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
from .types import EncryptResponse
2121
from .types import GenerateDataKeyRequest
2222
from .types import GetKeyRequest
23+
from .types import GetPublicKeyRequest
2324
from .types import ImportKeyMaterialRequest
2425
from .types import ListKeysRequest
2526
from .types import ListKeysResponse
2627
from .types import ProtectKeyRequest
28+
from .types import PublicKey
2729
from .types import RotateKeyRequest
2830
from .types import UnprotectKeyRequest
2931
from .types import UpdateKeyRequest
@@ -50,10 +52,12 @@
5052
"EncryptResponse",
5153
"GenerateDataKeyRequest",
5254
"GetKeyRequest",
55+
"GetPublicKeyRequest",
5356
"ImportKeyMaterialRequest",
5457
"ListKeysRequest",
5558
"ListKeysResponse",
5659
"ProtectKeyRequest",
60+
"PublicKey",
5761
"RotateKeyRequest",
5862
"UnprotectKeyRequest",
5963
"UpdateKeyRequest",

scaleway/scaleway/key_manager/v1alpha1/api.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
KeyRotationPolicy,
2828
KeyUsage,
2929
ListKeysResponse,
30+
PublicKey,
3031
UpdateKeyRequest,
3132
)
3233
from .marshalling import (
@@ -35,6 +36,7 @@
3536
unmarshal_DecryptResponse,
3637
unmarshal_EncryptResponse,
3738
unmarshal_ListKeysResponse,
39+
unmarshal_PublicKey,
3840
marshal_CreateKeyRequest,
3941
marshal_DecryptRequest,
4042
marshal_EncryptRequest,
@@ -144,6 +146,40 @@ def get_key(
144146
self._throw_on_error(res)
145147
return unmarshal_Key(res.json())
146148

149+
def get_public_key(
150+
self,
151+
*,
152+
key_id: str,
153+
region: Optional[ScwRegion] = None,
154+
) -> PublicKey:
155+
"""
156+
Get the public key in PEM format.
157+
Retrieves the public portion of an asymmetric cryptographic key in PEM format.
158+
:param key_id: ID of the key.
159+
:param region: Region to target. If none is passed will use default region from the config.
160+
:return: :class:`PublicKey <PublicKey>`
161+
162+
Usage:
163+
::
164+
165+
result = api.get_public_key(
166+
key_id="example",
167+
)
168+
"""
169+
170+
param_region = validate_path_param(
171+
"region", region or self.client.default_region
172+
)
173+
param_key_id = validate_path_param("key_id", key_id)
174+
175+
res = self._request(
176+
"GET",
177+
f"/key-manager/v1alpha1/regions/{param_region}/keys/{param_key_id}/public-key",
178+
)
179+
180+
self._throw_on_error(res)
181+
return unmarshal_PublicKey(res.json())
182+
147183
def update_key(
148184
self,
149185
*,

scaleway/scaleway/key_manager/v1alpha1/marshalling.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
DecryptResponse,
1818
EncryptResponse,
1919
ListKeysResponse,
20+
PublicKey,
2021
CreateKeyRequest,
2122
DecryptRequest,
2223
EncryptRequest,
@@ -253,6 +254,21 @@ def unmarshal_ListKeysResponse(data: Any) -> ListKeysResponse:
253254
return ListKeysResponse(**args)
254255

255256

257+
def unmarshal_PublicKey(data: Any) -> PublicKey:
258+
if not isinstance(data, dict):
259+
raise TypeError(
260+
"Unmarshalling the type 'PublicKey' failed as data isn't a dictionary."
261+
)
262+
263+
args: Dict[str, Any] = {}
264+
265+
field = data.get("pem", None)
266+
if field is not None:
267+
args["pem"] = field
268+
269+
return PublicKey(**args)
270+
271+
256272
def marshal_KeyRotationPolicy(
257273
request: KeyRotationPolicy,
258274
defaults: ProfileDefaults,

scaleway/scaleway/key_manager/v1alpha1/types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,19 @@ class GetKeyRequest:
405405
"""
406406

407407

408+
@dataclass
409+
class GetPublicKeyRequest:
410+
key_id: str
411+
"""
412+
ID of the key.
413+
"""
414+
415+
region: Optional[ScwRegion]
416+
"""
417+
Region to target. If none is passed will use default region from the config.
418+
"""
419+
420+
408421
@dataclass
409422
class ImportKeyMaterialRequest:
410423
key_id: str
@@ -488,6 +501,11 @@ class ProtectKeyRequest:
488501
"""
489502

490503

504+
@dataclass
505+
class PublicKey:
506+
pem: str
507+
508+
491509
@dataclass
492510
class RotateKeyRequest:
493511
key_id: str

0 commit comments

Comments
 (0)