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