Skip to content

Commit 57ed247

Browse files
micheldavidandrewsg
authored andcommitted
DLP: Add auto_populate_timespan option for create job trigger. (#1543)
1 parent 89b498f commit 57ed247

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

dlp/triggers.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
# [START dlp_create_trigger]
2525
def create_trigger(project, bucket, scan_period_days, info_types,
2626
trigger_id=None, display_name=None, description=None,
27-
min_likelihood=None, max_findings=None):
27+
min_likelihood=None, max_findings=None,
28+
auto_populate_timespan=False):
2829
"""Creates a scheduled Data Loss Prevention API inspect_content trigger.
2930
Args:
3031
project: The Google Cloud project id to use as a parent resource.
@@ -42,6 +43,8 @@ def create_trigger(project, bucket, scan_period_days, info_types,
4243
that constitutes a match. One of: 'LIKELIHOOD_UNSPECIFIED',
4344
'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', 'LIKELY', 'VERY_LIKELY'.
4445
max_findings: The maximum number of findings to report; 0 = no maximum.
46+
auto_populate_timespan: Automatically populates time span config start
47+
and end times in order to scan new content only.
4548
Returns:
4649
None; the response from the API is printed to the terminal.
4750
"""
@@ -69,7 +72,13 @@ def create_trigger(project, bucket, scan_period_days, info_types,
6972
storage_config = {
7073
'cloud_storage_options': {
7174
'file_set': {'url': url}
72-
}
75+
},
76+
# Time-based configuration for each storage object.
77+
'timespan_config': {
78+
# Auto-populate start and end times in order to scan new objects
79+
# only.
80+
'enable_auto_population_of_timespan_config': auto_populate_timespan
81+
},
7382
}
7483

7584
# Construct the job definition.
@@ -222,6 +231,9 @@ def delete_trigger(project, trigger_id):
222231
parser_create.add_argument(
223232
'--max_findings', type=int,
224233
help='The maximum number of findings to report; 0 = no maximum.')
234+
parser_create.add_argument(
235+
'--auto_populate_timespan', type=bool,
236+
help='Limit scan to new content only.')
225237

226238
parser_list = subparsers.add_parser('list', help='List all triggers.')
227239
parser_list.add_argument(
@@ -246,6 +258,7 @@ def delete_trigger(project, trigger_id):
246258
trigger_id=args.trigger_id, display_name=args.display_name,
247259
description=args.description, min_likelihood=args.min_likelihood,
248260
max_findings=args.max_findings,
261+
auto_populate_timespan=args.auto_populate_timespan,
249262
)
250263
elif args.action == 'list':
251264
list_triggers(args.project)

dlp/triggers_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def test_create_list_and_delete_trigger(bucket, capsys):
7878
GCLOUD_PROJECT, bucket.name, 7,
7979
['FIRST_NAME', 'EMAIL_ADDRESS', 'PHONE_NUMBER'],
8080
trigger_id=TEST_TRIGGER_ID,
81+
auto_populate_timespan=True,
8182
)
8283

8384
out, _ = capsys.readouterr()

0 commit comments

Comments
 (0)