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

Function main

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

Source from the content-addressed store, hash-verified

19// description: De-identify sensitive data in a string by replacing it with a given time config.
20// usage: node deidentifyWithTimeExtraction.js my-project string
21function main(projectId) {
22 // [START dlp_deidentify_time_extract]
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 de-identify
33 // const string = 'My BirthDay is on 9/21/1976';
34
35 // Table to de-identify
36 const tablularData = {
37 headers: [
38 {name: 'Name'},
39 {name: 'Birth Date'},
40 {name: 'Credit Card'},
41 {name: 'Register Date'},
42 ],
43 rows: [
44 {
45 values: [
46 {stringValue: 'Ann'},
47 {stringValue: '01/01/1970'},
48 {stringValue: '4532908762519852'},
49 {stringValue: '07/21/1996'},
50 ],
51 },
52 {
53 values: [
54 {stringValue: 'James'},
55 {stringValue: '03/06/1988'},
56 {stringValue: '4301261899725540'},
57 {stringValue: '04/09/2001'},
58 ],
59 },
60 ],
61 };
62
63 async function deidentifyWithTimeExtraction() {
64 // Specify transformation to extract a portion of date.
65 const primitiveTransformation = {
66 timePartConfig: {
67 partToExtract: 'YEAR',
68 },
69 };
70
71 // Specify which fields the TimePart should apply too
72 const dateFields = [{name: 'Birth Date'}, {name: 'Register Date'}];
73
74 // Construct de-identification request to be sent by client.
75 const request = {
76 parent: `projects/${projectId}/locations/global`,
77 deidentifyConfig: {
78 recordTransformations: {

Callers 1

Calls 1

Tested by

no test coverage detected