Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .kokoro/datacatalog.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ env_vars: {
env_vars: {
key: "TRAMPOLINE_BUILD_FILE"
value: "github/nodejs-docs-samples/.kokoro/build.sh"
}
}

# Set organization used by datacatalog samples.
env_vars: {
key: "GCP_ORG"
value: "?"
}

5 changes: 4 additions & 1 deletion datacatalog/cloud-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ Run the following command to install the library dependencies for Node.js:
# Running the sample

Commands:
createEntryGroup.js <projectId> <entryGroupId> Create a entry group.
createFilesetEntry.js <projectId> <entryGroupId> <entryId> Create a fileset entry.
lookupEntry.js <projectId> <datasetId> Lookup a dataset entry.

searchCatalogProject.js <projectId> <query> Search Catalog with project scope.
searchCatalogOrg.js <organizationId> <query> Search Catalog with organization scope.

For more information, see https://cloud.google.com/data-catalog/docs/
3 changes: 2 additions & 1 deletion datacatalog/cloud-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"uuid": "^8.0.0"
},
"dependencies": {
"@google-cloud/datacatalog": "^2.0.0"
"@google-cloud/datacatalog": "^2.0.0",
"@google-cloud/bigquery": "^4.0.0"
}
}
52 changes: 52 additions & 0 deletions datacatalog/cloud-client/searchCatalogOrg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2020 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.

// [START datacatalog_search_org]
// This application demonstrates how to perform search operations with the
// Cloud Data Catalog API.

const main = async (
organizationId = process.env.GCP_ORG,
query
) => {

// -------------------------------
// Import required modules.
// -------------------------------
const { DataCatalogClient } = require('@google-cloud/datacatalog').v1;
const datacatalog = new DataCatalogClient();

// Create request.
const scope = {
includeOrgIds: [organizationId],
// Alternatively, search using project scopes.
// includeProjectIds: ['my-project'],
};

const request = {
scope: scope,
query: query,
};

const [response] = await datacatalog.searchCatalog(request);
console.log(response);
return response;
}

// node searchCatalogOrg.js <organizationId> <query>
// sample values:
// organizationId = 111111000000;
// query = 'type=dataset'
main(...process.argv.slice(2));
// [END datacatalog_search_org]
52 changes: 52 additions & 0 deletions datacatalog/cloud-client/searchCatalogProject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2020 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.

// [START datacatalog_search_project]
// This application demonstrates how to perform search operations with the
// Cloud Data Catalog API.

const main = async (
projectId = process.env.GCLOUD_PROJECT,
query
) => {

// -------------------------------
// Import required modules.
// -------------------------------
const { DataCatalogClient } = require('@google-cloud/datacatalog').v1;
const datacatalog = new DataCatalogClient();

// Create request.
const scope = {
includeProjectIds: [projectId],
// Alternatively, search using org scopes.
// includeOrgIds: [organizationId]
};

const request = {
scope: scope,
query: query,
};

const [response] = await datacatalog.searchCatalog(request);
console.log(response);
return response;
}

// node searchCatalogProject.js <projectId> <query>
// sample values:
// projectId = 'my-project';
// query = 'type=dataset'
main(...process.argv.slice(2));
// [END datacatalog_search_project]
66 changes: 66 additions & 0 deletions datacatalog/cloud-client/system-test/searchCatalogOrg.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2020 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';

const path = require('path');
const assert = require('assert');
const cwd = path.join(__dirname, '..');
const {exec} = require('child_process');
const uuid = require('uuid');
const generateUuid = () => `datacatalog-tests-${uuid.v4()}`.replace(/-/gi, '_');
const datasetId = generateUuid();
const {BigQuery} = require('@google-cloud/bigquery');

const bigquery = new BigQuery();

before(async () => {
assert(
process.env.GCP_ORG,
`Must set GCP_ORG environment variable!`
);
assert(
process.env.GCLOUD_PROJECT,
`Must set GCLOUD_PROJECT environment variable!`
);
assert(
process.env.GOOGLE_APPLICATION_CREDENTIALS,
`Must set GOOGLE_APPLICATION_CREDENTIALS environment variable!`
);

await bigquery.createDataset(datasetId);
});
after(async () => {
await bigquery
.dataset(datasetId)
.delete({force: true})
.catch(console.warn);
});

describe('searchCatalog org', () => {
it('should return a dataset entry', (done) => {
const organizationId = process.env.GCP_ORG;
const projectId = process.env.GCLOUD_PROJECT;
const query = 'type=dataset';
const expectedLinkedResource = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}`;
exec(
`node searchCatalogOrg.js ${organizationId} ${query}`,
{cwd},
(err, stdout) => {
assert.ok(stdout.includes(expectedLinkedResource));
done();
}
);
});
});
61 changes: 61 additions & 0 deletions datacatalog/cloud-client/system-test/searchCatalogProject.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2020 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';

const path = require('path');
const assert = require('assert');
const cwd = path.join(__dirname, '..');
const {exec} = require('child_process');
const uuid = require('uuid');
const generateUuid = () => `datacatalog-tests-${uuid.v4()}`.replace(/-/gi, '_');
const datasetId = generateUuid();
const {BigQuery} = require('@google-cloud/bigquery');

const bigquery = new BigQuery();

before(async () => {
assert(
process.env.GCLOUD_PROJECT,
`Must set GCLOUD_PROJECT environment variable!`
);
assert(
process.env.GOOGLE_APPLICATION_CREDENTIALS,
`Must set GOOGLE_APPLICATION_CREDENTIALS environment variable!`
);

await bigquery.createDataset(datasetId);
});
after(async () => {
await bigquery
.dataset(datasetId)
.delete({force: true})
.catch(console.warn);
});

describe('searchCatalog project', () => {
it('should return a dataset entry', (done) => {
const projectId = process.env.GCLOUD_PROJECT;
const query = 'type=dataset';
const expectedLinkedResource = `//bigquery.googleapis.com/projects/${projectId}/datasets/${datasetId}`;
exec(
`node searchCatalogProject.js ${projectId} ${query}`,
{cwd},
(err, stdout) => {
assert.ok(stdout.includes(expectedLinkedResource));
done();
}
);
});
});