Skip to content

Commit

Permalink
Update dlp v2beta1 client
Browse files Browse the repository at this point in the history
  • Loading branch information
evaogbe committed Aug 11, 2017
1 parent ae33610 commit b0231a1
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 32 deletions.
33 changes: 33 additions & 0 deletions packages/dlp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,39 @@ In order to use this library, you first need to go through the following steps:
$ npm install --save @google-cloud/dlp
```

### Preview
#### DlpServiceClient
```js
var dlp = require('@google-cloud/dlp');

var client = dlp({
// optional auth parameters.
});

var minLikelihood = dlp.v2beta1.types.Likelihood.POSSIBLE;
var inspectConfig = {
minLikelihood : minLikelihood
};
var type = 'text/plain';
var value = 'my phone number is 215-512-1212';
var itemsElement = {
type : type,
value : value
};
var items = [itemsElement];
var request = {
inspectConfig: inspectConfig,
items: items
};
client.inspectContent(request).then(function(responses) {
var response = responses[0];
// doThingsWith(response)
})
.catch(function(err) {
console.error(err);
});
```

### Next Steps
- Read the [Client Library Documentation][] for DLP API to see other available methods on the client.
- Read the [DLP API Product documentation][Product Documentation] to learn more about the product and see How-to Guides.
Expand Down
13 changes: 7 additions & 6 deletions packages/dlp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"files": [
"src",
"AUTHORS",
"CONTRIBUTING",
"COPYING"
],
"keywords": [
Expand All @@ -25,16 +24,18 @@
"DLP API"
],
"dependencies": {
"google-proto-files": "^0.12.0",
"extend": "^3.0",
"google-gax": "^0.13.2",
"extend": "^3.0.0"
"google-proto-files": "^0.12.0"
},
"devDependencies": {
"mocha": "^3.2.0"
"mocha": "^3.2.0",
"through2": "^2.0.3"
},
"scripts": {
"test": "mocha",
"publish-module": "node ../../scripts/publish.js dlp"
"publish-module": "node ../../scripts/publish.js dlp",
"smoke-test": "mocha smoke-test/*.js --timeout 5000",
"test": "mocha test/*.js"
},
"license": "Apache-2.0",
"engines": {
Expand Down
49 changes: 49 additions & 0 deletions packages/dlp/smoke-test/dlp_service_smoke_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2017, 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';

describe('DlpServiceSmokeTest', function() {

it('successfully makes a call to the service', function(done) {
var dlp = require('../src');

var client = dlp.v2beta1({
// optional auth parameters.
});

var minLikelihood = dlp.v2beta1.types.Likelihood.POSSIBLE;
var inspectConfig = {
minLikelihood : minLikelihood
};
var type = 'text/plain';
var value = 'my phone number is 215-512-1212';
var itemsElement = {
type : type,
value : value
};
var items = [itemsElement];
var request = {
inspectConfig: inspectConfig,
items: items
};
client.inspectContent(request).then(function(responses) {
var response = responses[0];
console.log(response);
})
.then(done)
.catch(done);
});
});
45 changes: 37 additions & 8 deletions packages/dlp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,41 @@ var extend = require('extend');
var gapic = {
v2beta1: require('./v2beta1')
};
var gaxGrpc = require('google-gax').grpc();

const VERSION = require('../package.json').version;

/**
* The [Data Loss Prevention (DLP) API](https://cloud.google.com/dlp) allows
* clients to detect the presence of Personally Identifiable Information (PII)
* and other privacy-sensitive data in user-supplied, unstructured data streams,
* like text blocks or images.
* Create a dlpServiceClient with additional helpers for common
* tasks.
*
* The service also includes methods for sensitive data redaction and scheduling
* of data scans on Google Cloud Platform based data sets.
* The DLP API is a service that allows clients
* to detect the presence of Personally Identifiable Information (PII) and other
* privacy-sensitive data in user-supplied, unstructured data streams, like text
* blocks or images.
* The service also includes methods for sensitive data redaction and
* scheduling of data scans on Google Cloud Platform based data sets.
*
* @param {object=} options - [Configuration object](#/docs).
* @param {object=} options.credentials - Credentials object.
* @param {string=} options.credentials.client_email
* @param {string=} options.credentials.private_key
* @param {string=} options.email - Account email address. Required when using a
* .pem or .p12 keyFilename.
* @param {string=} options.keyFilename - Full path to the a .json, .pem, or
* .p12 key downloaded from the Google Developers Console. If you provide
* a path to a JSON file, the projectId option above is not necessary.
* NOTE: .pem and .p12 require you to specify options.email as well.
* @param {number=} options.port - The port on which to connect to
* the remote host.
* @param {string=} options.projectId - The project ID from the Google
* Developer's Console, e.g. 'grape-spaceship-123'. We will also check
* the environment variable GCLOUD_PROJECT for your project ID. If your
* app is running in an environment which supports
* {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
* your project ID will be detected automatically.
* @param {function=} options.promise - Custom promise module to use instead
* of native Promises.
* @param {string=} options.servicePath - The domain name of the
* API remote host.
*/
Expand All @@ -50,10 +70,19 @@ function dlpV2beta1(options) {
libVersion: VERSION
});

// Create the image annotator client with the provided options.
// Create the client with the provided options.
var client = gapic.v2beta1(options).dlpServiceClient(options);
return client;
}

var v2beta1Protos = {};

extend(v2beta1Protos, gaxGrpc.load([{
root: require('google-proto-files')('..'),
file: 'google/privacy/dlp/v2beta1/dlp.proto'
}]).google.privacy.dlp.v2beta1);

module.exports = dlpV2beta1;
module.exports.v2beta1 = dlpV2beta1;
module.exports.types = v2beta1Protos;
module.exports.v2beta1 = dlpV2beta1;
module.exports.v2beta1.types = v2beta1Protos;
10 changes: 6 additions & 4 deletions packages/dlp/src/v2beta1/dlp_service_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var SERVICE_ADDRESS = 'dlp.googleapis.com';

var DEFAULT_SERVICE_PORT = 443;

var CODE_GEN_NAME_VERSION = 'gapic/0.0.0';
var CODE_GEN_NAME_VERSION = 'gapic/0.0.5';

/**
* The scopes needed to make gRPC calls to all of the methods defined in
Expand Down Expand Up @@ -312,11 +312,13 @@ DlpServiceClient.prototype.redactContent = function(request, options, callback)
* identifier for the Operation, and the `count` is a counter used for
* tracking the number of files written. <p>The CSV file(s) contain the
* following columns regardless of storage type scanned: <li>id <li>info_type
* <li>likelihood <li>byte size of finding <li>quote <li>time_stamp<br/>
* <li>likelihood <li>byte size of finding <li>quote <li>timestamp<br/>
* <p>For Cloud Storage the next columns are: <li>file_path
* <li>start_offset<br/>
* <p>For Cloud Datastore the next columns are: <li>project_id
* <li>namespace_id <li>path <li>column_name <li>offset
* <li>namespace_id <li>path <li>column_name <li>offset<br/>
* <p>For BigQuery the next columns are: <li>row_number <li>project_id
* <li>dataset_id <li>table_id
*
* This object should have the same structure as [OutputStorageConfig]{@link OutputStorageConfig}
* @param {Object=} options
Expand Down Expand Up @@ -423,7 +425,7 @@ DlpServiceClient.prototype.createInspectOperation = function(request, options, c
* @param {string} request.name
* Identifier of the results set returned as metadata of
* the longrunning operation created by a call to CreateInspectOperation.
* Should be in the format of `inspect/results/{id}.
* Should be in the format of `inspect/results/{id}`.
* @param {number=} request.pageSize
* Maximum number of results to return.
* If 0, the implementation selects a reasonable value.
Expand Down
2 changes: 1 addition & 1 deletion packages/dlp/src/v2beta1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function v2beta1(options) {
return dlpServiceClient(gaxGrpc);
}

v2beta1.GAPIC_VERSION = '0.0.0';
v2beta1.GAPIC_VERSION = '0.0.5';
v2beta1.SERVICE_ADDRESS = dlpServiceClient.SERVICE_ADDRESS;
v2beta1.ALL_SCOPES = dlpServiceClient.ALL_SCOPES;

Expand Down
39 changes: 26 additions & 13 deletions packages/dlp/test/gapic-v2beta1.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
'use strict';

var assert = require('assert');
var dlpV2beta1 = require('../src/v2beta1')();
var dlp = require('../src');

var FAKE_STATUS_CODE = 1;
var error = new Error();
error.code = FAKE_STATUS_CODE;

describe('DlpServiceClient', function() {
describe('inspectContent', function() {
it('invokes inspectContent without error', function(done) {
var client = dlpV2beta1.dlpServiceClient();
var client = dlp.v2beta1();

// Mock request
var inspectConfig = {};
var items = [];
Expand All @@ -47,7 +49,8 @@ describe('DlpServiceClient', function() {
});

it('invokes inspectContent with error', function(done) {
var client = dlpV2beta1.dlpServiceClient();
var client = dlp.v2beta1();

// Mock request
var inspectConfig = {};
var items = [];
Expand All @@ -69,7 +72,8 @@ describe('DlpServiceClient', function() {

describe('redactContent', function() {
it('invokes redactContent without error', function(done) {
var client = dlpV2beta1.dlpServiceClient();
var client = dlp.v2beta1();

// Mock request
var inspectConfig = {};
var items = [];
Expand All @@ -94,7 +98,8 @@ describe('DlpServiceClient', function() {
});

it('invokes redactContent with error', function(done) {
var client = dlpV2beta1.dlpServiceClient();
var client = dlp.v2beta1();

// Mock request
var inspectConfig = {};
var items = [];
Expand All @@ -118,7 +123,8 @@ describe('DlpServiceClient', function() {

describe('createInspectOperation', function() {
it('invokes createInspectOperation without error', function(done) {
var client = dlpV2beta1.dlpServiceClient();
var client = dlp.v2beta1();

// Mock request
var inspectConfig = {};
var storageConfig = {};
Expand Down Expand Up @@ -150,7 +156,8 @@ describe('DlpServiceClient', function() {
});

it('invokes createInspectOperation with error', function(done) {
var client = dlpV2beta1.dlpServiceClient();
var client = dlp.v2beta1();

// Mock request
var inspectConfig = {};
var storageConfig = {};
Expand Down Expand Up @@ -179,7 +186,8 @@ describe('DlpServiceClient', function() {

describe('listInspectFindings', function() {
it('invokes listInspectFindings without error', function(done) {
var client = dlpV2beta1.dlpServiceClient();
var client = dlp.v2beta1();

// Mock request
var formattedName = client.resultPath("[RESULT]");
var request = {
Expand All @@ -203,7 +211,8 @@ describe('DlpServiceClient', function() {
});

it('invokes listInspectFindings with error', function(done) {
var client = dlpV2beta1.dlpServiceClient();
var client = dlp.v2beta1();

// Mock request
var formattedName = client.resultPath("[RESULT]");
var request = {
Expand All @@ -223,7 +232,8 @@ describe('DlpServiceClient', function() {

describe('listInfoTypes', function() {
it('invokes listInfoTypes without error', function(done) {
var client = dlpV2beta1.dlpServiceClient();
var client = dlp.v2beta1();

// Mock request
var category = 'category50511102';
var languageCode = 'languageCode-412800396';
Expand All @@ -246,7 +256,8 @@ describe('DlpServiceClient', function() {
});

it('invokes listInfoTypes with error', function(done) {
var client = dlpV2beta1.dlpServiceClient();
var client = dlp.v2beta1();

// Mock request
var category = 'category50511102';
var languageCode = 'languageCode-412800396';
Expand All @@ -268,7 +279,8 @@ describe('DlpServiceClient', function() {

describe('listRootCategories', function() {
it('invokes listRootCategories without error', function(done) {
var client = dlpV2beta1.dlpServiceClient();
var client = dlp.v2beta1();

// Mock request
var languageCode = 'languageCode-412800396';
var request = {
Expand All @@ -289,7 +301,8 @@ describe('DlpServiceClient', function() {
});

it('invokes listRootCategories with error', function(done) {
var client = dlpV2beta1.dlpServiceClient();
var client = dlp.v2beta1();

// Mock request
var languageCode = 'languageCode-412800396';
var request = {
Expand Down

0 comments on commit b0231a1

Please sign in to comment.