(projectId, string, infoTypes, excludedWords)
| 20 | // usage: node inspectStringWithExclusionDict.js my-project string infoTypes excludedWords |
| 21 | |
| 22 | function main(projectId, string, infoTypes, excludedWords) { |
| 23 | [infoTypes, excludedWords] = transformCLI(infoTypes, excludedWords); |
| 24 | // [START dlp_inspect_string_with_exclusion_dict] |
| 25 | // Imports the Google Cloud Data Loss Prevention library |
| 26 | const DLP = require('@google-cloud/dlp'); |
| 27 | |
| 28 | // Instantiates a client |
| 29 | const dlp = new DLP.DlpServiceClient(); |
| 30 | |
| 31 | // The project ID to run the API call under |
| 32 | // const projectId = 'my-project'; |
| 33 | |
| 34 | // The string to inspect |
| 35 | // const string = 'Some email addresses: gary@example.com, example@example.com'; |
| 36 | |
| 37 | // The infoTypes of information to match |
| 38 | // const infoTypes = [{ name: 'EMAIL_ADDRESS' }]; |
| 39 | |
| 40 | // Words to exclude |
| 41 | // const excludedWords = ['gary@example.com']; |
| 42 | |
| 43 | async function inspectStringWithExclusionDict() { |
| 44 | // Specify the type and content to be inspected. |
| 45 | const item = { |
| 46 | byteItem: { |
| 47 | type: DLP.protos.google.privacy.dlp.v2.ByteContentItem.BytesType |
| 48 | .TEXT_UTF8, |
| 49 | data: Buffer.from(string, 'utf-8'), |
| 50 | }, |
| 51 | }; |
| 52 | |
| 53 | // Exclude matches from the specified excludedWords. |
| 54 | const exclusionRule = { |
| 55 | dictionary: { |
| 56 | wordList: { |
| 57 | words: excludedWords, |
| 58 | }, |
| 59 | }, |
| 60 | matchingType: |
| 61 | DLP.protos.google.privacy.dlp.v2.MatchingType.MATCHING_TYPE_FULL_MATCH, |
| 62 | }; |
| 63 | |
| 64 | // Construct a ruleset that applies the exclusion rule to the specified infotype. |
| 65 | const ruleSet = [ |
| 66 | { |
| 67 | infoTypes: infoTypes, |
| 68 | rules: [ |
| 69 | { |
| 70 | exclusionRule: exclusionRule, |
| 71 | }, |
| 72 | ], |
| 73 | }, |
| 74 | ]; |
| 75 | |
| 76 | // Construct the configuration for the Inspect request, including the ruleset. |
| 77 | const inspectConfig = { |
| 78 | infoTypes: infoTypes, |
| 79 | ruleSet: ruleSet, |
no test coverage detected