( projectId = 'my-project', locationId = 'us-east1', keyRingId = 'my-key-ring', keyId = 'my-key' )
| 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 | ) { |
| 23 | // [START kms_update_key_add_rotation_schedule] |
| 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 | // const versionId = '123'; |
| 32 | |
| 33 | // Imports the Cloud KMS library |
| 34 | const {KeyManagementServiceClient} = require('@google-cloud/kms'); |
| 35 | |
| 36 | // Instantiates a client |
| 37 | const client = new KeyManagementServiceClient(); |
| 38 | |
| 39 | // Build the key name |
| 40 | const keyName = client.cryptoKeyPath(projectId, locationId, keyRingId, keyId); |
| 41 | |
| 42 | async function updateKeyAddRotation() { |
| 43 | const [key] = await client.updateCryptoKey({ |
| 44 | cryptoKey: { |
| 45 | name: keyName, |
| 46 | |
| 47 | // Rotate the key every 30 days. |
| 48 | rotationPeriod: { |
| 49 | seconds: 60 * 60 * 24 * 30, |
| 50 | }, |
| 51 | |
| 52 | // Start the first rotation in 24 hours. |
| 53 | nextRotationTime: { |
| 54 | seconds: new Date().getTime() / 1000 + 60 * 60 * 24, |
| 55 | }, |
| 56 | }, |
| 57 | updateMask: { |
| 58 | paths: ['rotation_period', 'next_rotation_time'], |
| 59 | }, |
| 60 | }); |
| 61 | |
| 62 | console.log(`Updated rotation for: ${key.name}`); |
| 63 | return key; |
| 64 | } |
| 65 | |
| 66 | return updateKeyAddRotation(); |
| 67 | // [END kms_update_key_add_rotation_schedule] |
| 68 | } |
| 69 | module.exports.main = main; |
| 70 | |
| 71 | /* c8 ignore next 10 */ |
no test coverage detected