( projectId = 'my-project', locationId = 'us-east1', keyRingId = 'my-key-ring', keyId = 'my-key', versionId = '123' )
| 15 | 'use strict'; |
| 16 | |
| 17 | async 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_update_key_set_primary] |
| 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 name |
| 41 | const keyName = client.cryptoKeyPath(projectId, locationId, keyRingId, keyId); |
| 42 | |
| 43 | async function updateKeySetPrimary() { |
| 44 | const [key] = await client.updateCryptoKeyPrimaryVersion({ |
| 45 | name: keyName, |
| 46 | cryptoKeyVersionId: versionId, |
| 47 | }); |
| 48 | |
| 49 | console.log(`Set primary to ${versionId}`); |
| 50 | return key; |
| 51 | } |
| 52 | |
| 53 | return updateKeySetPrimary(); |
| 54 | // [END kms_update_key_set_primary] |
| 55 | } |
| 56 | module.exports.main = main; |
| 57 | |
| 58 | /* c8 ignore next 10 */ |
no test coverage detected