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

Function main

dlp/inspectStringMultipleRules.js:21–120  ·  view source on GitHub ↗
(projectId, string)

Source from the content-addressed store, hash-verified

19// description: Inspect a string for sensitive data by using multiple rules.
20// usage: node inspectStringMultipleRules.js my-project string
21function main(projectId, string) {
22 // [START dlp_inspect_string_multiple_rules]
23 // Imports the Google Cloud Data Loss Prevention library
24 const DLP = require('@google-cloud/dlp');
25
26 // Instantiates a client
27 const dlp = new DLP.DlpServiceClient();
28
29 // The project ID to run the API call under
30 // const projectId = 'my-project';
31
32 // The string to inspect
33 // const string = 'patient: Jane Doe';
34
35 async function inspectStringMultipleRules() {
36 // Construct item to inspect
37 const item = {value: string};
38
39 // Construct hotword rules
40 const patientRule = {
41 hotwordRegex: {pattern: 'patient'},
42 proximity: {windowBefore: 10},
43 likelihoodAdjustment: {
44 fixedLikelihood:
45 DLP.protos.google.privacy.dlp.v2.Likelihood.VERY_LIKELY,
46 },
47 };
48
49 const doctorRule = {
50 hotwordRegex: {pattern: 'doctor'},
51 proximity: {windowBefore: 10},
52 likelihoodAdjustment: {
53 fixedLikelihood: DLP.protos.google.privacy.dlp.v2.Likelihood.UNLIKELY,
54 },
55 };
56
57 // Construct exclusion rules
58 const quasimodoRule = {
59 dictionary: {wordList: {words: ['quasimodo']}},
60 matchingType:
61 DLP.protos.google.privacy.dlp.v2.MatchingType
62 .MATCHING_TYPE_PARTIAL_MATCH,
63 };
64
65 const redactedRule = {
66 regex: {pattern: 'REDACTED'},
67 matchingType:
68 DLP.protos.google.privacy.dlp.v2.MatchingType
69 .MATCHING_TYPE_PARTIAL_MATCH,
70 };
71
72 // The infoTypes of information to match
73 const infoTypes = [{name: 'PERSON_NAME'}];
74
75 // Construct a ruleset that applies the rules to the PERSON_NAME infotype.
76 const ruleSet = [
77 {
78 infoTypes: infoTypes,

Callers 1

Calls 1

Tested by

no test coverage detected