Skip to content

Commit

Permalink
Add DLP quickstart + fix incorrect comments (#442)
Browse files Browse the repository at this point in the history
* Fix typo in comments

* Add DLP quickstart

* Address comments
  • Loading branch information
Ace Nassri authored Aug 4, 2017
1 parent b984fae commit 8ab8083
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions packages/google-privacy-dlp/samples/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Copyright 2017, Google, Inc.
* 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';

// [START quickstart]
// Imports the Google Cloud Data Loss Prevention library
const DLP = require('@google-cloud/dlp');

// Instantiates a client
const dlp = DLP();

// The string to inspect
const string = 'Robert Frost';

// The minimum likelihood required before returning a match
const minLikelihood = 'LIKELIHOOD_UNSPECIFIED';

// The maximum number of findings to report (0 = server maximum)
const maxFindings = 0;

// The infoTypes of information to match
const infoTypes = [
{ name: 'US_MALE_NAME' },
{ name: 'US_FEMALE_NAME' }
];

// Whether to include the matching string
const includeQuote = true;

// Construct items to inspect
const items = [{ type: 'text/plain', value: string }];

// Construct request
const request = {
inspectConfig: {
infoTypes: infoTypes,
minLikelihood: minLikelihood,
maxFindings: maxFindings,
includeQuote: includeQuote
},
items: items
};

// Run request
dlp.inspectContent(request)
.then((response) => {
const findings = response[0].results[0].findings;
if (findings.length > 0) {
console.log(`Findings:`);
findings.forEach((finding) => {
if (includeQuote) {
console.log(`\tQuote: ${finding.quote}`);
}
console.log(`\tInfo type: ${finding.infoType.name}`);
console.log(`\tLikelihood: ${finding.likelihood}`);
});
} else {
console.log(`No findings.`);
}
})
.catch((err) => {
console.error(`Error in inspectString: ${err.message || err}`);
});
// [END quickstart]

0 comments on commit 8ab8083

Please sign in to comment.