Skip to content

Commit dade839

Browse files
authored
feat(secret): add support for RestoreSecretRequest and RestoreSecretVersionRequest (scaleway#861)
1 parent 30d5e30 commit dade839

File tree

8 files changed

+278
-0
lines changed

8 files changed

+278
-0
lines changed

scaleway-async/scaleway_async/secret/v1beta1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
from .types import ListTagsRequest
4040
from .types import ListTagsResponse
4141
from .types import ProtectSecretRequest
42+
from .types import RestoreSecretRequest
43+
from .types import RestoreSecretVersionRequest
4244
from .types import SSHKey
4345
from .types import UnprotectSecretRequest
4446
from .types import UpdateSecretRequest
@@ -85,6 +87,8 @@
8587
"ListTagsRequest",
8688
"ListTagsResponse",
8789
"ProtectSecretRequest",
90+
"RestoreSecretRequest",
91+
"RestoreSecretVersionRequest",
8892
"SSHKey",
8993
"UnprotectSecretRequest",
9094
"UpdateSecretRequest",

scaleway-async/scaleway_async/secret/v1beta1/api.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ async def list_secrets(
253253
path: Optional[str] = None,
254254
ephemeral: Optional[bool] = None,
255255
type_: Optional[SecretType] = None,
256+
scheduled_for_deletion: Optional[bool] = None,
256257
) -> ListSecretsResponse:
257258
"""
258259
List secrets.
@@ -268,6 +269,7 @@ async def list_secrets(
268269
:param path: Filter by exact path (optional).
269270
:param ephemeral: Filter by ephemeral / not ephemeral (optional).
270271
:param type_: Filter by secret type (optional).
272+
:param scheduled_for_deletion: Filter by whether the secret was scheduled for deletion / not scheduled for deletion (optional).
271273
:return: :class:`ListSecretsResponse <ListSecretsResponse>`
272274
273275
Usage:
@@ -293,6 +295,7 @@ async def list_secrets(
293295
"page_size": page_size or self.client.default_page_size,
294296
"path": path,
295297
"project_id": project_id or self.client.default_project_id,
298+
"scheduled_for_deletion": scheduled_for_deletion,
296299
"tags": tags,
297300
"type": type_,
298301
},
@@ -315,6 +318,7 @@ async def list_secrets_all(
315318
path: Optional[str] = None,
316319
ephemeral: Optional[bool] = None,
317320
type_: Optional[SecretType] = None,
321+
scheduled_for_deletion: Optional[bool] = None,
318322
) -> List[Secret]:
319323
"""
320324
List secrets.
@@ -330,6 +334,7 @@ async def list_secrets_all(
330334
:param path: Filter by exact path (optional).
331335
:param ephemeral: Filter by ephemeral / not ephemeral (optional).
332336
:param type_: Filter by secret type (optional).
337+
:param scheduled_for_deletion: Filter by whether the secret was scheduled for deletion / not scheduled for deletion (optional).
333338
:return: :class:`List[Secret] <List[Secret]>`
334339
335340
Usage:
@@ -354,6 +359,7 @@ async def list_secrets_all(
354359
"path": path,
355360
"ephemeral": ephemeral,
356361
"type_": type_,
362+
"scheduled_for_deletion": scheduled_for_deletion,
357363
},
358364
)
359365

@@ -1120,3 +1126,77 @@ async def list_secret_types_all(
11201126
"page_size": page_size,
11211127
},
11221128
)
1129+
1130+
async def restore_secret_version(
1131+
self,
1132+
*,
1133+
secret_id: str,
1134+
revision: str,
1135+
region: Optional[ScwRegion] = None,
1136+
) -> SecretVersion:
1137+
"""
1138+
Restore a version.
1139+
Restore a secret's version specified by the `region`, `secret_id` and `revision` parameters.
1140+
:param secret_id:
1141+
:param revision:
1142+
:param region: Region to target. If none is passed will use default region from the config.
1143+
:return: :class:`SecretVersion <SecretVersion>`
1144+
1145+
Usage:
1146+
::
1147+
1148+
result = await api.restore_secret_version(
1149+
secret_id="example",
1150+
revision="example",
1151+
)
1152+
"""
1153+
1154+
param_region = validate_path_param(
1155+
"region", region or self.client.default_region
1156+
)
1157+
param_secret_id = validate_path_param("secret_id", secret_id)
1158+
param_revision = validate_path_param("revision", revision)
1159+
1160+
res = self._request(
1161+
"POST",
1162+
f"/secret-manager/v1beta1/regions/{param_region}/secrets/{param_secret_id}/versions/{param_revision}/restore",
1163+
body={},
1164+
)
1165+
1166+
self._throw_on_error(res)
1167+
return unmarshal_SecretVersion(res.json())
1168+
1169+
async def restore_secret(
1170+
self,
1171+
*,
1172+
secret_id: str,
1173+
region: Optional[ScwRegion] = None,
1174+
) -> Secret:
1175+
"""
1176+
Restore a secret.
1177+
Restore a secret and all its versions scheduled for deletion specified by the `region` and `secret_id` parameters.
1178+
:param secret_id:
1179+
:param region: Region to target. If none is passed will use default region from the config.
1180+
:return: :class:`Secret <Secret>`
1181+
1182+
Usage:
1183+
::
1184+
1185+
result = await api.restore_secret(
1186+
secret_id="example",
1187+
)
1188+
"""
1189+
1190+
param_region = validate_path_param(
1191+
"region", region or self.client.default_region
1192+
)
1193+
param_secret_id = validate_path_param("secret_id", secret_id)
1194+
1195+
res = self._request(
1196+
"POST",
1197+
f"/secret-manager/v1beta1/regions/{param_region}/secrets/{param_secret_id}/restore",
1198+
body={},
1199+
)
1200+
1201+
self._throw_on_error(res)
1202+
return unmarshal_Secret(res.json())

scaleway-async/scaleway_async/secret/v1beta1/marshalling.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ def unmarshal_SecretVersion(data: Any) -> SecretVersion:
110110
else:
111111
args["ephemeral_properties"] = None
112112

113+
field = data.get("deletion_requested_at", None)
114+
if field is not None:
115+
args["deletion_requested_at"] = (
116+
parser.isoparse(field) if isinstance(field, str) else field
117+
)
118+
else:
119+
args["deletion_requested_at"] = None
120+
113121
return SecretVersion(**args)
114122

115123

@@ -220,6 +228,14 @@ def unmarshal_Secret(data: Any) -> Secret:
220228
else:
221229
args["ephemeral_policy"] = None
222230

231+
field = data.get("deletion_requested_at", None)
232+
if field is not None:
233+
args["deletion_requested_at"] = (
234+
parser.isoparse(field) if isinstance(field, str) else field
235+
)
236+
else:
237+
args["deletion_requested_at"] = None
238+
223239
return Secret(**args)
224240

225241

scaleway-async/scaleway_async/secret/v1beta1/types.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class SecretVersionStatus(str, Enum, metaclass=StrEnumMeta):
8383
ENABLED = "enabled"
8484
DISABLED = "disabled"
8585
DELETED = "deleted"
86+
SCHEDULED_FOR_DELETION = "scheduled_for_deletion"
8687

8788
def __str__(self) -> str:
8889
return str(self.value)
@@ -174,6 +175,7 @@ class SecretVersion:
174175
* `unknown_status`: the version is in an invalid state.
175176
* `enabled`: the version is accessible.
176177
* `disabled`: the version is not accessible but can be enabled.
178+
* `scheduled_for_deletion`: the version is scheduled for deletion. It will be deleted in 7 days.
177179
* `deleted`: the version is permanently deleted. It is not possible to recover it.
178180
"""
179181

@@ -207,6 +209,11 @@ class SecretVersion:
207209
Returns the version's expiration date, whether it expires after being accessed once, and the action to perform (disable or delete) once the version expires.
208210
"""
209211

212+
deletion_requested_at: Optional[datetime]
213+
"""
214+
Returns the time at which deletion was requested.
215+
"""
216+
210217

211218
@dataclass
212219
class Secret:
@@ -291,6 +298,11 @@ class Secret:
291298
(Optional.) Policy that defines whether/when a secret's versions expire. By default, the policy is applied to all the secret's versions.
292299
"""
293300

301+
deletion_requested_at: Optional[datetime]
302+
"""
303+
Returns the time at which deletion was requested.
304+
"""
305+
294306

295307
@dataclass
296308
class AccessSecretVersionByPathRequest:
@@ -792,6 +804,11 @@ class ListSecretsRequest:
792804
Filter by secret type (optional).
793805
"""
794806

807+
scheduled_for_deletion: Optional[bool]
808+
"""
809+
Filter by whether the secret was scheduled for deletion / not scheduled for deletion (optional).
810+
"""
811+
795812

796813
@dataclass
797814
class ListSecretsResponse:
@@ -849,6 +866,28 @@ class ProtectSecretRequest:
849866
"""
850867

851868

869+
@dataclass
870+
class RestoreSecretRequest:
871+
secret_id: str
872+
873+
region: Optional[ScwRegion]
874+
"""
875+
Region to target. If none is passed will use default region from the config.
876+
"""
877+
878+
879+
@dataclass
880+
class RestoreSecretVersionRequest:
881+
secret_id: str
882+
883+
revision: str
884+
885+
region: Optional[ScwRegion]
886+
"""
887+
Region to target. If none is passed will use default region from the config.
888+
"""
889+
890+
852891
@dataclass
853892
class SSHKey:
854893
ssh_private_key: str

scaleway/scaleway/secret/v1beta1/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
from .types import ListTagsRequest
4040
from .types import ListTagsResponse
4141
from .types import ProtectSecretRequest
42+
from .types import RestoreSecretRequest
43+
from .types import RestoreSecretVersionRequest
4244
from .types import SSHKey
4345
from .types import UnprotectSecretRequest
4446
from .types import UpdateSecretRequest
@@ -85,6 +87,8 @@
8587
"ListTagsRequest",
8688
"ListTagsResponse",
8789
"ProtectSecretRequest",
90+
"RestoreSecretRequest",
91+
"RestoreSecretVersionRequest",
8892
"SSHKey",
8993
"UnprotectSecretRequest",
9094
"UpdateSecretRequest",

scaleway/scaleway/secret/v1beta1/api.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ def list_secrets(
253253
path: Optional[str] = None,
254254
ephemeral: Optional[bool] = None,
255255
type_: Optional[SecretType] = None,
256+
scheduled_for_deletion: Optional[bool] = None,
256257
) -> ListSecretsResponse:
257258
"""
258259
List secrets.
@@ -268,6 +269,7 @@ def list_secrets(
268269
:param path: Filter by exact path (optional).
269270
:param ephemeral: Filter by ephemeral / not ephemeral (optional).
270271
:param type_: Filter by secret type (optional).
272+
:param scheduled_for_deletion: Filter by whether the secret was scheduled for deletion / not scheduled for deletion (optional).
271273
:return: :class:`ListSecretsResponse <ListSecretsResponse>`
272274
273275
Usage:
@@ -293,6 +295,7 @@ def list_secrets(
293295
"page_size": page_size or self.client.default_page_size,
294296
"path": path,
295297
"project_id": project_id or self.client.default_project_id,
298+
"scheduled_for_deletion": scheduled_for_deletion,
296299
"tags": tags,
297300
"type": type_,
298301
},
@@ -315,6 +318,7 @@ def list_secrets_all(
315318
path: Optional[str] = None,
316319
ephemeral: Optional[bool] = None,
317320
type_: Optional[SecretType] = None,
321+
scheduled_for_deletion: Optional[bool] = None,
318322
) -> List[Secret]:
319323
"""
320324
List secrets.
@@ -330,6 +334,7 @@ def list_secrets_all(
330334
:param path: Filter by exact path (optional).
331335
:param ephemeral: Filter by ephemeral / not ephemeral (optional).
332336
:param type_: Filter by secret type (optional).
337+
:param scheduled_for_deletion: Filter by whether the secret was scheduled for deletion / not scheduled for deletion (optional).
333338
:return: :class:`List[Secret] <List[Secret]>`
334339
335340
Usage:
@@ -354,6 +359,7 @@ def list_secrets_all(
354359
"path": path,
355360
"ephemeral": ephemeral,
356361
"type_": type_,
362+
"scheduled_for_deletion": scheduled_for_deletion,
357363
},
358364
)
359365

@@ -1120,3 +1126,77 @@ def list_secret_types_all(
11201126
"page_size": page_size,
11211127
},
11221128
)
1129+
1130+
def restore_secret_version(
1131+
self,
1132+
*,
1133+
secret_id: str,
1134+
revision: str,
1135+
region: Optional[ScwRegion] = None,
1136+
) -> SecretVersion:
1137+
"""
1138+
Restore a version.
1139+
Restore a secret's version specified by the `region`, `secret_id` and `revision` parameters.
1140+
:param secret_id:
1141+
:param revision:
1142+
:param region: Region to target. If none is passed will use default region from the config.
1143+
:return: :class:`SecretVersion <SecretVersion>`
1144+
1145+
Usage:
1146+
::
1147+
1148+
result = api.restore_secret_version(
1149+
secret_id="example",
1150+
revision="example",
1151+
)
1152+
"""
1153+
1154+
param_region = validate_path_param(
1155+
"region", region or self.client.default_region
1156+
)
1157+
param_secret_id = validate_path_param("secret_id", secret_id)
1158+
param_revision = validate_path_param("revision", revision)
1159+
1160+
res = self._request(
1161+
"POST",
1162+
f"/secret-manager/v1beta1/regions/{param_region}/secrets/{param_secret_id}/versions/{param_revision}/restore",
1163+
body={},
1164+
)
1165+
1166+
self._throw_on_error(res)
1167+
return unmarshal_SecretVersion(res.json())
1168+
1169+
def restore_secret(
1170+
self,
1171+
*,
1172+
secret_id: str,
1173+
region: Optional[ScwRegion] = None,
1174+
) -> Secret:
1175+
"""
1176+
Restore a secret.
1177+
Restore a secret and all its versions scheduled for deletion specified by the `region` and `secret_id` parameters.
1178+
:param secret_id:
1179+
:param region: Region to target. If none is passed will use default region from the config.
1180+
:return: :class:`Secret <Secret>`
1181+
1182+
Usage:
1183+
::
1184+
1185+
result = api.restore_secret(
1186+
secret_id="example",
1187+
)
1188+
"""
1189+
1190+
param_region = validate_path_param(
1191+
"region", region or self.client.default_region
1192+
)
1193+
param_secret_id = validate_path_param("secret_id", secret_id)
1194+
1195+
res = self._request(
1196+
"POST",
1197+
f"/secret-manager/v1beta1/regions/{param_region}/secrets/{param_secret_id}/restore",
1198+
body={},
1199+
)
1200+
1201+
self._throw_on_error(res)
1202+
return unmarshal_Secret(res.json())

0 commit comments

Comments
 (0)