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

Function inspectBigquery

dlp/inspectBigQuery.js:78–159  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

76 // const subscriptionId = 'MY-PUBSUB-SUBSCRIPTION'
77
78 async function inspectBigquery() {
79 // Construct item to be inspected
80 const storageItem = {
81 bigQueryOptions: {
82 tableReference: {
83 projectId: dataProjectId,
84 datasetId: datasetId,
85 tableId: tableId,
86 },
87 },
88 };
89
90 // Construct request for creating an inspect job
91 const request = {
92 parent: `projects/${projectId}/locations/global`,
93 inspectJob: {
94 inspectConfig: {
95 infoTypes: infoTypes,
96 customInfoTypes: customInfoTypes,
97 minLikelihood: minLikelihood,
98 limits: {
99 maxFindingsPerRequest: maxFindings,
100 },
101 },
102 storageConfig: storageItem,
103 actions: [
104 {
105 pubSub: {
106 topic: `projects/${projectId}/topics/${topicId}`,
107 },
108 },
109 ],
110 },
111 };
112
113 // Run inspect-job creation request
114 const [topicResponse] = await pubsub.topic(topicId).get();
115 // Verify the Pub/Sub topic and listen for job notifications via an
116 // existing subscription.
117 const subscription = await topicResponse.subscription(subscriptionId);
118 const [jobsResponse] = await dlp.createDlpJob(request);
119 const jobName = jobsResponse.name;
120 // Watch the Pub/Sub topic until the DLP job finishes
121 await new Promise((resolve, reject) => {
122 const messageHandler = message => {
123 if (message.attributes && message.attributes.DlpJobName === jobName) {
124 message.ack();
125 subscription.removeListener('message', messageHandler);
126 subscription.removeListener('error', errorHandler);
127 resolve(jobName);
128 } else {
129 message.nack();
130 }
131 };
132
133 const errorHandler = err => {
134 subscription.removeListener('message', messageHandler);
135 subscription.removeListener('error', errorHandler);

Callers 1

mainFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected