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

Function lDiversityAnalysis

dlp/lDiversityAnalysis.js:68–157  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 2

mainFunction · 0.85
risk.test.jsFile · 0.85

Calls 2

getValueFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected