(projectId, cloudFileUrl)
| 19 | // description: Create an inspection job |
| 20 | // usage: node createJob.js my-project bucket-url |
| 21 | function main(projectId, cloudFileUrl) { |
| 22 | // [START dlp_create_job] |
| 23 | // Imports the Google Cloud Data Loss Prevention library |
| 24 | const DLP = require('@google-cloud/dlp'); |
| 25 | |
| 26 | // Initialize google DLP Client |
| 27 | const dlp = new DLP.DlpServiceClient(); |
| 28 | |
| 29 | async function jobsCreate() { |
| 30 | // Construct cloud storage configuration |
| 31 | const cloudStorageConfig = { |
| 32 | cloudStorageOptions: { |
| 33 | fileSet: { |
| 34 | url: cloudFileUrl, |
| 35 | }, |
| 36 | }, |
| 37 | timespanConfig: { |
| 38 | enableAutoPopulationOfTimespanConfig: true, |
| 39 | }, |
| 40 | }; |
| 41 | |
| 42 | // Construct inspect job configuration |
| 43 | const inspectJob = { |
| 44 | storageConfig: cloudStorageConfig, |
| 45 | }; |
| 46 | |
| 47 | // Construct inspect configuration |
| 48 | const inspectConfig = { |
| 49 | infoTypes: [ |
| 50 | {name: 'EMAIL_ADDRESS'}, |
| 51 | {name: 'PERSON_NAME'}, |
| 52 | {name: 'LOCATION'}, |
| 53 | {name: 'PHONE_NUMBER'}, |
| 54 | ], |
| 55 | includeQuote: true, |
| 56 | minLikelihood: DLP.protos.google.privacy.dlp.v2.Likelihood.LIKELY, |
| 57 | excludeInfoTypes: false, |
| 58 | }; |
| 59 | |
| 60 | // Combine configurations into a request for the service. |
| 61 | const request = { |
| 62 | parent: `projects/${projectId}/locations/global`, |
| 63 | inspectJob: inspectJob, |
| 64 | inspectConfig: inspectConfig, |
| 65 | }; |
| 66 | |
| 67 | // Send the request and receive response from the service |
| 68 | const [response] = await dlp.createDlpJob(request); |
| 69 | // Print the results |
| 70 | console.log(`Job created successfully: ${response.name}`); |
| 71 | } |
| 72 | |
| 73 | jobsCreate(); |
| 74 | // [END dlp_create_job] |
| 75 | } |
| 76 | |
| 77 | process.on('unhandledRejection', err => { |
| 78 | console.error(err.message); |
no test coverage detected