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

Function main

kms/checkStateImportedKey.js:17–62  ·  view source on GitHub ↗
(
  projectId = 'my-project',
  locationId = 'us-east1',
  keyRingId = 'my-key-ring',
  cryptoKeyId = 'my-imported-key',
  cryptoKeyVersionId = '1'
)

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 cryptoKeyId = 'my-imported-key',
22 cryptoKeyVersionId = '1'
23) {
24 // [START kms_check_state_imported_key]
25 //
26 // TODO(developer): Uncomment these variables before running the sample.
27 //
28 // const projectId = 'my-project';
29 // const locationId = 'us-east1';
30 // const keyRingId = 'my-key-ring';
31 // const cryptoKeyId = 'my-imported-key';
32 // const cryptoKeyVersionId = '1';
33
34 // Imports the Cloud KMS library
35 const {KeyManagementServiceClient} = require('@google-cloud/kms');
36
37 // Instantiates a client
38 const client = new KeyManagementServiceClient();
39
40 // Build the key version name
41 const keyVersionName = client.cryptoKeyVersionPath(
42 projectId,
43 locationId,
44 keyRingId,
45 cryptoKeyId,
46 cryptoKeyVersionId
47 );
48
49 async function checkStateCryptoKeyVersion() {
50 const [keyVersion] = await client.getCryptoKeyVersion({
51 name: keyVersionName,
52 });
53
54 console.log(
55 `Current state of key version ${keyVersion.name}: ${keyVersion.state}`
56 );
57 return keyVersion;
58 }
59
60 return checkStateCryptoKeyVersion();
61 // [END kms_check_state_imported_key]
62}
63module.exports.main = main;
64
65/* c8 ignore next 10 */

Callers 1

Calls 1

Tested by

no test coverage detected