Skip to content

Commit 6c9197b

Browse files
authored
feat(secret): add ephemeral policy (#1072)
1 parent 6096c85 commit 6c9197b

File tree

4 files changed

+122
-21
lines changed

4 files changed

+122
-21
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ export class API extends ParentAPI {
167167
)
168168

169169
/**
170-
* Update metadata of a secret. Edit a secret's metadata such as name, tag(s)
171-
* and description. The secret to update is specified by the `secret_id` and
172-
* `region` parameters.
170+
* Update metadata of a secret. Edit a secret's metadata such as name, tag(s),
171+
* description and ephemeral policy. The secret to update is specified by the
172+
* `secret_id` and `region` parameters.
173173
*
174174
* @param request - The request {@link UpdateSecretRequest}
175175
* @returns A Promise of Secret

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export type {
1414
DestroySecretVersionRequest,
1515
DisableSecretVersionRequest,
1616
EnableSecretVersionRequest,
17+
EphemeralPolicy,
18+
EphemeralPolicyAction,
19+
EphemeralProperties,
1720
Folder,
1821
GeneratePasswordRequest,
1922
GetSecretByNameRequest,
@@ -35,7 +38,6 @@ export type {
3538
Product,
3639
ProtectSecretRequest,
3740
Secret,
38-
SecretEphemeralAction,
3941
SecretStatus,
4042
SecretType,
4143
SecretVersion,

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

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import type {
1212
CreateFolderRequest,
1313
CreateSecretRequest,
1414
CreateSecretVersionRequest,
15+
EphemeralPolicy,
16+
EphemeralProperties,
1517
Folder,
1618
GeneratePasswordRequest,
1719
ListFoldersResponse,
@@ -42,6 +44,20 @@ export const unmarshalFolder = (data: unknown): Folder => {
4244
} as Folder
4345
}
4446

47+
const unmarshalEphemeralProperties = (data: unknown): EphemeralProperties => {
48+
if (!isJSONObject(data)) {
49+
throw new TypeError(
50+
`Unmarshalling the type 'EphemeralProperties' failed as data isn't a dictionary.`,
51+
)
52+
}
53+
54+
return {
55+
action: data.action,
56+
expiresAt: unmarshalDate(data.expires_at),
57+
expiresOnceAccessed: data.expires_once_accessed,
58+
} as EphemeralProperties
59+
}
60+
4561
export const unmarshalSecretVersion = (data: unknown): SecretVersion => {
4662
if (!isJSONObject(data)) {
4763
throw new TypeError(
@@ -52,6 +68,9 @@ export const unmarshalSecretVersion = (data: unknown): SecretVersion => {
5268
return {
5369
createdAt: unmarshalDate(data.created_at),
5470
description: data.description,
71+
ephemeralProperties: data.ephemeral_properties
72+
? unmarshalEphemeralProperties(data.ephemeral_properties)
73+
: undefined,
5574
isLatest: data.is_latest,
5675
revision: data.revision,
5776
secretId: data.secret_id,
@@ -60,6 +79,20 @@ export const unmarshalSecretVersion = (data: unknown): SecretVersion => {
6079
} as SecretVersion
6180
}
6281

82+
export const unmarshalEphemeralPolicy = (data: unknown): EphemeralPolicy => {
83+
if (!isJSONObject(data)) {
84+
throw new TypeError(
85+
`Unmarshalling the type 'EphemeralPolicy' failed as data isn't a dictionary.`,
86+
)
87+
}
88+
89+
return {
90+
action: data.action,
91+
expiresOnceAccessed: data.expires_once_accessed,
92+
timeToLive: data.time_to_live,
93+
} as EphemeralPolicy
94+
}
95+
6396
export const unmarshalSecret = (data: unknown): Secret => {
6497
if (!isJSONObject(data)) {
6598
throw new TypeError(
@@ -70,8 +103,9 @@ export const unmarshalSecret = (data: unknown): Secret => {
70103
return {
71104
createdAt: unmarshalDate(data.created_at),
72105
description: data.description,
73-
ephemeralAction: data.ephemeral_action,
74-
expiresAt: unmarshalDate(data.expires_at),
106+
ephemeralPolicy: data.ephemeral_policy
107+
? unmarshalEphemeralPolicy(data.ephemeral_policy)
108+
: undefined,
75109
id: data.id,
76110
isManaged: data.is_managed,
77111
isProtected: data.is_protected,
@@ -179,13 +213,24 @@ export const marshalCreateFolderRequest = (
179213
project_id: request.projectId ?? defaults.defaultProjectId,
180214
})
181215

216+
export const marshalEphemeralPolicy = (
217+
request: EphemeralPolicy,
218+
defaults: DefaultValues,
219+
): Record<string, unknown> => ({
220+
action: request.action,
221+
expires_once_accessed: request.expiresOnceAccessed,
222+
time_to_live: request.timeToLive,
223+
})
224+
182225
export const marshalCreateSecretRequest = (
183226
request: CreateSecretRequest,
184227
defaults: DefaultValues,
185228
): Record<string, unknown> => ({
186229
description: request.description,
187-
ephemeral_action: request.ephemeralAction,
188-
expires_at: request.expiresAt,
230+
ephemeral_policy:
231+
request.ephemeralPolicy !== undefined
232+
? marshalEphemeralPolicy(request.ephemeralPolicy, defaults)
233+
: undefined,
189234
name: request.name,
190235
path: request.path,
191236
project_id: request.projectId ?? defaults.defaultProjectId,
@@ -236,14 +281,31 @@ export const marshalUpdateSecretRequest = (
236281
defaults: DefaultValues,
237282
): Record<string, unknown> => ({
238283
description: request.description,
284+
ephemeral_policy:
285+
request.ephemeralPolicy !== undefined
286+
? marshalEphemeralPolicy(request.ephemeralPolicy, defaults)
287+
: undefined,
239288
name: request.name,
240289
path: request.path,
241290
tags: request.tags,
242291
})
243292

293+
const marshalEphemeralProperties = (
294+
request: EphemeralProperties,
295+
defaults: DefaultValues,
296+
): Record<string, unknown> => ({
297+
action: request.action,
298+
expires_at: request.expiresAt,
299+
expires_once_accessed: request.expiresOnceAccessed,
300+
})
301+
244302
export const marshalUpdateSecretVersionRequest = (
245303
request: UpdateSecretVersionRequest,
246304
defaults: DefaultValues,
247305
): Record<string, unknown> => ({
248306
description: request.description,
307+
ephemeral_properties:
308+
request.ephemeralProperties !== undefined
309+
? marshalEphemeralProperties(request.ephemeralProperties, defaults)
310+
: undefined,
249311
})

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

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// If you have any remark or suggestion do not hesitate to open an issue.
33
import type { Region } from '../../../bridge'
44

5+
export type EphemeralPolicyAction = 'unknown_action' | 'delete' | 'disable'
6+
57
export type ListFoldersRequestOrderBy =
68
| 'created_at_asc'
79
| 'created_at_desc'
@@ -18,11 +20,6 @@ export type ListSecretsRequestOrderBy =
1820

1921
export type Product = 'unknown' | 'edge_services'
2022

21-
export type SecretEphemeralAction =
22-
| 'unknown_ephemeral_action'
23-
| 'delete_secret'
24-
| 'disable_secret'
25-
2623
export type SecretStatus = 'ready' | 'locked'
2724

2825
export type SecretType =
@@ -37,6 +34,30 @@ export type SecretVersionStatus =
3734
| 'disabled'
3835
| 'destroyed'
3936

37+
export interface EphemeralProperties {
38+
/** (Optional.) If not specified, the version does not have an expiration date. */
39+
expiresAt?: Date
40+
/**
41+
* (Optional.) If not specified, the version can be accessed an unlimited
42+
* amount of times.
43+
*/
44+
expiresOnceAccessed?: boolean
45+
/** See `EphemeralPolicy.Action` enum for a description of values. */
46+
action: EphemeralPolicyAction
47+
}
48+
49+
export interface EphemeralPolicy {
50+
/**
51+
* Time frame, from one second and up to one year, during which the secret's
52+
* versions are valid.
53+
*/
54+
timeToLive?: string
55+
/** Returns `true` if the version expires after a single user access. */
56+
expiresOnceAccessed?: boolean
57+
/** See the `EphemeralPolicy.Action` enum for a description of values. */
58+
action: EphemeralPolicyAction
59+
}
60+
4061
export interface PasswordGenerationParams {
4162
/** Length of the password to generate (between 1 and 1024). */
4263
length: number
@@ -88,6 +109,12 @@ export interface SecretVersion {
88109
description?: string
89110
/** Returns `true` if the version is the latest. */
90111
isLatest: boolean
112+
/**
113+
* Returns the version's expiration date, whether it expires after being
114+
* accessed once, and the action to perform (disable or delete) once the
115+
* version expires.
116+
*/
117+
ephemeralProperties?: EphemeralProperties
91118
}
92119

93120
export interface Secret {
@@ -121,10 +148,11 @@ export interface Secret {
121148
type: SecretType
122149
/** Location of the secret in the directory structure. */
123150
path: string
124-
/** (Optional.) Date on which the secret will be deleted or deactivated. */
125-
expiresAt?: Date
126-
/** See `Secret.EphemeralAction` enum for description of values. */
127-
ephemeralAction: SecretEphemeralAction
151+
/**
152+
* (Optional.) Policy that defines whether/when a secret's versions expire. By
153+
* default, the policy is applied to all the secret's versions.
154+
*/
155+
ephemeralPolicy?: EphemeralPolicy
128156
/** Region of the secret. */
129157
region: Region
130158
}
@@ -244,10 +272,11 @@ export type CreateSecretRequest = {
244272
* specified, the path is `/`.
245273
*/
246274
path?: string
247-
/** (Optional.) Date on which the secret will be deleted or deactivated. */
248-
expiresAt?: Date
249-
/** Action to be taken when the secret expires. */
250-
ephemeralAction?: SecretEphemeralAction
275+
/**
276+
* (Optional.) Policy that defines whether/when a secret's versions expire. By
277+
* default, the policy is applied to all the secret's versions.
278+
*/
279+
ephemeralPolicy?: EphemeralPolicy
251280
}
252281

253282
export type CreateSecretVersionRequest = {
@@ -619,6 +648,8 @@ export type UpdateSecretRequest = {
619648
* specified, the path is `/`.
620649
*/
621650
path?: string
651+
/** (Optional.) Policy that defines whether/when a secret's versions expire. */
652+
ephemeralPolicy?: EphemeralPolicy
622653
}
623654

624655
export type UpdateSecretVersionRequest = {
@@ -640,4 +671,10 @@ export type UpdateSecretVersionRequest = {
640671
revision: string
641672
/** Description of the version. */
642673
description?: string
674+
/**
675+
* (Optional.) Properties that defines the version's expiration date, whether
676+
* it expires after being accessed once, and the action to perform (disable or
677+
* delete) once the version expires.
678+
*/
679+
ephemeralProperties?: EphemeralProperties
643680
}

0 commit comments

Comments
 (0)