List job triggers (v2)

List job triggers in a Google Cloud project.

Code sample

Python

To learn how to install and use the client library for Sensitive Data Protection, see Sensitive Data Protection client libraries.

To authenticate to Sensitive Data Protection, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

import google.api_core.exceptions
from google.cloud import dlp_v2


def list_job_triggers(project_id: str) -> None:
    """Lists job triggers in a Google Cloud project.

    Args:
        project_id: The Google Cloud project ID (for example, 'example-project-id').
    """
    # Set the quota project to ensure service usage and quota evaluate against the target project.
    client = dlp_v2.DlpServiceClient(
        client_options={"quota_project_id": project_id}
    )
    parent = f"projects/{project_id}"

    request = dlp_v2.ListJobTriggersRequest(
        parent=parent,
    )

    try:
        response = client.list_job_triggers(request=request)
        found = False
        for trigger in response:
            found = True
            print(f"Trigger Name: {trigger.name}")
            print(f"Display Name: {trigger.display_name}")
            print(f"Status: {trigger.status}")
        if not found:
            print("No job triggers found.")
    except google.api_core.exceptions.PermissionDenied as e:
        print(f"Permission denied: {e}")
    except google.api_core.exceptions.NotFound as e:
        print(f"Resource not found: {e}")

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.