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

Function inspectGCSFile

dlp/inspectGCSFile.js:74–152  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 2

mainFunction · 0.85
inspect.test.jsFile · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected