MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

dlp/quickstart.js:22–85  ·  view source on GitHub ↗
(projectId)

Source from the content-addressed store, hash-verified

20// usage: node quickstart.js my-project
21
22function main(projectId) {
23 // Imports the Google Cloud Data Loss Prevention library
24 const DLP = require('@google-cloud/dlp');
25
26 // [START dlp_quickstart]
27
28 // Instantiates a client
29 const dlp = new DLP.DlpServiceClient();
30
31 // The string to inspect
32 const string = 'Robert Frost';
33
34 // The project ID to run the API call under
35 // const projectId = 'my-project';
36
37 async function quickStart() {
38 // The minimum likelihood required before returning a match
39 const minLikelihood = 'LIKELIHOOD_UNSPECIFIED';
40
41 // The maximum number of findings to report (0 = server maximum)
42 const maxFindings = 0;
43
44 // The infoTypes of information to match
45 const infoTypes = [{name: 'PERSON_NAME'}, {name: 'US_STATE'}];
46
47 // Whether to include the matching string
48 const includeQuote = true;
49
50 // Construct item to inspect
51 const item = {value: string};
52
53 // Construct request
54 const request = {
55 parent: `projects/${projectId}/locations/global`,
56 inspectConfig: {
57 infoTypes: infoTypes,
58 minLikelihood: minLikelihood,
59 limits: {
60 maxFindingsPerRequest: maxFindings,
61 },
62 includeQuote: includeQuote,
63 },
64 item: item,
65 };
66
67 // Run request
68 const [response] = await dlp.inspectContent(request);
69 const findings = response.result.findings;
70 if (findings.length > 0) {
71 console.log('Findings:');
72 findings.forEach(finding => {
73 if (includeQuote) {
74 console.log(`\tQuote: ${finding.quote}`);
75 }
76 console.log(`\tInfo type: ${finding.infoType.name}`);
77 console.log(`\tLikelihood: ${finding.likelihood}`);
78 });
79 } else {

Callers 1

quickstart.jsFile · 0.70

Calls 1

quickStartFunction · 0.70

Tested by

no test coverage detected