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

Function main

dlp/deidentifyWithReplacement.js:22–70  ·  view source on GitHub ↗
(projectId, string, replacement)

Source from the content-addressed store, hash-verified

20// usage: node deidentifyWithMask.js my-project string replacement
21
22function main(projectId, string, replacement) {
23 // [START dlp_deidentify_replace]
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 deidentify
34 // const string = 'My SSN is 372819127';
35
36 // The string to replace sensitive information with
37 // const replacement = "[REDACTED]"
38
39 async function deidentifyWithReplacement() {
40 // Construct deidentification request
41 const item = {value: string};
42 const request = {
43 parent: `projects/${projectId}/locations/global`,
44 deidentifyConfig: {
45 infoTypeTransformations: {
46 transformations: [
47 {
48 primitiveTransformation: {
49 replaceConfig: {
50 newValue: {
51 stringValue: replacement,
52 },
53 },
54 },
55 },
56 ],
57 },
58 },
59 item: item,
60 };
61
62 // Run deidentification request
63 const [response] = await dlp.deidentifyContent(request);
64 const deidentifiedItem = response.item;
65 console.log(deidentifiedItem.value);
66 }
67
68 deidentifyWithReplacement();
69 // [END dlp_deidentify_replace]
70}
71
72main(...process.argv.slice(2));
73process.on('unhandledRejection', err => {

Callers 1

Calls 1

Tested by

no test coverage detected