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

Function main

dlp/listTriggers.js:22–65  ·  view source on GitHub ↗
(projectId)

Source from the content-addressed store, hash-verified

20// usage: node listTriggers.js my-project
21
22function main(projectId) {
23 // [START dlp_list_triggers]
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 async function listTriggers() {
34 // Construct trigger listing request
35 const request = {
36 parent: `projects/${projectId}/locations/global`,
37 };
38
39 // Helper function to pretty-print dates
40 const formatDate = date => {
41 const msSinceEpoch = parseInt(date.seconds, 10) * 1000;
42 return new Date(msSinceEpoch).toLocaleString('en-US');
43 };
44
45 // Run trigger listing request
46 const [triggers] = await dlp.listJobTriggers(request);
47 triggers.forEach(trigger => {
48 // Log trigger details
49 console.log(`Trigger ${trigger.name}:`);
50 console.log(` Created: ${formatDate(trigger.createTime)}`);
51 console.log(` Updated: ${formatDate(trigger.updateTime)}`);
52 if (trigger.displayName) {
53 console.log(` Display Name: ${trigger.displayName}`);
54 }
55 if (trigger.description) {
56 console.log(` Description: ${trigger.description}`);
57 }
58 console.log(` Status: ${trigger.status}`);
59 console.log(` Error count: ${trigger.errors.length}`);
60 });
61 }
62
63 listTriggers();
64 // [END dlp_list_triggers]
65}
66
67main(...process.argv.slice(2));
68process.on('unhandledRejection', err => {

Callers 1

listTriggers.jsFile · 0.70

Calls 1

listTriggersFunction · 0.85

Tested by

no test coverage detected