Skip to content

DLP: Add autoPopulateTimespan option for creating job triggers. #1134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion dlp/src/main/java/com/example/dlp/Triggers.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.privacy.dlp.v2.ProjectName;
import com.google.privacy.dlp.v2.Schedule;
import com.google.privacy.dlp.v2.StorageConfig;
import com.google.privacy.dlp.v2.StorageConfig.TimespanConfig;
import com.google.protobuf.Duration;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -52,6 +53,7 @@ public class Triggers {
* @param triggerId (Optional) name of the trigger to be created
* @param displayName (Optional) display name for the trigger to be created
* @param description (Optional) description for the trigger to be created
* @param autoPopulateTimespan If true, limits scans to new content only.
* @param scanPeriod How often to wait between scans, in days (minimum = 1 day)
* @param infoTypes infoTypes of information to match eg. InfoType.PHONE_NUMBER,
* InfoType.EMAIL_ADDRESS
Expand All @@ -65,6 +67,7 @@ private static void createTrigger(
String description,
String bucketName,
String fileName,
boolean autoPopulateTimespan,
int scanPeriod,
List<InfoType> infoTypes,
Likelihood minLikelihood,
Expand All @@ -82,8 +85,13 @@ private static void createTrigger(
CloudStorageOptions.FileSet.newBuilder()
.setUrl("gs://" + bucketName + "/" + fileName))
.build();

TimespanConfig timespanConfig = TimespanConfig.newBuilder()
.setEnableAutoPopulationOfTimespanConfig(autoPopulateTimespan).build();

StorageConfig storageConfig =
StorageConfig.newBuilder().setCloudStorageOptions(cloudStorageOptions).build();
StorageConfig.newBuilder().setCloudStorageOptions(cloudStorageOptions)
.setTimespanConfig(timespanConfig).build();

InspectConfig.FindingLimits findingLimits =
InspectConfig.FindingLimits.newBuilder().setMaxFindingsPerRequest(maxFindings).build();
Expand Down Expand Up @@ -216,6 +224,10 @@ public static void main(String[] args) throws Exception {
Option gcsFileNameOption = Option.builder("fileName").hasArg(true).required(false).build();
commandLineOptions.addOption(gcsFileNameOption);

Option autoPopulateTimespanOption = Option.builder("autoPopulateTimespan").required(false)
.build();
commandLineOptions.addOption(autoPopulateTimespanOption);

Option minLikelihoodOption =
Option.builder("minLikelihood").hasArg(true).required(false).build();

Expand Down Expand Up @@ -268,6 +280,8 @@ public static void main(String[] args) throws Exception {
String description = cmd.getOptionValue(descriptionOption.getOpt(), "");
String bucketName = cmd.getOptionValue(bucketNameOption.getOpt());
String fileName = cmd.getOptionValue(gcsFileNameOption.getOpt());
boolean autoPopulateTimespan = Boolean
.valueOf(cmd.getOptionValue(autoPopulateTimespanOption.getOpt()));
int scanPeriod = Integer.valueOf(cmd.getOptionValue(scanPeriodOption.getOpt()));
List<InfoType> infoTypesList = new ArrayList<>();
if (cmd.hasOption(infoTypesOption.getOpt())) {
Expand All @@ -283,6 +297,7 @@ public static void main(String[] args) throws Exception {
description,
bucketName,
fileName,
autoPopulateTimespan,
scanPeriod,
infoTypesList,
minLikelihood,
Expand Down
7 changes: 2 additions & 5 deletions dlp/src/test/java/com/example/dlp/TriggersIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,13 @@ public class TriggersIT {
//CHECKSTYLE ON: AbbreviationAsWordInName

private ByteArrayOutputStream bout;
private PrintStream out;

private String bucketName = System.getenv("GOOGLE_CLOUD_PROJECT") + "/dlp";
private String topicId = "dlp-tests";
private String subscriptionId = "dlp-test";

@Before
public void setUp() {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
System.setOut(out);
System.setOut(new PrintStream(bout));
assertNotNull(System.getenv("GOOGLE_APPLICATION_CREDENTIALS"));
}

Expand All @@ -74,6 +70,7 @@ public void testCreateTrigger() throws Exception {
bucketName,
"-fileName",
"test.txt",
"-autoPopulateTimespan",
"-scanPeriod",
"1"
});
Expand Down