MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

dlp/inspectStringWithExclusionRegex.js:21–102  ·  view source on GitHub ↗
(projectId, string, exclusionRegex)

Source from the content-addressed store, hash-verified

19// description: Inspect a string with list of regex as exclusions.
20// usage: node inspectStringWithExclusionRegex.js my-project string exclusionRegex
21function main(projectId, string, exclusionRegex) {
22 // [START dlp_inspect_string_with_exclusion_regex]
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 = 'Some email addresses: gary@example.com, bob@example.org';
34
35 // Exclusion Regex
36 // const exclusionRegex = '.+@example.com';
37
38 async function inspectStringMultipleRules() {
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 // Info Types for inspection
49 const infoTypes = [{name: 'EMAIL_ADDRESS'}];
50
51 // Construct a exclusion rule that uses a regex pattern
52 const exclusionRule = {
53 regex: {pattern: exclusionRegex},
54 matchingType:
55 DLP.protos.google.privacy.dlp.v2.MatchingType.MATCHING_TYPE_FULL_MATCH,
56 };
57
58 // Construct a ruleset that applies the exclusion rule to the EMAIL_ADDRESSES infotype.
59 const ruleSet = [
60 {
61 infoTypes: infoTypes,
62 rules: [
63 {
64 exclusionRule: exclusionRule,
65 },
66 ],
67 },
68 ];
69
70 // Construct the configuration for the Inspect request, including the ruleset.
71 const inspectConfig = {
72 infoTypes: infoTypes,
73 ruleSet: ruleSet,
74 includeQuote: true,
75 };
76
77 // Construct the Inspect request to be sent by the client.
78 const request = {

Calls 1

Tested by

no test coverage detected