Cloud Data Loss Prevention (Cloud DLP) is now a part of Sensitive Data Protection. The API name remains the same: Cloud Data Loss Prevention API (DLP API). For information about the services that make up Sensitive Data Protection, see
Sensitive Data Protection overview.
Create a job trigger
Stay organized with collections
Save and categorize content based on your preferences.
Creates a scheduled Cloud Data Loss Prevention API job trigger.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Go
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 (
"context"
"fmt"
"io"
dlp "cloud.google.com/go/dlp/apiv2"
"cloud.google.com/go/dlp/apiv2/dlppb"
"github.com/golang/protobuf/ptypes/duration"
)
// createTrigger creates a trigger with the given configuration.
func createTrigger(w io.Writer, projectID string, triggerID, displayName, description, bucketName string, infoTypeNames []string) error {
// projectID := "my-project-id"
// triggerID := "my-trigger"
// displayName := "My Trigger"
// description := "My trigger description"
// bucketName := "my-bucket"
// infoTypeNames := []string{"US_SOCIAL_SECURITY_NUMBER"}
ctx := context.Background()
client, err := dlp.NewClient(ctx)
if err != nil {
return fmt.Errorf("dlp.NewClient: %w", err)
}
defer client.Close()
// Convert the info type strings to a list of InfoTypes.
var infoTypes []*dlppb.InfoType
for _, it := range infoTypeNames {
infoTypes = append(infoTypes, &dlppb.InfoType{Name: it})
}
// Create a configured request.
req := &dlppb.CreateJobTriggerRequest{
Parent: fmt.Sprintf("projects/%s/locations/global", projectID),
TriggerId: triggerID,
JobTrigger: &dlppb.JobTrigger{
DisplayName: displayName,
Description: description,
Status: dlppb.JobTrigger_HEALTHY,
// Triggers control when the job will start.
Triggers: []*dlppb.JobTrigger_Trigger{
{
Trigger: &dlppb.JobTrigger_Trigger_Schedule{
Schedule: &dlppb.Schedule{
Option: &dlppb.Schedule_RecurrencePeriodDuration{
RecurrencePeriodDuration: &duration.Duration{
Seconds: 10 * 60 * 60 * 24, // 10 days in seconds.
},
},
},
},
},
},
// Job configures the job to run when the trigger runs.
Job: &dlppb.JobTrigger_InspectJob{
InspectJob: &dlppb.InspectJobConfig{
InspectConfig: &dlppb.InspectConfig{
InfoTypes: infoTypes,
MinLikelihood: dlppb.Likelihood_POSSIBLE,
Limits: &dlppb.InspectConfig_FindingLimits{
MaxFindingsPerRequest: 10,
},
},
StorageConfig: &dlppb.StorageConfig{
Type: &dlppb.StorageConfig_CloudStorageOptions{
CloudStorageOptions: &dlppb.CloudStorageOptions{
FileSet: &dlppb.CloudStorageOptions_FileSet{
Url: "gs://" + bucketName + "/*",
},
},
},
// Time-based configuration for each storage object. See more at
// https://cloud.google.com/dlp/docs/reference/rest/v2/InspectJobConfig#TimespanConfig
TimespanConfig: &dlppb.StorageConfig_TimespanConfig{
// Auto-populate start and end times in order to scan new objects only.
EnableAutoPopulationOfTimespanConfig: true,
},
},
},
},
},
}
// Send the request.
resp, err := client.CreateJobTrigger(ctx, req)
if err != nil {
return fmt.Errorf("CreateJobTrigger: %w", err)
}
fmt.Fprintf(w, "Successfully created trigger: %v", resp.GetName())
return nil
}
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]