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

Function main

dlp/inspectStringCustomOmitOverlap.js:20–104  ·  view source on GitHub ↗
(projectId, string)

Source from the content-addressed store, hash-verified

18// title: Inspect a string for sensitive data, omitting custom matches.
19// usage: node inspectStringCustomOmitOverlap.js my-project string
20function main(projectId, string) {
21 // [START dlp_inspect_string_custom_omit_overlap]
22 // Imports the Google Cloud Data Loss Prevention library
23 const DLP = require('@google-cloud/dlp');
24
25 // Instantiates a client
26 const dlp = new DLP.DlpServiceClient();
27
28 // The project ID to run the API call under
29 // const projectId = 'my-project';
30
31 // The string to inspect
32 // const string = 'Name: Jane Doe. Name: Larry Page.';
33
34 async function inspectStringCustomOmitOverlap() {
35 // Construct item to inspect
36 const item = {value: string};
37
38 // Construct a custom regex detector for names
39 const customInfoTypes = [
40 {
41 infoType: {name: 'VIP_DETECTOR'},
42 regex: {pattern: 'Larry Page|Sergey Brin'},
43 exclusionType:
44 DLP.protos.google.privacy.dlp.v2.CustomInfoType.ExclusionType
45 .EXCLUSION_TYPE_EXCLUDE,
46 },
47 ];
48
49 // Construct a exclusion rule
50 const exclusionRule = {
51 excludeInfoTypes: {
52 infoTypes: [{name: 'VIP_DETECTOR'}],
53 },
54 matchingType:
55 DLP.protos.google.privacy.dlp.v2.MatchingType.MATCHING_TYPE_FULL_MATCH,
56 };
57
58 // Construct a rule set that will only match if the match text does not
59 // contains Info type matches.
60 const ruleSet = [
61 {
62 infoTypes: [{name: 'PERSON_NAME'}],
63 rules: [
64 {
65 exclusionRule: exclusionRule,
66 },
67 ],
68 },
69 ];
70
71 // Construct the inspect configuration
72 const inspectConfig = {
73 infoTypes: [{name: 'PERSON_NAME'}],
74 customInfoTypes: customInfoTypes,
75 ruleSet: ruleSet,
76 includeQuote: true,
77 };

Calls 1

Tested by

no test coverage detected