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