( projectId = 'my-project', locationId = 'us-east1', keyRingId = 'my-key-ring', id = 'my-imported-key' )
| 15 | 'use strict'; |
| 16 | |
| 17 | async function main( |
| 18 | projectId = 'my-project', |
| 19 | locationId = 'us-east1', |
| 20 | keyRingId = 'my-key-ring', |
| 21 | id = 'my-imported-key' |
| 22 | ) { |
| 23 | // [START kms_create_key_for_import] |
| 24 | // |
| 25 | // TODO(developer): Uncomment these variables before running the sample. |
| 26 | // |
| 27 | // const projectId = 'my-project'; |
| 28 | // const locationId = 'us-east1'; |
| 29 | // const keyRingId = 'my-key-ring'; |
| 30 | // const id = 'my-imported-key'; |
| 31 | |
| 32 | // Imports the Cloud KMS library |
| 33 | const {KeyManagementServiceClient} = require('@google-cloud/kms'); |
| 34 | |
| 35 | // Instantiates a client |
| 36 | const client = new KeyManagementServiceClient(); |
| 37 | |
| 38 | // Build the parent key ring name |
| 39 | const keyRingName = client.keyRingPath(projectId, locationId, keyRingId); |
| 40 | |
| 41 | async function createKeyForImport() { |
| 42 | const [key] = await client.createCryptoKey({ |
| 43 | parent: keyRingName, |
| 44 | cryptoKeyId: id, |
| 45 | cryptoKey: { |
| 46 | purpose: 'ENCRYPT_DECRYPT', |
| 47 | versionTemplate: { |
| 48 | algorithm: 'GOOGLE_SYMMETRIC_ENCRYPTION', |
| 49 | protectionLevel: 'HSM', |
| 50 | }, |
| 51 | // Optional: ensure that only imported versions may be added to this |
| 52 | // key. |
| 53 | importOnly: true, |
| 54 | }, |
| 55 | // Do not allow KMS to generate an initial version of this key. |
| 56 | skipInitialVersionCreation: true, |
| 57 | }); |
| 58 | |
| 59 | console.log(`Created key for import: ${key.name}`); |
| 60 | return key; |
| 61 | } |
| 62 | |
| 63 | return createKeyForImport(); |
| 64 | // [END kms_create_key_for_import] |
| 65 | } |
| 66 | module.exports.main = main; |
| 67 | |
| 68 | /* c8 ignore next 10 */ |
no test coverage detected