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

Function main

dlp/inspectString.js:22–99  ·  view source on GitHub ↗
(
  projectId,
  string,
  minLikelihood,
  maxFindings,
  infoTypes,
  customInfoTypes,
  includeQuote
)

Source from the content-addressed store, hash-verified

20// usage: node inspectString.js my-project string minLikelihood maxFindings infoTypes customInfoTypes includeQuote
21
22function main(
23 projectId,
24 string,
25 minLikelihood,
26 maxFindings,
27 infoTypes,
28 customInfoTypes,
29 includeQuote
30) {
31 [infoTypes, customInfoTypes] = transformCLI(infoTypes, customInfoTypes);
32
33 // [START dlp_inspect_string]
34 // Imports the Google Cloud Data Loss Prevention library
35 const DLP = require('@google-cloud/dlp');
36
37 // Instantiates a client
38 const dlp = new DLP.DlpServiceClient();
39
40 // The project ID to run the API call under
41 // const projectId = 'my-project';
42
43 // The string to inspect
44 // const string = 'My name is Gary and my email is gary@example.com';
45
46 // The minimum likelihood required before returning a match
47 // const minLikelihood = 'LIKELIHOOD_UNSPECIFIED';
48
49 // The maximum number of findings to report per request (0 = server maximum)
50 // const maxFindings = 0;
51
52 // The infoTypes of information to match
53 // const infoTypes = [{ name: 'PHONE_NUMBER' }, { name: 'EMAIL_ADDRESS' }, { name: 'CREDIT_CARD_NUMBER' }];
54
55 // The customInfoTypes of information to match
56 // const customInfoTypes = [{ infoType: { name: 'DICT_TYPE' }, dictionary: { wordList: { words: ['foo', 'bar', 'baz']}}},
57 // { infoType: { name: 'REGEX_TYPE' }, regex: {pattern: '\\(\\d{3}\\) \\d{3}-\\d{4}'}}];
58
59 // Whether to include the matching string
60 // const includeQuote = true;
61
62 async function inspectString() {
63 // Construct item to inspect
64 const item = {value: string};
65
66 // Construct request
67 const request = {
68 parent: `projects/${projectId}/locations/global`,
69 inspectConfig: {
70 infoTypes: infoTypes,
71 customInfoTypes: customInfoTypes,
72 minLikelihood: minLikelihood,
73 includeQuote: includeQuote,
74 limits: {
75 maxFindingsPerRequest: maxFindings,
76 },
77 },
78 item: item,
79 };

Callers 1

inspectString.jsFile · 0.70

Calls 2

transformCLIFunction · 0.70
inspectStringFunction · 0.70

Tested by

no test coverage detected