Skip to content

Commit 5bee9e2

Browse files
authored
feat: add secret protection (#748)
1 parent 7ee2e85 commit 5bee9e2

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ import type {
4444
ListSecretsResponse,
4545
ListTagsRequest,
4646
ListTagsResponse,
47+
ProtectSecretRequest,
4748
Secret,
4849
SecretVersion,
50+
UnprotectSecretRequest,
4951
UpdateSecretRequest,
5052
UpdateSecretVersionRequest,
5153
} from './types.gen'
@@ -203,6 +205,52 @@ export class API extends ParentAPI {
203205
)}/secrets/${validatePathParam('secretId', request.secretId)}`,
204206
})
205207

208+
/**
209+
* Protect a secret. Protect a given secret specified by the `secret_id`
210+
* parameter. A protected secret can be read and modified but cannot be
211+
* deleted.
212+
*
213+
* @param request - The request {@link ProtectSecretRequest}
214+
* @returns A Promise of Secret
215+
*/
216+
protectSecret = (request: Readonly<ProtectSecretRequest>) =>
217+
this.client.fetch<Secret>(
218+
{
219+
body: '{}',
220+
headers: jsonContentHeaders,
221+
method: 'POST',
222+
path: `/secret-manager/v1alpha1/regions/${validatePathParam(
223+
'region',
224+
request.region ?? this.client.settings.defaultRegion,
225+
)}/secrets/${validatePathParam('secretId', request.secretId)}/protect`,
226+
},
227+
unmarshalSecret,
228+
)
229+
230+
/**
231+
* Unprotect a secret. Unprotect a given secret specified by the `secret_id`
232+
* parameter. An unprotected secret can be read, modified and deleted.
233+
*
234+
* @param request - The request {@link UnprotectSecretRequest}
235+
* @returns A Promise of Secret
236+
*/
237+
unprotectSecret = (request: Readonly<UnprotectSecretRequest>) =>
238+
this.client.fetch<Secret>(
239+
{
240+
body: '{}',
241+
headers: jsonContentHeaders,
242+
method: 'POST',
243+
path: `/secret-manager/v1alpha1/regions/${validatePathParam(
244+
'region',
245+
request.region ?? this.client.settings.defaultRegion,
246+
)}/secrets/${validatePathParam(
247+
'secretId',
248+
request.secretId,
249+
)}/unprotect`,
250+
},
251+
unmarshalSecret,
252+
)
253+
206254
/**
207255
* Allow a product to use the secret.
208256
*

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ export type {
2727
ListTagsResponse,
2828
PasswordGenerationParams,
2929
Product,
30+
ProtectSecretRequest,
3031
Secret,
3132
SecretStatus,
3233
SecretType,
3334
SecretVersion,
3435
SecretVersionStatus,
36+
UnprotectSecretRequest,
3537
UpdateSecretRequest,
3638
UpdateSecretVersionRequest,
3739
} from './types.gen'

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const unmarshalSecret = (data: unknown) => {
3535
description: data.description,
3636
id: data.id,
3737
isManaged: data.is_managed,
38+
isProtected: data.is_protected,
3839
name: data.name,
3940
projectId: data.project_id,
4041
region: data.region,

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ export interface Secret {
9090
/** Name of the secret. */
9191
name: string
9292
/**
93-
* Current status of the secret. `ready`: the secret is ready. `locked`: the
94-
* secret is locked.
93+
* Current status of the secret. `ready`: the secret can be read, modified and
94+
* deleted. `locked`: no action can be performed on the secret. This status
95+
* can only be applied and removed by Scaleway.
9596
*/
9697
status: SecretStatus
9798
/** Date and time of the secret's creation. */
@@ -106,6 +107,8 @@ export interface Secret {
106107
description?: string
107108
/** Returns `true` for secrets that are managed by another product. */
108109
isManaged: boolean
110+
/** Returns `true` for protected secrets that cannot be deleted. */
111+
isProtected: boolean
109112
/** Type of the secret. See `Secret.Type` enum for description of values. */
110113
type: SecretType
111114
/** Region of the secret. */
@@ -231,6 +234,26 @@ export type DeleteSecretRequest = {
231234
secretId: string
232235
}
233236

237+
export type ProtectSecretRequest = {
238+
/**
239+
* Region to target. If none is passed will use default region from the
240+
* config.
241+
*/
242+
region?: Region
243+
/** ID of the secret to protect. */
244+
secretId: string
245+
}
246+
247+
export type UnprotectSecretRequest = {
248+
/**
249+
* Region to target. If none is passed will use default region from the
250+
* config.
251+
*/
252+
region?: Region
253+
/** ID of the secret to unprotect. */
254+
secretId: string
255+
}
256+
234257
export type AddSecretOwnerRequest = {
235258
/**
236259
* Region to target. If none is passed will use default region from the

0 commit comments

Comments
 (0)