| 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] |