| 20 | // usage: node listJobs.js my-project filter jobType |
| 21 | |
| 22 | function main(projectId, filter, jobType) { |
| 23 | // [START dlp_list_jobs] |
| 24 | // Imports the Google Cloud Data Loss Prevention library |
| 25 | const DLP = require('@google-cloud/dlp'); |
| 26 | |
| 27 | // Instantiates a client |
| 28 | const dlp = new DLP.DlpServiceClient(); |
| 29 | |
| 30 | // The project ID to run the API call under |
| 31 | // const projectId = 'my-project'; |
| 32 | |
| 33 | // The filter expression to use |
| 34 | // For more information and filter syntax, see https://cloud.google.com/dlp/docs/reference/rest/v2/projects.dlpJobs/list |
| 35 | // const filter = `state=DONE`; |
| 36 | |
| 37 | // The type of job to list (either 'INSPECT_JOB' or 'RISK_ANALYSIS_JOB') |
| 38 | // const jobType = 'INSPECT_JOB'; |
| 39 | async function listJobs() { |
| 40 | // Construct request for listing DLP scan jobs |
| 41 | const request = { |
| 42 | parent: `projects/${projectId}/locations/global`, |
| 43 | filter: filter, |
| 44 | type: jobType, |
| 45 | }; |
| 46 | |
| 47 | // Run job-listing request |
| 48 | const [jobs] = await dlp.listDlpJobs(request); |
| 49 | jobs.forEach(job => { |
| 50 | console.log(`Job ${job.name} status: ${job.state}`); |
| 51 | }); |
| 52 | } |
| 53 | |
| 54 | listJobs(); |
| 55 | // [END dlp_list_jobs] |
| 56 | } |
| 57 | |
| 58 | main(...process.argv.slice(2)); |
| 59 | process.on('unhandledRejection', err => { |