Skip to content

Commit

Permalink
docs(samples): add auto-generated Node samples (#501)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 398604509

Source-Link: googleapis/googleapis@6ef16b9

Source-Link: googleapis/googleapis-gen@8314e1e
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODMxNGUxZWFkM2U5MDZkYmYyMDEyY2VkOGQ5MmYyYmM4ZGQ0NWM5NSJ9
  • Loading branch information
gcf-owl-bot[bot] authored Sep 24, 2021
1 parent 88a883e commit bdecd11
Show file tree
Hide file tree
Showing 28 changed files with 1,839 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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));
Original file line number Diff line number Diff line change
@@ -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));
Original file line number Diff line number Diff line change
@@ -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));
Original file line number Diff line number Diff line change
@@ -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));
Original file line number Diff line number Diff line change
@@ -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));
Loading

0 comments on commit bdecd11

Please sign in to comment.