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

Function main

kms/disableKeyVersion.js:17–66  ·  view source on GitHub ↗
(
  projectId = 'my-project',
  locationId = 'us-east1',
  keyRingId = 'my-key-ring',
  keyId = 'my-key',
  versionId = '123'
)

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 versionId = '123'
23) {
24 // [START kms_disable_key_version]
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 keyId = 'my-key';
32 // const versionId = '123';
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 versionName = client.cryptoKeyVersionPath(
42 projectId,
43 locationId,
44 keyRingId,
45 keyId,
46 versionId
47 );
48
49 async function disableKeyVersion() {
50 const [version] = await client.updateCryptoKeyVersion({
51 cryptoKeyVersion: {
52 name: versionName,
53 state: 'DISABLED',
54 },
55 updateMask: {
56 paths: ['state'],
57 },
58 });
59
60 console.log(`Disabled key version: ${version.name}`);
61 return version;
62 }
63
64 return disableKeyVersion();
65 // [END kms_disable_key_version]
66}
67module.exports.main = main;
68
69/* c8 ignore next 10 */

Callers 1

Calls 1

disableKeyVersionFunction · 0.85

Tested by

no test coverage detected