(projectId, string)
| 20 | // usage: node inspectStringWithoutOverlap.js my-project string |
| 21 | |
| 22 | function main(projectId, string) { |
| 23 | // [START dlp_inspect_string_without_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 = 'example.com is a domain, james@example.org is an email.'; |
| 35 | |
| 36 | async function inspectStringWithoutOverlap() { |
| 37 | // Construct item to inspect |
| 38 | const item = {value: string}; |
| 39 | |
| 40 | // The infoTypes of information to match |
| 41 | const infoTypes = [{name: 'DOMAIN_NAME'}, {name: 'EMAIL_ADDRESS'}]; |
| 42 | |
| 43 | // Define a custom info type to exclude email addresses |
| 44 | const customInfoTypes = [ |
| 45 | { |
| 46 | infoType: {name: 'EMAIL_ADDRESS'}, |
| 47 | exclusionType: |
| 48 | DLP.protos.google.privacy.dlp.v2.CustomInfoType.ExclusionType |
| 49 | .EXCLUSION_TYPE_EXCLUDE, |
| 50 | }, |
| 51 | ]; |
| 52 | |
| 53 | // Construct a exclusion rule |
| 54 | const exclusionRule = { |
| 55 | excludeInfoTypes: { |
| 56 | infoTypes: [{name: 'EMAIL_ADDRESS'}], |
| 57 | }, |
| 58 | matchingType: |
| 59 | DLP.protos.google.privacy.dlp.v2.MatchingType |
| 60 | .MATCHING_TYPE_PARTIAL_MATCH, |
| 61 | }; |
| 62 | |
| 63 | // Construct a rule set with exclusions |
| 64 | const ruleSet = [ |
| 65 | { |
| 66 | infoTypes: [{name: 'DOMAIN_NAME'}], |
| 67 | rules: [ |
| 68 | { |
| 69 | exclusionRule: exclusionRule, |
| 70 | }, |
| 71 | ], |
| 72 | }, |
| 73 | ]; |
| 74 | |
| 75 | // Construct the inspect configuration |
| 76 | const inspectConfig = { |
| 77 | infoTypes: infoTypes, |
| 78 | customInfoTypes: customInfoTypes, |
| 79 | ruleSet: ruleSet, |
no test coverage detected