( projectId, string, minLikelihood, maxFindings, infoTypes, customInfoTypes, includeQuote, hotwordRegexPattern )
| 20 | // usage: node inspectWithHotwordRules.js my-project string minLikelihood maxFindings infoTypes customInfoTypes includeQuote hotwordRegexPattern |
| 21 | |
| 22 | function main( |
| 23 | projectId, |
| 24 | string, |
| 25 | minLikelihood, |
| 26 | maxFindings, |
| 27 | infoTypes, |
| 28 | customInfoTypes, |
| 29 | includeQuote, |
| 30 | hotwordRegexPattern |
| 31 | ) { |
| 32 | [infoTypes, customInfoTypes] = transformCLI(infoTypes, customInfoTypes); |
| 33 | // [START dlp_inspect_hotword_rule] |
| 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 = 'Patients MRN 444-5-22222'; |
| 45 | |
| 46 | // The minimum likelihood required before returning a match |
| 47 | // const minLikelihood = DLP.protos.google.privacy.dlp.v2.Likelihood.POSSIBLE; |
| 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 | // See https://cloud.google.com/dlp/docs/concepts-infotypes for more information |
| 54 | // about supported infoTypes. |
| 55 | // const infoTypes = [{ name: 'EMAIL_ADDRESS' }]; |
| 56 | |
| 57 | // The customInfoTypes of information to match |
| 58 | // const customInfoTypes = [{ infoType: { name: 'DICT_TYPE' }, dictionary: { wordList: { words: ['foo', 'bar', 'baz']}}}, |
| 59 | // { infoType: { name: 'REGEX_TYPE' }, regex: {pattern: '\\(\\d{3}\\) \\d{3}-\\d{4}'}}]; |
| 60 | |
| 61 | // Whether to include the matching string |
| 62 | // const includeQuote = true; |
| 63 | |
| 64 | // Custom hotword regex patten |
| 65 | // const hotwordRegexPattern = '(?i)(mrn|medical)(?-i)'; |
| 66 | |
| 67 | async function inspectWithHotwordRule() { |
| 68 | // Construct item to inspect |
| 69 | const item = { |
| 70 | byteItem: { |
| 71 | type: DLP.protos.google.privacy.dlp.v2.ByteContentItem.BytesType |
| 72 | .TEXT_UTF8, |
| 73 | data: Buffer.from(string, 'utf-8'), |
| 74 | }, |
| 75 | }; |
| 76 | |
| 77 | // Construct a hot word rule |
| 78 | const hotwordRule = { |
| 79 | hotwordRegex: { |
no test coverage detected