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

Function main

kms/getKeyLabels.js:17–55  ·  view source on GitHub ↗
(
  projectId = 'my-project',
  locationId = 'us-east1',
  keyRingId = 'my-key-ring',
  keyId = 'my-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 keyId = 'my-key'
22) {
23 // [START kms_get_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 keyId = 'my-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 key name
39 const keyName = client.cryptoKeyPath(projectId, locationId, keyRingId, keyId);
40
41 async function getKeyLabels() {
42 const [key] = await client.getCryptoKey({
43 name: keyName,
44 });
45
46 for (const k in key.labels) {
47 console.log(`${k}: ${key.labels[k]}`);
48 }
49
50 return key;
51 }
52
53 return getKeyLabels();
54 // [END kms_get_key_labels]
55}
56module.exports.main = main;
57
58/* c8 ignore next 10 */

Callers 1

getKeyLabels.jsFile · 0.70

Calls 1

getKeyLabelsFunction · 0.85

Tested by

no test coverage detected