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

Function kAnonymityAnalysis

dlp/kAnonymityAnalysis.js:64–143  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62 // A set of columns that form a composite key ('quasi-identifiers')
63 // const quasiIds = [{ name: 'age' }, { name: 'city' }];
64 async function kAnonymityAnalysis() {
65 const sourceTable = {
66 projectId: tableProjectId,
67 datasetId: datasetId,
68 tableId: tableId,
69 };
70 // Construct request for creating a risk analysis job
71
72 const request = {
73 parent: `projects/${projectId}/locations/global`,
74 riskJob: {
75 privacyMetric: {
76 kAnonymityConfig: {
77 quasiIds: quasiIds,
78 },
79 },
80 sourceTable: sourceTable,
81 actions: [
82 {
83 pubSub: {
84 topic: `projects/${projectId}/topics/${topicId}`,
85 },
86 },
87 ],
88 },
89 };
90
91 // Create helper function for unpacking values
92 const getValue = obj => obj[Object.keys(obj)[0]];
93
94 // Run risk analysis job
95 const [topicResponse] = await pubsub.topic(topicId).get();
96 const subscription = await topicResponse.subscription(subscriptionId);
97 const [jobsResponse] = await dlp.createDlpJob(request);
98 const jobName = jobsResponse.name;
99 console.log(`Job created. Job name: ${jobName}`);
100 // Watch the Pub/Sub topic until the DLP job finishes
101 await new Promise((resolve, reject) => {
102 const messageHandler = message => {
103 if (message.attributes && message.attributes.DlpJobName === jobName) {
104 message.ack();
105 subscription.removeListener('message', messageHandler);
106 subscription.removeListener('error', errorHandler);
107 resolve(jobName);
108 } else {
109 message.nack();
110 }
111 };
112
113 const errorHandler = err => {
114 subscription.removeListener('message', messageHandler);
115 subscription.removeListener('error', errorHandler);
116 reject(err);
117 };
118
119 subscription.on('message', messageHandler);
120 subscription.on('error', errorHandler);
121 });

Callers 2

mainFunction · 0.85
risk.test.jsFile · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected