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

Function main

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

Callers 1

Calls 2

transformCLIFunction · 0.70
inspectStringFunction · 0.70

Tested by

no test coverage detected