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

Function main

dlp/deidentifyWithDictionaryReplacement.js:21–86  ·  view source on GitHub ↗
(projectId, string, infoTypes, words)

Source from the content-addressed store, hash-verified

19// description: De-identify sensitive data in a string by replacing it with a random list of replacement string.
20// usage: node deidentifyWithDictionaryReplacement.js my-project string infoTypes words
21function main(projectId, string, infoTypes, words) {
22 [infoTypes, words] = transformCLI(infoTypes, words);
23 // [START dlp_deidentify_dictionary_replacement]
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 de-identify
34 // const string = 'My name is Alicia Abernathy, and my email address is aabernathy@example.com.';
35
36 // The infoTypes of information to match
37 // const infoTypes = [{ name: 'EMAIL_ADDRESS' }];
38
39 // The words to replace sensitive information with
40 // const words = ['izumi@example.com', 'alex@example.com', 'tal@example.com'];
41
42 async function deidentifyWithDictionaryReplacement() {
43 // Construct word list to be used for replacement
44 const wordList = {
45 words: words,
46 };
47 // Construct item to de-identify
48 const item = {value: string};
49
50 // Specify replacement dictionary config using word list.
51 const replaceDictionaryConfig = {
52 wordList: wordList,
53 };
54
55 // Associate replacement dictionary config with infotype transformation.
56 const infoTypeTransformations = {
57 transformations: [
58 {
59 infoTypes: infoTypes,
60 primitiveTransformation: {
61 replaceDictionaryConfig: replaceDictionaryConfig,
62 },
63 },
64 ],
65 };
66
67 // Combine configurations into a request for the service.
68 const request = {
69 parent: `projects/${projectId}/locations/global`,
70 deidentifyConfig: {
71 infoTypeTransformations: infoTypeTransformations,
72 },
73 item: item,
74 };
75
76 // Run de-identification request.
77 const [response] = await dlp.deidentifyContent(request);
78 const deidentifiedItem = response.item;

Calls 2

transformCLIFunction · 0.70

Tested by

no test coverage detected