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

Function main

dlp/redactText.js:20–65  ·  view source on GitHub ↗
(projectId, string, minLikelihood, infoTypes)

Source from the content-addressed store, hash-verified

18// usage: node redactText.js my-project string minLikelihood infoTypes
19
20function main(projectId, string, minLikelihood, infoTypes) {
21 infoTypes = transformCLI(infoTypes);
22 // [START dlp_redact_text]
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 // Construct transformation config which replaces sensitive info with its info type.
33 // E.g., "Her email is xxx@example.com" => "Her email is [EMAIL_ADDRESS]"
34 const replaceWithInfoTypeTransformation = {
35 primitiveTransformation: {
36 replaceWithInfoTypeConfig: {},
37 },
38 };
39
40 async function redactText() {
41 // Construct redaction request
42 const request = {
43 parent: `projects/${projectId}/locations/global`,
44 item: {
45 value: string,
46 },
47 deidentifyConfig: {
48 infoTypeTransformations: {
49 transformations: [replaceWithInfoTypeTransformation],
50 },
51 },
52 inspectConfig: {
53 minLikelihood: minLikelihood,
54 infoTypes: infoTypes,
55 },
56 };
57
58 // Run string redaction
59 const [response] = await dlp.deidentifyContent(request);
60 const resultString = response.item.value;
61 console.log(`Redacted text: ${resultString}`);
62 }
63 redactText();
64 // [END dlp_redact_text]
65}
66
67main(...process.argv.slice(2));
68process.on('unhandledRejection', err => {

Callers 1

redactText.jsFile · 0.70

Calls 2

redactTextFunction · 0.85
transformCLIFunction · 0.70

Tested by

no test coverage detected