Skip to content

Commit b9fbf5b

Browse files
micheldavidbshaffer
authored andcommitted
DLP: Add autoPopulateTimespan option for creating job triggers. (GoogleCloudPlatform#633)
1 parent 2312750 commit b9fbf5b

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

dlp/dlp.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@
276276
->addArgument('trigger-id', InputArgument::OPTIONAL, 'The name of the trigger to be created', '')
277277
->addArgument('display-name', InputArgument::OPTIONAL, 'The human-readable name to give the trigger', '')
278278
->addArgument('description', InputArgument::OPTIONAL, 'A description for the trigger to be created', '')
279+
->addArgument('auto-populate-timespan', InputArgument::OPTIONAL, 'Limit scan to new content only')
279280
->addArgument(
280281
'max-findings',
281282
InputArgument::OPTIONAL,
@@ -291,7 +292,8 @@
291292
$input->getArgument('display-name'),
292293
$input->getArgument('description'),
293294
(int) $input->getArgument('frequency'),
294-
(int) $input->getArgument('max-findings')
295+
(int) $input->getArgument('max-findings'),
296+
(bool) $input->getArgument('auto-populate-timespan')
295297
);
296298
});
297299

dlp/src/create_trigger.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Google\Cloud\Dlp\V2\CloudStorageOptions;
2929
use Google\Cloud\Dlp\V2\CloudStorageOptions_FileSet;
3030
use Google\Cloud\Dlp\V2\StorageConfig;
31+
use Google\Cloud\Dlp\V2\StorageConfig_TimespanConfig;
3132
use Google\Cloud\Dlp\V2\InfoType;
3233
use Google\Cloud\Dlp\V2\Likelihood;
3334
use Google\Cloud\Dlp\V2\InspectConfig_FindingLimits;
@@ -43,6 +44,7 @@
4344
* @param string $description (Optional) A description for the trigger to be created
4445
* @param int $scanPeriod (Optional) How often to wait between scans, in days (minimum = 1 day)
4546
* @param int $maxFindings (Optional) The maximum number of findings to report per request (0 = server maximum)
47+
* @param bool $autoPopulateTimespan (Optional) Automatically limit scan to new content only
4648
*/
4749

4850
function create_trigger(
@@ -52,7 +54,8 @@ function create_trigger(
5254
$displayName = '',
5355
$description = '',
5456
$scanPeriod = 1,
55-
$maxFindings = 0
57+
$maxFindings = 0,
58+
$autoPopulateTimespan = false
5659
) {
5760
// Instantiate a client.
5861
$dlp = new DlpServiceClient();
@@ -95,8 +98,13 @@ function create_trigger(
9598
$storageOptions = (new CloudStorageOptions())
9699
->setFileSet($fileSet);
97100

101+
// Auto-populate start and end times in order to scan new objects only.
102+
$timespanConfig = (new StorageConfig_TimespanConfig())
103+
->setEnableAutoPopulationOfTimespanConfig($autoPopulateTimespan);
104+
98105
$storageConfig = (new StorageConfig())
99-
->setCloudStorageOptions($storageOptions);
106+
->setCloudStorageOptions($storageOptions)
107+
->setTimespanConfig($timespanConfig);
100108

101109
// Construct the jobConfig object
102110
$jobConfig = (new InspectJobConfig())

dlp/src/list_inspect_templates.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ function list_inspect_templates($callingProjectId)
4545
printf(' Description: %s' . PHP_EOL, $template->getDescription());
4646

4747
$inspectConfig = $template->getInspectConfig();
48-
printf(' Minimum likelihood: %s' . PHP_EOL, $inspectConfig->getMinLikelihood());
49-
printf(' Include quotes: %s' . PHP_EOL, $inspectConfig->getIncludeQuote());
50-
51-
$limits = $inspectConfig->getLimits();
52-
printf(' Max findings per request: %s' . PHP_EOL, $limits->getMaxFindingsPerRequest());
48+
if ($inspectConfig === null) {
49+
print(' No inspect config.' . PHP_EOL);
50+
} else {
51+
printf(' Minimum likelihood: %s' . PHP_EOL, $inspectConfig->getMinLikelihood());
52+
printf(' Include quotes: %s' . PHP_EOL, $inspectConfig->getIncludeQuote());
53+
$limits = $inspectConfig->getLimits();
54+
printf(' Max findings per request: %s' . PHP_EOL, $limits->getMaxFindingsPerRequest());
55+
}
5356
}
5457
}
5558
// [END dlp_list_inspect_templates]

dlp/src/list_triggers.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ function list_triggers($callingProjectId)
4444
printf(' Description: %s' . PHP_EOL, $trigger->getDescription());
4545
printf(' Status: %s' . PHP_EOL, $trigger->getStatus());
4646
printf(' Error count: %s' . PHP_EOL, count($trigger->getErrors()));
47+
printf(' Auto-populates timespan config: %s' . PHP_EOL, ($trigger->
48+
getInspectJob()->getStorageConfig()->getTimespanConfig()->
49+
getEnableAutoPopulationOfTimespanConfig() ? 'yes' : 'no'));
4750
}
4851
}
4952
# [END dlp_list_triggers]

dlp/test/data/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Test outputs
2+
*.output.*
3+

dlp/test/dlpTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,16 @@ public function testTriggers()
236236
'display-name' => $displayName,
237237
'description' => $description,
238238
'trigger-id' => $triggerId,
239-
'frequency' => 1
239+
'frequency' => 1,
240+
'auto-populate-timespan' => true,
240241
]);
241242
$this->assertContains('Successfully created trigger ' . $triggerId, $output);
242243

243244
$output = $this->runCommand('list-triggers', []);
244245
$this->assertContains('Trigger ' . $fullTriggerId, $output);
245246
$this->assertContains('Display Name: ' . $displayName, $output);
246247
$this->assertContains('Description: ' . $description, $output);
248+
$this->assertContains('Auto-populates timespan config: yes', $output);
247249

248250
$output = $this->runCommand('delete-trigger', [
249251
'trigger-id' => $fullTriggerId

0 commit comments

Comments
 (0)