Skip to content

Commit abe764a

Browse files
authored
feat(key_manager): make key_id argument positional in ImportKeyMaterial and DeleteKeyMaterial (#1409)
1 parent 06ba7ce commit abe764a

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
marshalDecryptRequest,
1313
marshalEncryptRequest,
1414
marshalGenerateDataKeyRequest,
15+
marshalImportKeyMaterialRequest,
1516
marshalUpdateKeyRequest,
1617
unmarshalDataKey,
1718
unmarshalDecryptResponse,
@@ -24,13 +25,15 @@ import type {
2425
DataKey,
2526
DecryptRequest,
2627
DecryptResponse,
28+
DeleteKeyMaterialRequest,
2729
DeleteKeyRequest,
2830
DisableKeyRequest,
2931
EnableKeyRequest,
3032
EncryptRequest,
3133
EncryptResponse,
3234
GenerateDataKeyRequest,
3335
GetKeyRequest,
36+
ImportKeyMaterialRequest,
3437
Key,
3538
ListKeysRequest,
3639
ListKeysResponse,
@@ -324,4 +327,39 @@ export class API extends ParentAPI {
324327
},
325328
unmarshalDecryptResponse,
326329
)
330+
331+
/**
332+
* Import key material. Import key material to use to derive a new
333+
* cryptographic key. The key's origin must be `external`.
334+
*
335+
* @param request - The request {@link ImportKeyMaterialRequest}
336+
* @returns A Promise of Key
337+
*/
338+
importKeyMaterial = (request: Readonly<ImportKeyMaterialRequest>) =>
339+
this.client.fetch<Key>(
340+
{
341+
body: JSON.stringify(
342+
marshalImportKeyMaterialRequest(request, this.client.settings),
343+
),
344+
headers: jsonContentHeaders,
345+
method: 'POST',
346+
path: `/key-manager/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam('keyId', request.keyId)}/import-key-material`,
347+
},
348+
unmarshalKey,
349+
)
350+
351+
/**
352+
* Delete key material. Delete previously imported key material. This renders
353+
* the associated cryptographic key unusable for any operation. The key's
354+
* origin must be `external`.
355+
*
356+
* @param request - The request {@link DeleteKeyMaterialRequest}
357+
*/
358+
deleteKeyMaterial = (request: Readonly<DeleteKeyMaterialRequest>) =>
359+
this.client.fetch<void>({
360+
body: '{}',
361+
headers: jsonContentHeaders,
362+
method: 'POST',
363+
path: `/key-manager/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/keys/${validatePathParam('keyId', request.keyId)}/delete-key-material`,
364+
})
327365
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ export type {
77
DataKeyAlgorithmSymmetricEncryption,
88
DecryptRequest,
99
DecryptResponse,
10+
DeleteKeyMaterialRequest,
1011
DeleteKeyRequest,
1112
DisableKeyRequest,
1213
EnableKeyRequest,
1314
EncryptRequest,
1415
EncryptResponse,
1516
GenerateDataKeyRequest,
1617
GetKeyRequest,
18+
ImportKeyMaterialRequest,
1719
Key,
1820
KeyAlgorithmSymmetricEncryption,
21+
KeyOrigin,
1922
KeyRotationPolicy,
2023
KeyState,
2124
KeyUsage,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
EncryptRequest,
1616
EncryptResponse,
1717
GenerateDataKeyRequest,
18+
ImportKeyMaterialRequest,
1819
Key,
1920
KeyRotationPolicy,
2021
KeyUsage,
@@ -62,6 +63,7 @@ export const unmarshalKey = (data: unknown): Key => {
6263
id: data.id,
6364
locked: data.locked,
6465
name: data.name,
66+
origin: data.origin,
6567
projectId: data.project_id,
6668
protected: data.protected,
6769
region: data.region,
@@ -156,6 +158,7 @@ export const marshalCreateKeyRequest = (
156158
): Record<string, unknown> => ({
157159
description: request.description,
158160
name: request.name,
161+
origin: request.origin,
159162
project_id: request.projectId ?? defaults.defaultProjectId,
160163
rotation_policy:
161164
request.rotationPolicy !== undefined
@@ -193,6 +196,14 @@ export const marshalGenerateDataKeyRequest = (
193196
without_plaintext: request.withoutPlaintext,
194197
})
195198

199+
export const marshalImportKeyMaterialRequest = (
200+
request: ImportKeyMaterialRequest,
201+
defaults: DefaultValues,
202+
): Record<string, unknown> => ({
203+
key_material: request.keyMaterial,
204+
salt: request.salt,
205+
})
206+
196207
export const marshalUpdateKeyRequest = (
197208
request: UpdateKeyRequest,
198209
defaults: DefaultValues,

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export type KeyAlgorithmSymmetricEncryption =
1010
| 'unknown_symmetric_encryption'
1111
| 'aes_256_gcm'
1212

13+
export type KeyOrigin = 'unknown_origin' | 'scaleway_kms' | 'external'
14+
1315
export type KeyState =
1416
| 'unknown_state'
1517
| 'enabled'
@@ -77,6 +79,8 @@ export interface Key {
7779
rotatedAt?: Date
7880
/** Key rotation policy. */
7981
rotationPolicy?: KeyRotationPolicy
82+
/** Refer to the `Key.Origin` enum for a description of values. */
83+
origin: KeyOrigin
8084
/** Region of the key. */
8185
region: Region
8286
}
@@ -104,6 +108,8 @@ export type CreateKeyRequest = {
104108
rotationPolicy?: KeyRotationPolicy
105109
/** Default value is `false`. */
106110
unprotected: boolean
111+
/** Refer to the `Key.Origin` enum for a description of values. */
112+
origin?: KeyOrigin
107113
}
108114

109115
export interface DataKey {
@@ -152,6 +158,16 @@ export interface DecryptResponse {
152158
ciphertext?: string
153159
}
154160

161+
export type DeleteKeyMaterialRequest = {
162+
/**
163+
* Region to target. If none is passed will use default region from the
164+
* config.
165+
*/
166+
region?: Region
167+
/** ID of the key of which to delete the key material. */
168+
keyId: string
169+
}
170+
155171
export type DeleteKeyRequest = {
156172
/**
157173
* Region to target. If none is passed will use default region from the
@@ -237,6 +253,26 @@ export type GetKeyRequest = {
237253
keyId: string
238254
}
239255

256+
export type ImportKeyMaterialRequest = {
257+
/**
258+
* Region to target. If none is passed will use default region from the
259+
* config.
260+
*/
261+
region?: Region
262+
/** The key's origin must be 'external'. */
263+
keyId: string
264+
/**
265+
* The key material The key material is a random sequence of bytes used to
266+
* derive a cryptographic key.
267+
*/
268+
keyMaterial: string
269+
/**
270+
* A salt can be used to improve the quality of randomness when the key
271+
* material is generated from a low entropy source.
272+
*/
273+
salt?: string
274+
}
275+
240276
export type ListKeysRequest = {
241277
/**
242278
* Region to target. If none is passed will use default region from the

0 commit comments

Comments
 (0)