Skip to content

Commit eaf54ab

Browse files
feat(secret): add support for RestoreSecretRequest and RestoreSecretVersionRequest (#1826)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 1368798 commit eaf54ab

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

packages/clients/src/api/secret/v1beta1/api.gen.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import type {
4646
ListTagsRequest,
4747
ListTagsResponse,
4848
ProtectSecretRequest,
49+
RestoreSecretRequest,
50+
RestoreSecretVersionRequest,
4951
Secret,
5052
SecretVersion,
5153
UnprotectSecretRequest,
@@ -158,6 +160,7 @@ export class API extends ParentAPI {
158160
],
159161
['path', request.path],
160162
['project_id', request.projectId],
163+
['scheduled_for_deletion', request.scheduledForDeletion],
161164
['tags', request.tags],
162165
['type', request.type],
163166
),
@@ -496,4 +499,40 @@ export class API extends ParentAPI {
496499
*/
497500
listSecretTypes = (request: Readonly<ListSecretTypesRequest> = {}) =>
498501
enrichForPagination('types', this.pageOfListSecretTypes, request)
502+
503+
/**
504+
* Restore a version.. Restore a secret's version specified by the `region`,
505+
* `secret_id` and `revision` parameters.
506+
*
507+
* @param request - The request {@link RestoreSecretVersionRequest}
508+
* @returns A Promise of SecretVersion
509+
*/
510+
restoreSecretVersion = (request: Readonly<RestoreSecretVersionRequest>) =>
511+
this.client.fetch<SecretVersion>(
512+
{
513+
body: '{}',
514+
headers: jsonContentHeaders,
515+
method: 'POST',
516+
path: `/secret-manager/v1beta1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/secrets/${validatePathParam('secretId', request.secretId)}/versions/${validatePathParam('revision', request.revision)}/restore`,
517+
},
518+
unmarshalSecretVersion,
519+
)
520+
521+
/**
522+
* Restore a secret.. Restore a secret and all its versions scheduled for
523+
* deletion specified by the `region` and `secret_id` parameters.
524+
*
525+
* @param request - The request {@link RestoreSecretRequest}
526+
* @returns A Promise of Secret
527+
*/
528+
restoreSecret = (request: Readonly<RestoreSecretRequest>) =>
529+
this.client.fetch<Secret>(
530+
{
531+
body: '{}',
532+
headers: jsonContentHeaders,
533+
method: 'POST',
534+
path: `/secret-manager/v1beta1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/secrets/${validatePathParam('secretId', request.secretId)}/restore`,
535+
},
536+
unmarshalSecret,
537+
)
499538
}

packages/clients/src/api/secret/v1beta1/index.gen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export type {
3636
ListTagsResponse,
3737
Product,
3838
ProtectSecretRequest,
39+
RestoreSecretRequest,
40+
RestoreSecretVersionRequest,
3941
SSHKey,
4042
Secret,
4143
SecretStatus,

packages/clients/src/api/secret/v1beta1/marshalling.gen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const unmarshalSecretVersion = (data: unknown): SecretVersion => {
5151
return {
5252
createdAt: unmarshalDate(data.created_at),
5353
deletedAt: unmarshalDate(data.deleted_at),
54+
deletionRequestedAt: unmarshalDate(data.deletion_requested_at),
5455
description: data.description,
5556
ephemeralProperties: data.ephemeral_properties
5657
? unmarshalEphemeralProperties(data.ephemeral_properties)
@@ -86,6 +87,7 @@ export const unmarshalSecret = (data: unknown): Secret => {
8687

8788
return {
8889
createdAt: unmarshalDate(data.created_at),
90+
deletionRequestedAt: unmarshalDate(data.deletion_requested_at),
8991
description: data.description,
9092
ephemeralPolicy: data.ephemeral_policy
9193
? unmarshalEphemeralPolicy(data.ephemeral_policy)

packages/clients/src/api/secret/v1beta1/types.gen.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type SecretVersionStatus =
3838
| 'enabled'
3939
| 'disabled'
4040
| 'deleted'
41+
| 'scheduled_for_deletion'
4142

4243
export interface EphemeralPolicy {
4344
/**
@@ -95,8 +96,9 @@ export interface SecretVersion {
9596
/**
9697
* - `unknown_status`: the version is in an invalid state. `enabled`: the
9798
* version is accessible. `disabled`: the version is not accessible but can
98-
* be enabled. `deleted`: the version is permanently deleted. It is not
99-
* possible to recover it.
99+
* be enabled. `scheduled_for_deletion`: the version is scheduled for
100+
* deletion. It will be deleted in 7 days. `deleted`: the version is
101+
* permanently deleted. It is not possible to recover it.
100102
*/
101103
status: SecretVersionStatus
102104
/** Date and time of the version's creation. */
@@ -115,6 +117,8 @@ export interface SecretVersion {
115117
* version expires.
116118
*/
117119
ephemeralProperties?: EphemeralProperties
120+
/** Returns the time at which deletion was requested. */
121+
deletionRequestedAt?: Date
118122
}
119123

120124
export interface Secret {
@@ -155,6 +159,8 @@ export interface Secret {
155159
ephemeralPolicy?: EphemeralPolicy
156160
/** List of Scaleway resources that can access and manage the secret. */
157161
usedBy: Product[]
162+
/** Returns the time at which deletion was requested. */
163+
deletionRequestedAt?: Date
158164
/** Region of the secret. */
159165
region: ScwRegion
160166
}
@@ -500,6 +506,11 @@ export type ListSecretsRequest = {
500506
ephemeral?: boolean
501507
/** Filter by secret type (optional). */
502508
type?: SecretType
509+
/**
510+
* Filter by whether the secret was scheduled for deletion / not scheduled for
511+
* deletion (optional).
512+
*/
513+
scheduledForDeletion?: boolean
503514
}
504515

505516
export interface ListSecretsResponse {
@@ -538,6 +549,25 @@ export type ProtectSecretRequest = {
538549
secretId: string
539550
}
540551

552+
export type RestoreSecretRequest = {
553+
/**
554+
* Region to target. If none is passed will use default region from the
555+
* config.
556+
*/
557+
region?: ScwRegion
558+
secretId: string
559+
}
560+
561+
export type RestoreSecretVersionRequest = {
562+
/**
563+
* Region to target. If none is passed will use default region from the
564+
* config.
565+
*/
566+
region?: ScwRegion
567+
secretId: string
568+
revision: string
569+
}
570+
541571
export interface SSHKey {
542572
/** The private SSH key. */
543573
sshPrivateKey: string

0 commit comments

Comments
 (0)