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

Function main

dlp/inspectWithCustomHotwords.js:21–114  ·  view source on GitHub ↗
(projectId)

Source from the content-addressed store, hash-verified

19// description: Uses the Data Loss Prevention API to inspect a table excluding findings from an entire column.
20// usage: node inspectWithCustomHotwords.js projectId
21function main(projectId) {
22 // [START dlp_inspect_column_values_w_custom_hotwords]
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 = "your-project-id";
31
32 // Table to inspect
33 const tableToInspect = {
34 headers: [
35 {name: 'Fake Social Security Number'},
36 {name: 'Real Social Security Number'},
37 ],
38 rows: [
39 {
40 values: [{stringValue: '111-11-1111'}, {stringValue: '222-22-2222'}],
41 },
42 ],
43 };
44
45 async function inspectWithCustomHotwords() {
46 // Specify the regex pattern to be detected.
47 const hotwordRegexPattern = '(Fake Social Security Number)';
48
49 // Specify what content you want the service to de-identify.
50 const contentItem = {
51 table: tableToInspect,
52 };
53
54 // Specify the type of info the inspection will look for.
55 const infoTypes = [{name: 'US_SOCIAL_SECURITY_NUMBER'}];
56
57 // Construct hotword rule.
58 const hotwordRule = {
59 hotwordRegex: {
60 pattern: hotwordRegexPattern,
61 },
62 likelihoodAdjustment: {
63 fixedLikelihood:
64 DLP.protos.google.privacy.dlp.v2.Likelihood.VERY_UNLIKELY,
65 },
66 proximity: {
67 windowBefore: 1,
68 },
69 };
70
71 // Construct rule set for the inspect configuration.
72 const inspectionRuleSet = {
73 infoTypes: infoTypes,
74 rules: [
75 {
76 hotwordRule: hotwordRule,
77 },
78 ],

Callers 1

Calls 1

Tested by

no test coverage detected