(projectId, string, customHotword)
| 19 | // description: Inspect a string for sensitive data using a custom hotword and increase the likelihood of match |
| 20 | // usage: node inspectStringCustomHotword.js my-project string customHotword |
| 21 | function main(projectId, string, customHotword) { |
| 22 | // [START dlp_inspect_string_custom_hotword] |
| 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 name: John Doe'; |
| 34 | |
| 35 | // Custom hotward |
| 36 | // const customHotword = 'patient'; |
| 37 | |
| 38 | async function inspectStringCustomHotword() { |
| 39 | // Specify the type and content to be inspected. |
| 40 | const item = { |
| 41 | byteItem: { |
| 42 | type: DLP.protos.google.privacy.dlp.v2.ByteContentItem.BytesType |
| 43 | .TEXT_UTF8, |
| 44 | data: Buffer.from(string, 'utf-8'), |
| 45 | }, |
| 46 | }; |
| 47 | |
| 48 | // Increase likelihood of matches that have customHotword nearby. |
| 49 | const hotwordRule = { |
| 50 | hotwordRegex: { |
| 51 | pattern: customHotword, |
| 52 | }, |
| 53 | proximity: { |
| 54 | windowBefore: 50, |
| 55 | }, |
| 56 | likelihoodAdjustment: { |
| 57 | fixedLikelihood: |
| 58 | DLP.protos.google.privacy.dlp.v2.Likelihood.VERY_LIKELY, |
| 59 | }, |
| 60 | }; |
| 61 | |
| 62 | // Construct a ruleset that applies the hotword rule to the PERSON_NAME infotype. |
| 63 | const ruleSet = [ |
| 64 | { |
| 65 | infoTypes: [{name: 'PERSON_NAME'}], |
| 66 | rules: [ |
| 67 | { |
| 68 | hotwordRule: hotwordRule, |
| 69 | }, |
| 70 | ], |
| 71 | }, |
| 72 | ]; |
| 73 | |
| 74 | // Construct the configuration for the Inspect request. |
| 75 | const inspectConfig = { |
| 76 | infoTypes: [{name: 'PERSON_NAME'}], |
| 77 | ruleSet: ruleSet, |
| 78 | includeQuote: true, |
no test coverage detected