diff --git a/.kokoro/datacatalog/cloud-client/lookup-entry.cfg b/.kokoro/datacatalog/cloud-client/lookup-entry.cfg new file mode 100644 index 0000000000..e7dae3099d --- /dev/null +++ b/.kokoro/datacatalog/cloud-client/lookup-entry.cfg @@ -0,0 +1,25 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Set the folder in which the tests are run +env_vars: { + key: "PROJECT" + value: "datacatalog/cloud-client" +} + +# Tell the trampoline which build file to use. +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/nodejs-docs-samples/.kokoro/build.sh" +} + +# Specify the project that contains a valid dataset. +env_vars: { + key: "GCLOUD_PROJECT" + value: "bigquery-public-data" +} + +# Specify the dataset related to the project. +env_vars: { + key: "GCLOUD_DATASET_ID" + value: "new_york_taxi_trips" +} \ No newline at end of file diff --git a/datacatalog/cloud-client/README.md b/datacatalog/cloud-client/README.md new file mode 100644 index 0000000000..66f2f614d1 --- /dev/null +++ b/datacatalog/cloud-client/README.md @@ -0,0 +1,19 @@ +Google Cloud Platform logo + +# Google Cloud Data Catalog API Node.js Samples + +This directory contains samples for Google Cloud Data Catalog. Google Cloud Data Catalog is a fully managed and scalable metadata management service that empowers organizations to quickly discover, manage, and understand all their data in Google Cloud. + +# Setup + +Run the following command to install the library dependencies for Node.js: + + npm install + +# Running the sample + + Commands: + lookupEntry.js Lookup a dataset entry. + + +For more information, see https://cloud.google.com/data-catalog/docs/ \ No newline at end of file diff --git a/datacatalog/cloud-client/lookupEntry.js b/datacatalog/cloud-client/lookupEntry.js new file mode 100644 index 0000000000..52c59f2820 --- /dev/null +++ b/datacatalog/cloud-client/lookupEntry.js @@ -0,0 +1,53 @@ +/** + * Copyright 2019 Google Inc. All Rights Reserved. + * 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'; + +/** + * This application demonstrates how to perform lookup operations with the + * Cloud Data Catalog API. + + * For more information, see the README.md under /datacatalog and the + * documentation at https://cloud.google.com/data-catalog/docs. + */ +function main( + projectId = process.env.GCLOUD_PROJECT, + datasetId = process.env.GCLOUD_DATASET_ID +) { + // [START datacatalog_lookup_dataset] + // ------------------------------- + // Import required modules. + // ------------------------------- + const {DataCatalogClient} = require('@google-cloud/datacatalog').v1beta1; + const datacatalog = new DataCatalogClient(); + + async function lookup() { + // TODO(developer): Uncomment the following lines before running the sample. + // const projectId = 'my-project' + // const datasetId = 'my_dataset' + const resourceName = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}`; + const request = {linkedResource: resourceName}; + const [result] = await datacatalog.lookupEntry(request); + return result; + } + + lookup().then(response => { + console.log(response); + }); + // [END datacatalog_lookup_dataset] +} + +// node lookupEntry.js +main(...process.argv.slice(2)); diff --git a/datacatalog/cloud-client/package.json b/datacatalog/cloud-client/package.json new file mode 100644 index 0000000000..51e526f6e9 --- /dev/null +++ b/datacatalog/cloud-client/package.json @@ -0,0 +1,34 @@ +{ + "name": "@google-cloud/datacatalog-samples", + "version": "0.0.1", + "private": true, + "description": "Samples for the Cloud Data Catalog client library for Node.js", + "license": "Apache-2.0", + "author": "Google LLC", + "repository": "GoogleCloudPlatform/nodejs-docs-samples", + "engines": { + "node": ">=8.0.0" + }, + "scripts": { + "test": "mocha system-test/*.test.js --timeout=60000" + }, + "devDependencies": { + "@google-cloud/nodejs-repo-tools": "^3.3.0", + "mocha": "^6.0.0" + }, + "dependencies": { + "@google-cloud/datacatalog": "^1.0.1" + }, + "cloud-repo-tools": { + "requiresKeyFile": true, + "requiresProjectId": true, + "test": { + "build": { + "requiredEnvVars": [ + "GCLOUD_PROJECT", + "GCLOUD_DATASET_ID" + ] + } + } + } +} diff --git a/datacatalog/cloud-client/system-test/datacatalog.test.js b/datacatalog/cloud-client/system-test/datacatalog.test.js new file mode 100644 index 0000000000..621c61d9f5 --- /dev/null +++ b/datacatalog/cloud-client/system-test/datacatalog.test.js @@ -0,0 +1,35 @@ +/** + * Copyright 2019 Google Inc. All Rights Reserved. + * 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'; + +const path = require('path'); +const assert = require('assert'); +const tools = require('@google-cloud/nodejs-repo-tools'); + +const cwd = path.join(__dirname, '..'); +const projectId = process.env.GCLOUD_PROJECT; +const datasetId = process.env.GCLOUD_DATASET_ID; + +before(tools.checkCredentials); + +it('should lookup a dataset entry', async () => { + const output = await tools.runAsync( + `node lookupEntry.js ${projectId} ${datasetId}`, + cwd + ); + const expectedLinkedResource = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}`; + assert.ok(output.includes(expectedLinkedResource)); +});