MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

kms/createKeyLabels.js:17–63  ·  view source on GitHub ↗
(
  projectId = 'my-project',
  locationId = 'us-east1',
  keyRingId = 'my-key-ring',
  id = 'my-labeled-key'
)

Source from the content-addressed store, hash-verified

15'use strict';
16
17async function main(
18 projectId = 'my-project',
19 locationId = 'us-east1',
20 keyRingId = 'my-key-ring',
21 id = 'my-labeled-key'
22) {
23 // [START kms_create_key_labels]
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-labeled-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 createKeyLabels() {
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 },
50 labels: {
51 team: 'alpha',
52 cost_center: 'cc1234',
53 },
54 },
55 });
56
57 console.log(`Created labeled key: ${key.name}`);
58 return key;
59 }
60
61 return createKeyLabels();
62 // [END kms_create_key_labels]
63}
64module.exports.main = main;
65
66/* c8 ignore next 10 */

Callers 1

createKeyLabels.jsFile · 0.70

Calls 1

createKeyLabelsFunction · 0.85

Tested by

no test coverage detected