diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.asymmetric_decrypt.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.asymmetric_decrypt.js new file mode 100644 index 00000000000..1e7967553e2 --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.asymmetric_decrypt.js @@ -0,0 +1,75 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name, ciphertext) { + // [START kms_v1_generated_KeyManagementService_AsymmetricDecrypt_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The resource name of the [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] to use for + * decryption. + */ + // const name = 'abc123' + /** + * Required. The data encrypted with the named [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]'s public + * key using OAEP. + */ + // const ciphertext = 'Buffer.from('string')' + /** + * Optional. An optional CRC32C checksum of the [AsymmetricDecryptRequest.ciphertext][google.cloud.kms.v1.AsymmetricDecryptRequest.ciphertext]. + * If specified, [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will verify the integrity of the + * received [AsymmetricDecryptRequest.ciphertext][google.cloud.kms.v1.AsymmetricDecryptRequest.ciphertext] using this checksum. + * [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will report an error if the checksum verification + * fails. If you receive a checksum error, your client should verify that + * CRC32C([AsymmetricDecryptRequest.ciphertext][google.cloud.kms.v1.AsymmetricDecryptRequest.ciphertext]) is equal to + * [AsymmetricDecryptRequest.ciphertext_crc32c][google.cloud.kms.v1.AsymmetricDecryptRequest.ciphertext_crc32c], and if so, perform a + * limited number of retries. A persistent mismatch may indicate an issue in + * your computation of the CRC32C checksum. + * Note: This field is defined as int64 for reasons of compatibility across + * different languages. However, it is a non-negative integer, which will + * never exceed 2^32-1, and can be safely downconverted to uint32 in languages + * that support this type. + */ + // const ciphertextCrc32c = '' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function asymmetricDecrypt() { + // Construct request + const request = { + name, + ciphertext, + }; + + // Run request + const response = await kmsClient.asymmetricDecrypt(request); + console.log(response); + } + + asymmetricDecrypt(); + // [END kms_v1_generated_KeyManagementService_AsymmetricDecrypt_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.asymmetric_sign.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.asymmetric_sign.js new file mode 100644 index 00000000000..30088cdc12a --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.asymmetric_sign.js @@ -0,0 +1,75 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name, digest) { + // [START kms_v1_generated_KeyManagementService_AsymmetricSign_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The resource name of the [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] to use for signing. + */ + // const name = 'abc123' + /** + * Required. The digest of the data to sign. The digest must be produced with + * the same digest algorithm as specified by the key version's + * [algorithm][google.cloud.kms.v1.CryptoKeyVersion.algorithm]. + */ + // const digest = '' + /** + * Optional. An optional CRC32C checksum of the [AsymmetricSignRequest.digest][google.cloud.kms.v1.AsymmetricSignRequest.digest]. If + * specified, [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will verify the integrity of the + * received [AsymmetricSignRequest.digest][google.cloud.kms.v1.AsymmetricSignRequest.digest] using this checksum. + * [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will report an error if the checksum verification + * fails. If you receive a checksum error, your client should verify that + * CRC32C([AsymmetricSignRequest.digest][google.cloud.kms.v1.AsymmetricSignRequest.digest]) is equal to + * [AsymmetricSignRequest.digest_crc32c][google.cloud.kms.v1.AsymmetricSignRequest.digest_crc32c], and if so, perform a limited + * number of retries. A persistent mismatch may indicate an issue in your + * computation of the CRC32C checksum. + * Note: This field is defined as int64 for reasons of compatibility across + * different languages. However, it is a non-negative integer, which will + * never exceed 2^32-1, and can be safely downconverted to uint32 in languages + * that support this type. + */ + // const digestCrc32c = '' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function asymmetricSign() { + // Construct request + const request = { + name, + digest, + }; + + // Run request + const response = await kmsClient.asymmetricSign(request); + console.log(response); + } + + asymmetricSign(); + // [END kms_v1_generated_KeyManagementService_AsymmetricSign_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.create_crypto_key.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.create_crypto_key.js new file mode 100644 index 00000000000..31cf4591c75 --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.create_crypto_key.js @@ -0,0 +1,72 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(parent, cryptoKeyId, cryptoKey) { + // [START kms_v1_generated_KeyManagementService_CreateCryptoKey_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The [name][google.cloud.kms.v1.KeyRing.name] of the KeyRing associated with the + * [CryptoKeys][google.cloud.kms.v1.CryptoKey]. + */ + // const parent = 'abc123' + /** + * Required. It must be unique within a KeyRing and match the regular + * expression `[a-zA-Z0-9_-]{1,63}` + */ + // const cryptoKeyId = 'abc123' + /** + * Required. A [CryptoKey][google.cloud.kms.v1.CryptoKey] with initial field values. + */ + // const cryptoKey = '' + /** + * If set to true, the request will create a [CryptoKey][google.cloud.kms.v1.CryptoKey] without any + * [CryptoKeyVersions][google.cloud.kms.v1.CryptoKeyVersion]. You must manually call + * [CreateCryptoKeyVersion][google.cloud.kms.v1.KeyManagementService.CreateCryptoKeyVersion] or + * [ImportCryptoKeyVersion][google.cloud.kms.v1.KeyManagementService.ImportCryptoKeyVersion] + * before you can use this [CryptoKey][google.cloud.kms.v1.CryptoKey]. + */ + // const skipInitialVersionCreation = true + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function createCryptoKey() { + // Construct request + const request = { + parent, + cryptoKeyId, + cryptoKey, + }; + + // Run request + const response = await kmsClient.createCryptoKey(request); + console.log(response); + } + + createCryptoKey(); + // [END kms_v1_generated_KeyManagementService_CreateCryptoKey_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.create_crypto_key_version.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.create_crypto_key_version.js new file mode 100644 index 00000000000..932459c9e31 --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.create_crypto_key_version.js @@ -0,0 +1,58 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(parent, cryptoKeyVersion) { + // [START kms_v1_generated_KeyManagementService_CreateCryptoKeyVersion_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The [name][google.cloud.kms.v1.CryptoKey.name] of the [CryptoKey][google.cloud.kms.v1.CryptoKey] associated with + * the [CryptoKeyVersions][google.cloud.kms.v1.CryptoKeyVersion]. + */ + // const parent = 'abc123' + /** + * Required. A [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] with initial field values. + */ + // const cryptoKeyVersion = '' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function createCryptoKeyVersion() { + // Construct request + const request = { + parent, + cryptoKeyVersion, + }; + + // Run request + const response = await kmsClient.createCryptoKeyVersion(request); + console.log(response); + } + + createCryptoKeyVersion(); + // [END kms_v1_generated_KeyManagementService_CreateCryptoKeyVersion_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.create_import_job.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.create_import_job.js new file mode 100644 index 00000000000..d9c5ccc04a9 --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.create_import_job.js @@ -0,0 +1,64 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(parent, importJobId, importJob) { + // [START kms_v1_generated_KeyManagementService_CreateImportJob_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The [name][google.cloud.kms.v1.KeyRing.name] of the [KeyRing][google.cloud.kms.v1.KeyRing] associated with the + * [ImportJobs][google.cloud.kms.v1.ImportJob]. + */ + // const parent = 'abc123' + /** + * Required. It must be unique within a KeyRing and match the regular + * expression `[a-zA-Z0-9_-]{1,63}` + */ + // const importJobId = 'abc123' + /** + * Required. An [ImportJob][google.cloud.kms.v1.ImportJob] with initial field values. + */ + // const importJob = '' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function createImportJob() { + // Construct request + const request = { + parent, + importJobId, + importJob, + }; + + // Run request + const response = await kmsClient.createImportJob(request); + console.log(response); + } + + createImportJob(); + // [END kms_v1_generated_KeyManagementService_CreateImportJob_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.create_key_ring.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.create_key_ring.js new file mode 100644 index 00000000000..789db69aad7 --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.create_key_ring.js @@ -0,0 +1,64 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(parent, keyRingId, keyRing) { + // [START kms_v1_generated_KeyManagementService_CreateKeyRing_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The resource name of the location associated with the + * [KeyRings][google.cloud.kms.v1.KeyRing], in the format `projects/* /locations/*`. + */ + // const parent = 'abc123' + /** + * Required. It must be unique within a location and match the regular + * expression `[a-zA-Z0-9_-]{1,63}` + */ + // const keyRingId = 'abc123' + /** + * Required. A [KeyRing][google.cloud.kms.v1.KeyRing] with initial field values. + */ + // const keyRing = '' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function createKeyRing() { + // Construct request + const request = { + parent, + keyRingId, + keyRing, + }; + + // Run request + const response = await kmsClient.createKeyRing(request); + console.log(response); + } + + createKeyRing(); + // [END kms_v1_generated_KeyManagementService_CreateKeyRing_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.decrypt.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.decrypt.js new file mode 100644 index 00000000000..7ae0e409812 --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.decrypt.js @@ -0,0 +1,97 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name, ciphertext) { + // [START kms_v1_generated_KeyManagementService_Decrypt_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The resource name of the [CryptoKey][google.cloud.kms.v1.CryptoKey] to use for decryption. + * The server will choose the appropriate version. + */ + // const name = 'abc123' + /** + * Required. The encrypted data originally returned in + * [EncryptResponse.ciphertext][google.cloud.kms.v1.EncryptResponse.ciphertext]. + */ + // const ciphertext = 'Buffer.from('string')' + /** + * Optional. Optional data that must match the data originally supplied in + * [EncryptRequest.additional_authenticated_data][google.cloud.kms.v1.EncryptRequest.additional_authenticated_data]. + */ + // const additionalAuthenticatedData = 'Buffer.from('string')' + /** + * Optional. An optional CRC32C checksum of the [DecryptRequest.ciphertext][google.cloud.kms.v1.DecryptRequest.ciphertext]. If + * specified, [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will verify the integrity of the + * received [DecryptRequest.ciphertext][google.cloud.kms.v1.DecryptRequest.ciphertext] using this checksum. + * [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will report an error if the checksum verification + * fails. If you receive a checksum error, your client should verify that + * CRC32C([DecryptRequest.ciphertext][google.cloud.kms.v1.DecryptRequest.ciphertext]) is equal to + * [DecryptRequest.ciphertext_crc32c][google.cloud.kms.v1.DecryptRequest.ciphertext_crc32c], and if so, perform a limited number + * of retries. A persistent mismatch may indicate an issue in your computation + * of the CRC32C checksum. + * Note: This field is defined as int64 for reasons of compatibility across + * different languages. However, it is a non-negative integer, which will + * never exceed 2^32-1, and can be safely downconverted to uint32 in languages + * that support this type. + */ + // const ciphertextCrc32c = '' + /** + * Optional. An optional CRC32C checksum of the + * [DecryptRequest.additional_authenticated_data][google.cloud.kms.v1.DecryptRequest.additional_authenticated_data]. If specified, + * [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will verify the integrity of the received + * [DecryptRequest.additional_authenticated_data][google.cloud.kms.v1.DecryptRequest.additional_authenticated_data] using this checksum. + * [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will report an error if the checksum verification + * fails. If you receive a checksum error, your client should verify that + * CRC32C([DecryptRequest.additional_authenticated_data][google.cloud.kms.v1.DecryptRequest.additional_authenticated_data]) is equal to + * [DecryptRequest.additional_authenticated_data_crc32c][google.cloud.kms.v1.DecryptRequest.additional_authenticated_data_crc32c], and if so, perform + * a limited number of retries. A persistent mismatch may indicate an issue in + * your computation of the CRC32C checksum. + * Note: This field is defined as int64 for reasons of compatibility across + * different languages. However, it is a non-negative integer, which will + * never exceed 2^32-1, and can be safely downconverted to uint32 in languages + * that support this type. + */ + // const additionalAuthenticatedDataCrc32c = '' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function decrypt() { + // Construct request + const request = { + name, + ciphertext, + }; + + // Run request + const response = await kmsClient.decrypt(request); + console.log(response); + } + + decrypt(); + // [END kms_v1_generated_KeyManagementService_Decrypt_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.destroy_crypto_key_version.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.destroy_crypto_key_version.js new file mode 100644 index 00000000000..2614ccf50aa --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.destroy_crypto_key_version.js @@ -0,0 +1,52 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name) { + // [START kms_v1_generated_KeyManagementService_DestroyCryptoKeyVersion_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The resource name of the [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] to destroy. + */ + // const name = 'abc123' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function destroyCryptoKeyVersion() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await kmsClient.destroyCryptoKeyVersion(request); + console.log(response); + } + + destroyCryptoKeyVersion(); + // [END kms_v1_generated_KeyManagementService_DestroyCryptoKeyVersion_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.encrypt.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.encrypt.js new file mode 100644 index 00000000000..c03ee3028b3 --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.encrypt.js @@ -0,0 +1,110 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name, plaintext) { + // [START kms_v1_generated_KeyManagementService_Encrypt_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The resource name of the [CryptoKey][google.cloud.kms.v1.CryptoKey] or [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] + * to use for encryption. + * If a [CryptoKey][google.cloud.kms.v1.CryptoKey] is specified, the server will use its + * [primary version][google.cloud.kms.v1.CryptoKey.primary]. + */ + // const name = 'abc123' + /** + * Required. The data to encrypt. Must be no larger than 64KiB. + * The maximum size depends on the key version's + * [protection_level][google.cloud.kms.v1.CryptoKeyVersionTemplate.protection_level]. For + * [SOFTWARE][google.cloud.kms.v1.ProtectionLevel.SOFTWARE] keys, the plaintext must be no larger + * than 64KiB. For [HSM][google.cloud.kms.v1.ProtectionLevel.HSM] keys, the combined length of the + * plaintext and additional_authenticated_data fields must be no larger than + * 8KiB. + */ + // const plaintext = 'Buffer.from('string')' + /** + * Optional. Optional data that, if specified, must also be provided during decryption + * through [DecryptRequest.additional_authenticated_data][google.cloud.kms.v1.DecryptRequest.additional_authenticated_data]. + * The maximum size depends on the key version's + * [protection_level][google.cloud.kms.v1.CryptoKeyVersionTemplate.protection_level]. For + * [SOFTWARE][google.cloud.kms.v1.ProtectionLevel.SOFTWARE] keys, the AAD must be no larger than + * 64KiB. For [HSM][google.cloud.kms.v1.ProtectionLevel.HSM] keys, the combined length of the + * plaintext and additional_authenticated_data fields must be no larger than + * 8KiB. + */ + // const additionalAuthenticatedData = 'Buffer.from('string')' + /** + * Optional. An optional CRC32C checksum of the [EncryptRequest.plaintext][google.cloud.kms.v1.EncryptRequest.plaintext]. If + * specified, [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will verify the integrity of the + * received [EncryptRequest.plaintext][google.cloud.kms.v1.EncryptRequest.plaintext] using this checksum. + * [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will report an error if the checksum verification + * fails. If you receive a checksum error, your client should verify that + * CRC32C([EncryptRequest.plaintext][google.cloud.kms.v1.EncryptRequest.plaintext]) is equal to + * [EncryptRequest.plaintext_crc32c][google.cloud.kms.v1.EncryptRequest.plaintext_crc32c], and if so, perform a limited number of + * retries. A persistent mismatch may indicate an issue in your computation of + * the CRC32C checksum. + * Note: This field is defined as int64 for reasons of compatibility across + * different languages. However, it is a non-negative integer, which will + * never exceed 2^32-1, and can be safely downconverted to uint32 in languages + * that support this type. + */ + // const plaintextCrc32c = '' + /** + * Optional. An optional CRC32C checksum of the + * [EncryptRequest.additional_authenticated_data][google.cloud.kms.v1.EncryptRequest.additional_authenticated_data]. If specified, + * [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will verify the integrity of the received + * [EncryptRequest.additional_authenticated_data][google.cloud.kms.v1.EncryptRequest.additional_authenticated_data] using this checksum. + * [KeyManagementService][google.cloud.kms.v1.KeyManagementService] will report an error if the checksum verification + * fails. If you receive a checksum error, your client should verify that + * CRC32C([EncryptRequest.additional_authenticated_data][google.cloud.kms.v1.EncryptRequest.additional_authenticated_data]) is equal to + * [EncryptRequest.additional_authenticated_data_crc32c][google.cloud.kms.v1.EncryptRequest.additional_authenticated_data_crc32c], and if so, perform + * a limited number of retries. A persistent mismatch may indicate an issue in + * your computation of the CRC32C checksum. + * Note: This field is defined as int64 for reasons of compatibility across + * different languages. However, it is a non-negative integer, which will + * never exceed 2^32-1, and can be safely downconverted to uint32 in languages + * that support this type. + */ + // const additionalAuthenticatedDataCrc32c = '' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function encrypt() { + // Construct request + const request = { + name, + plaintext, + }; + + // Run request + const response = await kmsClient.encrypt(request); + console.log(response); + } + + encrypt(); + // [END kms_v1_generated_KeyManagementService_Encrypt_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.generate_random_bytes.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.generate_random_bytes.js new file mode 100644 index 00000000000..898a9a03814 --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.generate_random_bytes.js @@ -0,0 +1,61 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main() { + // [START kms_v1_generated_KeyManagementService_GenerateRandomBytes_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * The project-specific location in which to generate random bytes. + * For example, "projects/my-project/locations/us-central1". + */ + // const location = 'abc123' + /** + * The length in bytes of the amount of randomness to retrieve. Minimum 8 + * bytes, maximum 1024 bytes. + */ + // const lengthBytes = 1234 + /** + * The [ProtectionLevel][google.cloud.kms.v1.ProtectionLevel] to use when generating the random data. Defaults to + * [SOFTWARE][google.cloud.kms.v1.ProtectionLevel.SOFTWARE]. + */ + // const protectionLevel = '' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function generateRandomBytes() { + // Construct request + const request = {}; + + // Run request + const response = await kmsClient.generateRandomBytes(request); + console.log(response); + } + + generateRandomBytes(); + // [END kms_v1_generated_KeyManagementService_GenerateRandomBytes_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_crypto_key.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_crypto_key.js new file mode 100644 index 00000000000..92664b7c5aa --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_crypto_key.js @@ -0,0 +1,52 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name) { + // [START kms_v1_generated_KeyManagementService_GetCryptoKey_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The [name][google.cloud.kms.v1.CryptoKey.name] of the [CryptoKey][google.cloud.kms.v1.CryptoKey] to get. + */ + // const name = 'abc123' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function getCryptoKey() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await kmsClient.getCryptoKey(request); + console.log(response); + } + + getCryptoKey(); + // [END kms_v1_generated_KeyManagementService_GetCryptoKey_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_crypto_key_version.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_crypto_key_version.js new file mode 100644 index 00000000000..cf25bc470f3 --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_crypto_key_version.js @@ -0,0 +1,52 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name) { + // [START kms_v1_generated_KeyManagementService_GetCryptoKeyVersion_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The [name][google.cloud.kms.v1.CryptoKeyVersion.name] of the [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] to get. + */ + // const name = 'abc123' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function getCryptoKeyVersion() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await kmsClient.getCryptoKeyVersion(request); + console.log(response); + } + + getCryptoKeyVersion(); + // [END kms_v1_generated_KeyManagementService_GetCryptoKeyVersion_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_import_job.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_import_job.js new file mode 100644 index 00000000000..e8826b7e84a --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_import_job.js @@ -0,0 +1,52 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name) { + // [START kms_v1_generated_KeyManagementService_GetImportJob_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The [name][google.cloud.kms.v1.ImportJob.name] of the [ImportJob][google.cloud.kms.v1.ImportJob] to get. + */ + // const name = 'abc123' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function getImportJob() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await kmsClient.getImportJob(request); + console.log(response); + } + + getImportJob(); + // [END kms_v1_generated_KeyManagementService_GetImportJob_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_key_ring.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_key_ring.js new file mode 100644 index 00000000000..4fba8747efe --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_key_ring.js @@ -0,0 +1,52 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name) { + // [START kms_v1_generated_KeyManagementService_GetKeyRing_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The [name][google.cloud.kms.v1.KeyRing.name] of the [KeyRing][google.cloud.kms.v1.KeyRing] to get. + */ + // const name = 'abc123' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function getKeyRing() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await kmsClient.getKeyRing(request); + console.log(response); + } + + getKeyRing(); + // [END kms_v1_generated_KeyManagementService_GetKeyRing_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_public_key.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_public_key.js new file mode 100644 index 00000000000..0bbaaf48e07 --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.get_public_key.js @@ -0,0 +1,53 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name) { + // [START kms_v1_generated_KeyManagementService_GetPublicKey_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The [name][google.cloud.kms.v1.CryptoKeyVersion.name] of the [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] public key to + * get. + */ + // const name = 'abc123' + + // Imports the Kms library + const {KeyManagementServiceClient} = require('@google-cloud/kms').v1; + + // Instantiates a client + const kmsClient = new KeyManagementServiceClient(); + + async function getPublicKey() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await kmsClient.getPublicKey(request); + console.log(response); + } + + getPublicKey(); + // [END kms_v1_generated_KeyManagementService_GetPublicKey_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-kms/samples/generated/v1/key_management_service.import_crypto_key_version.js b/packages/google-cloud-kms/samples/generated/v1/key_management_service.import_crypto_key_version.js new file mode 100644 index 00000000000..33ec027ccf4 --- /dev/null +++ b/packages/google-cloud-kms/samples/generated/v1/key_management_service.import_crypto_key_version.js @@ -0,0 +1,108 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(parent, algorithm, importJob) { + // [START kms_v1_generated_KeyManagementService_ImportCryptoKeyVersion_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The [name][google.cloud.kms.v1.CryptoKey.name] of the [CryptoKey][google.cloud.kms.v1.CryptoKey] to be imported into. + * The create permission is only required on this key when creating a new + * [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]. + */ + // const parent = 'abc123' + /** + * Optional. The optional [name][google.cloud.kms.v1.CryptoKeyVersion.name] of an existing + * [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] to target for an import operation. + * If this field is not present, a new [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] containing the + * supplied key material is created. + * If this field is present, the supplied key material is imported into + * the existing [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion]. To import into an existing + * [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion], the [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] must be a child of + * [ImportCryptoKeyVersionRequest.parent][google.cloud.kms.v1.ImportCryptoKeyVersionRequest.parent], have been previously created via + * [ImportCryptoKeyVersion][], and be in + * [DESTROYED][google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.DESTROYED] or + * [IMPORT_FAILED][google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionState.IMPORT_FAILED] + * state. The key material and algorithm must match the previous + * [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] exactly if the [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] has ever contained + * key material. + */ + // const cryptoKeyVersion = 'abc123' + /** + * Required. The [algorithm][google.cloud.kms.v1.CryptoKeyVersion.CryptoKeyVersionAlgorithm] of + * the key being imported. This does not need to match the + * [version_template][google.cloud.kms.v1.CryptoKey.version_template] of the [CryptoKey][google.cloud.kms.v1.CryptoKey] this + * version imports into. + */ + // const algorithm = '' + /** + * Required. The [name][google.cloud.kms.v1.ImportJob.name] of the [ImportJob][google.cloud.kms.v1.ImportJob] that was used to + * wrap this key material. + */ + // const importJob = 'abc123' + /** + * Wrapped key material produced with + * [RSA_OAEP_3072_SHA1_AES_256][google.cloud.kms.v1.ImportJob.ImportMethod.RSA_OAEP_3072_SHA1_AES_256] + * or + * [RSA_OAEP_4096_SHA1_AES_256][google.cloud.kms.v1.ImportJob.ImportMethod.RSA_OAEP_4096_SHA1_AES_256]. + * This field contains the concatenation of two wrapped keys: + *