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 @@ -29,6 +29,7 @@
from .types import ListKeysResponse
from .types import ProtectKeyRequest
from .types import PublicKey
from .types import RestoreKeyRequest
from .types import RotateKeyRequest
from .types import SignRequest
from .types import SignResponse
Expand Down Expand Up @@ -68,6 +69,7 @@
"ListKeysResponse",
"ProtectKeyRequest",
"PublicKey",
"RestoreKeyRequest",
"RotateKeyRequest",
"SignRequest",
"SignResponse",
Expand Down
49 changes: 47 additions & 2 deletions scaleway-async/scaleway_async/key_manager/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ async def disable_key(
async def list_keys(
self,
*,
scheduled_for_deletion: bool,
region: Optional[ScwRegion] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
Expand All @@ -465,6 +466,7 @@ async def list_keys(
"""
List keys.
Retrieve a list of keys across all Projects in an Organization or within a specific Project. You must specify the `region`, and either the `organization_id` or the `project_id`.
:param scheduled_for_deletion: Filter keys based on their deletion status. By default, only keys not scheduled for deletion are returned in the output.
:param region: Region to target. If none is passed will use default region from the config.
:param organization_id: (Optional) Filter by Organization ID.
:param project_id: (Optional) Filter by Project ID.
Expand All @@ -479,7 +481,9 @@ async def list_keys(
Usage:
::

result = await api.list_keys()
result = await api.list_keys(
scheduled_for_deletion=False,
)
"""

param_region = validate_path_param(
Expand All @@ -497,6 +501,7 @@ async def list_keys(
"page": page,
"page_size": page_size or self.client.default_page_size,
"project_id": project_id or self.client.default_project_id,
"scheduled_for_deletion": scheduled_for_deletion,
"tags": tags,
"usage": usage,
},
Expand All @@ -508,6 +513,7 @@ async def list_keys(
async def list_keys_all(
self,
*,
scheduled_for_deletion: bool,
region: Optional[ScwRegion] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
Expand All @@ -521,6 +527,7 @@ async def list_keys_all(
"""
List keys.
Retrieve a list of keys across all Projects in an Organization or within a specific Project. You must specify the `region`, and either the `organization_id` or the `project_id`.
:param scheduled_for_deletion: Filter keys based on their deletion status. By default, only keys not scheduled for deletion are returned in the output.
:param region: Region to target. If none is passed will use default region from the config.
:param organization_id: (Optional) Filter by Organization ID.
:param project_id: (Optional) Filter by Project ID.
Expand All @@ -535,14 +542,17 @@ async def list_keys_all(
Usage:
::

result = await api.list_keys_all()
result = await api.list_keys_all(
scheduled_for_deletion=False,
)
"""

return await fetch_all_pages_async(
type=ListKeysResponse,
key="keys",
fetcher=self.list_keys,
args={
"scheduled_for_deletion": scheduled_for_deletion,
"region": region,
"organization_id": organization_id,
"project_id": project_id,
Expand Down Expand Up @@ -876,3 +886,38 @@ async def delete_key_material(
)

self._throw_on_error(res)

async def restore_key(
self,
*,
key_id: str,
region: Optional[ScwRegion] = None,
) -> Key:
"""
Restore a key.
Restore a key and all its rotations scheduled for deletion specified by the `region` and `key_id` parameters.
:param key_id:
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Key <Key>`

Usage:
::

result = await api.restore_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(
"POST",
f"/key-manager/v1alpha1/regions/{param_region}/keys/{param_key_id}/restore",
body={},
)

self._throw_on_error(res)
return unmarshal_Key(res.json())
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ def unmarshal_Key(data: Any) -> Key:
else:
args["rotation_policy"] = None

field = data.get("deletion_requested_at", None)
if field is not None:
args["deletion_requested_at"] = (
parser.isoparse(field) if isinstance(field, str) else field
)
else:
args["deletion_requested_at"] = None

return Key(**args)


Expand Down
20 changes: 20 additions & 0 deletions scaleway-async/scaleway_async/key_manager/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ class Key:
Key rotation policy.
"""

deletion_requested_at: Optional[datetime]
"""
Returns the time at which deletion was requested.
"""


@dataclass
class CreateKeyRequest:
Expand Down Expand Up @@ -482,6 +487,11 @@ class ImportKeyMaterialRequest:

@dataclass
class ListKeysRequest:
scheduled_for_deletion: bool
"""
Filter keys based on their deletion status. By default, only keys not scheduled for deletion are returned in the output.
"""

region: Optional[ScwRegion]
"""
Region to target. If none is passed will use default region from the config.
Expand Down Expand Up @@ -550,6 +560,16 @@ class PublicKey:
pem: str


@dataclass
class RestoreKeyRequest:
key_id: str

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


@dataclass
class RotateKeyRequest:
key_id: str
Expand Down
2 changes: 2 additions & 0 deletions scaleway/scaleway/key_manager/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .types import ListKeysResponse
from .types import ProtectKeyRequest
from .types import PublicKey
from .types import RestoreKeyRequest
from .types import RotateKeyRequest
from .types import SignRequest
from .types import SignResponse
Expand Down Expand Up @@ -68,6 +69,7 @@
"ListKeysResponse",
"ProtectKeyRequest",
"PublicKey",
"RestoreKeyRequest",
"RotateKeyRequest",
"SignRequest",
"SignResponse",
Expand Down
49 changes: 47 additions & 2 deletions scaleway/scaleway/key_manager/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def disable_key(
def list_keys(
self,
*,
scheduled_for_deletion: bool,
region: Optional[ScwRegion] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
Expand All @@ -465,6 +466,7 @@ def list_keys(
"""
List keys.
Retrieve a list of keys across all Projects in an Organization or within a specific Project. You must specify the `region`, and either the `organization_id` or the `project_id`.
:param scheduled_for_deletion: Filter keys based on their deletion status. By default, only keys not scheduled for deletion are returned in the output.
:param region: Region to target. If none is passed will use default region from the config.
:param organization_id: (Optional) Filter by Organization ID.
:param project_id: (Optional) Filter by Project ID.
Expand All @@ -479,7 +481,9 @@ def list_keys(
Usage:
::

result = api.list_keys()
result = api.list_keys(
scheduled_for_deletion=False,
)
"""

param_region = validate_path_param(
Expand All @@ -497,6 +501,7 @@ def list_keys(
"page": page,
"page_size": page_size or self.client.default_page_size,
"project_id": project_id or self.client.default_project_id,
"scheduled_for_deletion": scheduled_for_deletion,
"tags": tags,
"usage": usage,
},
Expand All @@ -508,6 +513,7 @@ def list_keys(
def list_keys_all(
self,
*,
scheduled_for_deletion: bool,
region: Optional[ScwRegion] = None,
organization_id: Optional[str] = None,
project_id: Optional[str] = None,
Expand All @@ -521,6 +527,7 @@ def list_keys_all(
"""
List keys.
Retrieve a list of keys across all Projects in an Organization or within a specific Project. You must specify the `region`, and either the `organization_id` or the `project_id`.
:param scheduled_for_deletion: Filter keys based on their deletion status. By default, only keys not scheduled for deletion are returned in the output.
:param region: Region to target. If none is passed will use default region from the config.
:param organization_id: (Optional) Filter by Organization ID.
:param project_id: (Optional) Filter by Project ID.
Expand All @@ -535,14 +542,17 @@ def list_keys_all(
Usage:
::

result = api.list_keys_all()
result = api.list_keys_all(
scheduled_for_deletion=False,
)
"""

return fetch_all_pages(
type=ListKeysResponse,
key="keys",
fetcher=self.list_keys,
args={
"scheduled_for_deletion": scheduled_for_deletion,
"region": region,
"organization_id": organization_id,
"project_id": project_id,
Expand Down Expand Up @@ -876,3 +886,38 @@ def delete_key_material(
)

self._throw_on_error(res)

def restore_key(
self,
*,
key_id: str,
region: Optional[ScwRegion] = None,
) -> Key:
"""
Restore a key.
Restore a key and all its rotations scheduled for deletion specified by the `region` and `key_id` parameters.
:param key_id:
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`Key <Key>`

Usage:
::

result = api.restore_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(
"POST",
f"/key-manager/v1alpha1/regions/{param_region}/keys/{param_key_id}/restore",
body={},
)

self._throw_on_error(res)
return unmarshal_Key(res.json())
8 changes: 8 additions & 0 deletions scaleway/scaleway/key_manager/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ def unmarshal_Key(data: Any) -> Key:
else:
args["rotation_policy"] = None

field = data.get("deletion_requested_at", None)
if field is not None:
args["deletion_requested_at"] = (
parser.isoparse(field) if isinstance(field, str) else field
)
else:
args["deletion_requested_at"] = None

return Key(**args)


Expand Down
20 changes: 20 additions & 0 deletions scaleway/scaleway/key_manager/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ class Key:
Key rotation policy.
"""

deletion_requested_at: Optional[datetime]
"""
Returns the time at which deletion was requested.
"""


@dataclass
class CreateKeyRequest:
Expand Down Expand Up @@ -482,6 +487,11 @@ class ImportKeyMaterialRequest:

@dataclass
class ListKeysRequest:
scheduled_for_deletion: bool
"""
Filter keys based on their deletion status. By default, only keys not scheduled for deletion are returned in the output.
"""

region: Optional[ScwRegion]
"""
Region to target. If none is passed will use default region from the config.
Expand Down Expand Up @@ -550,6 +560,16 @@ class PublicKey:
pem: str


@dataclass
class RestoreKeyRequest:
key_id: str

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


@dataclass
class RotateKeyRequest:
key_id: str
Expand Down