(projectId, textToInspect, words, infoTypes)
| 20 | // usage: node deIdentifyWithExceptionList.js my-project string words infotypes |
| 21 | |
| 22 | function main(projectId, textToInspect, words, infoTypes) { |
| 23 | words = words.split(','); |
| 24 | infoTypes = transformCLI(infoTypes); |
| 25 | // [START dlp_deidentify_exception_list] |
| 26 | // Imports the Google Cloud Data Loss Prevention library |
| 27 | const DLP = require('@google-cloud/dlp'); |
| 28 | |
| 29 | // Initialize client that will be used to send requests. This client only needs to be created |
| 30 | // once, and can be reused for multiple requests. After completing all of your requests, call |
| 31 | // the "close" method on the client to safely clean up any remaining background resources. |
| 32 | const dlp = new DLP.DlpServiceClient(); |
| 33 | |
| 34 | // TODO(developer): Replace these variables before running the sample. |
| 35 | // const projectId = "your-project-id"; |
| 36 | |
| 37 | // The string to deidentify |
| 38 | // const textToInspect = 'jack@example.org accessed customer record of user5@example.com'; |
| 39 | |
| 40 | // Words to exclude for during inspection |
| 41 | // const words = ['jack@example.org', 'jill@example.org']; |
| 42 | |
| 43 | // The infoTypes of information to match |
| 44 | // See https://cloud.google.com/dlp/docs/concepts-infotypes for more information |
| 45 | // about supported infoTypes. |
| 46 | // const infoTypes = [{ name: 'EMAIL_ADDRESS' }]; |
| 47 | |
| 48 | async function deIdentifyWithExceptionList() { |
| 49 | // Construct item to inspect |
| 50 | const item = {value: textToInspect}; |
| 51 | |
| 52 | // Construct the custom dictionary detector associated with the word list. |
| 53 | const wordListDict = { |
| 54 | wordList: { |
| 55 | words: words, |
| 56 | }, |
| 57 | }; |
| 58 | |
| 59 | // Construct a rule set that will only match if the match text does not |
| 60 | // contains tokens from the exclusion list. |
| 61 | const ruleSet = [ |
| 62 | { |
| 63 | infoTypes: infoTypes, |
| 64 | rules: [ |
| 65 | { |
| 66 | exclusionRule: { |
| 67 | matchingType: |
| 68 | DLP.protos.google.privacy.dlp.v2.MatchingType |
| 69 | .MATCHING_TYPE_FULL_MATCH, |
| 70 | dictionary: wordListDict, |
| 71 | }, |
| 72 | }, |
| 73 | ], |
| 74 | }, |
| 75 | ]; |
| 76 | |
| 77 | // Combine configurations to construct inspect config. |
| 78 | const inspectConfig = { |
| 79 | infoTypes: infoTypes, |
no test coverage detected