( 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_get_key_version_attestation] |
| 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 getKeyVersionAttestation() { |
| 50 | const [version] = await client.getCryptoKeyVersion({ |
| 51 | name: versionName, |
| 52 | }); |
| 53 | |
| 54 | // Only HSM keys have an attestation. For other key types, the attestion |
| 55 | // will be nil. |
| 56 | const attestation = version.attestation; |
| 57 | if (!attestation) { |
| 58 | throw new Error('no attestation'); |
| 59 | } |
| 60 | |
| 61 | console.log(`Attestation: ${attestation.toString('base64')}`); |
| 62 | return attestation.content; |
| 63 | } |
| 64 | |
| 65 | return getKeyVersionAttestation(); |
| 66 | // [END kms_get_key_version_attestation] |
| 67 | } |
| 68 | module.exports.main = main; |
| 69 | |
| 70 | /* c8 ignore next 10 */ |
no test coverage detected