@@ -59,8 +59,9 @@ def numerical_risk_analysis(
59
59
# Instantiate a client.
60
60
dlp = google .cloud .dlp_v2 .DlpServiceClient ()
61
61
62
- # Convert the project id into a full resource id.
63
- parent = dlp .project_path (project )
62
+ # Convert the project id into full resource ids.
63
+ topic = google .cloud .pubsub .PublisherClient .topic_path (project , topic_id )
64
+ parent = dlp .location_path (project , 'global' )
64
65
65
66
# Location info of the BigQuery table.
66
67
source_table = {
@@ -70,7 +71,7 @@ def numerical_risk_analysis(
70
71
}
71
72
72
73
# Tell the API where to send a notification when the job is complete.
73
- actions = [{"pub_sub" : {"topic" : "{}/topics/{}" . format ( parent , topic_id ) }}]
74
+ actions = [{"pub_sub" : {"topic" : topic }}]
74
75
75
76
# Configure risk analysis job
76
77
# Give the name of the numeric column to compute risk metrics for
@@ -86,11 +87,7 @@ def numerical_risk_analysis(
86
87
operation = dlp .create_dlp_job (parent , risk_job = risk_job )
87
88
88
89
def callback (message ):
89
- # The DlpJobName in the Pub/Sub message has the location indicator
90
- # and we need to remove that part for comparison.
91
- dlp_job_name = message .attributes ["DlpJobName" ].replace (
92
- '/locations/global' , '' )
93
- if dlp_job_name == operation .name :
90
+ if message .attributes ["DlpJobName" ] == operation .name :
94
91
# This is the message we're looking for, so acknowledge it.
95
92
message .ack ()
96
93
@@ -173,8 +170,9 @@ def categorical_risk_analysis(
173
170
# Instantiate a client.
174
171
dlp = google .cloud .dlp_v2 .DlpServiceClient ()
175
172
176
- # Convert the project id into a full resource id.
177
- parent = dlp .project_path (project )
173
+ # Convert the project id into full resource ids.
174
+ topic = google .cloud .pubsub .PublisherClient .topic_path (project , topic_id )
175
+ parent = dlp .location_path (project , 'global' )
178
176
179
177
# Location info of the BigQuery table.
180
178
source_table = {
@@ -184,7 +182,7 @@ def categorical_risk_analysis(
184
182
}
185
183
186
184
# Tell the API where to send a notification when the job is complete.
187
- actions = [{"pub_sub" : {"topic" : "{}/topics/{}" . format ( parent , topic_id ) }}]
185
+ actions = [{"pub_sub" : {"topic" : topic }}]
188
186
189
187
# Configure risk analysis job
190
188
# Give the name of the numeric column to compute risk metrics for
@@ -200,11 +198,7 @@ def categorical_risk_analysis(
200
198
operation = dlp .create_dlp_job (parent , risk_job = risk_job )
201
199
202
200
def callback (message ):
203
- # The DlpJobName in the Pub/Sub message has the location indicator
204
- # and we need to remove that part for comparison.
205
- dlp_job_name = message .attributes ["DlpJobName" ].replace (
206
- '/locations/global' , '' )
207
- if dlp_job_name == operation .name :
201
+ if message .attributes ["DlpJobName" ] == operation .name :
208
202
# This is the message we're looking for, so acknowledge it.
209
203
message .ack ()
210
204
@@ -302,7 +296,8 @@ def get_values(obj):
302
296
dlp = google .cloud .dlp_v2 .DlpServiceClient ()
303
297
304
298
# Convert the project id into a full resource id.
305
- parent = dlp .project_path (project )
299
+ topic = google .cloud .pubsub .PublisherClient .topic_path (project , topic_id )
300
+ parent = dlp .location_path (project , 'global' )
306
301
307
302
# Location info of the BigQuery table.
308
303
source_table = {
@@ -318,7 +313,7 @@ def map_fields(field):
318
313
quasi_ids = map (map_fields , quasi_ids )
319
314
320
315
# Tell the API where to send a notification when the job is complete.
321
- actions = [{"pub_sub" : {"topic" : "{}/topics/{}" . format ( parent , topic_id ) }}]
316
+ actions = [{"pub_sub" : {"topic" : topic }}]
322
317
323
318
# Configure risk analysis job
324
319
# Give the name of the numeric column to compute risk metrics for
@@ -332,11 +327,7 @@ def map_fields(field):
332
327
operation = dlp .create_dlp_job (parent , risk_job = risk_job )
333
328
334
329
def callback (message ):
335
- # The DlpJobName in the Pub/Sub message has the location indicator
336
- # and we need to remove that part for comparison.
337
- dlp_job_name = message .attributes ["DlpJobName" ].replace (
338
- '/locations/global' , '' )
339
- if dlp_job_name == operation .name :
330
+ if message .attributes ["DlpJobName" ] == operation .name :
340
331
# This is the message we're looking for, so acknowledge it.
341
332
message .ack ()
342
333
@@ -437,7 +428,8 @@ def get_values(obj):
437
428
dlp = google .cloud .dlp_v2 .DlpServiceClient ()
438
429
439
430
# Convert the project id into a full resource id.
440
- parent = dlp .project_path (project )
431
+ topic = google .cloud .pubsub .PublisherClient .topic_path (project , topic_id )
432
+ parent = dlp .location_path (project , 'global' )
441
433
442
434
# Location info of the BigQuery table.
443
435
source_table = {
@@ -453,7 +445,7 @@ def map_fields(field):
453
445
quasi_ids = map (map_fields , quasi_ids )
454
446
455
447
# Tell the API where to send a notification when the job is complete.
456
- actions = [{"pub_sub" : {"topic" : "{}/topics/{}" . format ( parent , topic_id ) }}]
448
+ actions = [{"pub_sub" : {"topic" : topic }}]
457
449
458
450
# Configure risk analysis job
459
451
# Give the name of the numeric column to compute risk metrics for
@@ -472,11 +464,7 @@ def map_fields(field):
472
464
operation = dlp .create_dlp_job (parent , risk_job = risk_job )
473
465
474
466
def callback (message ):
475
- # The DlpJobName in the Pub/Sub message has the location indicator
476
- # and we need to remove that part for comparison.
477
- dlp_job_name = message .attributes ["DlpJobName" ].replace (
478
- '/locations/global' , '' )
479
- if dlp_job_name == operation .name :
467
+ if message .attributes ["DlpJobName" ] == operation .name :
480
468
# This is the message we're looking for, so acknowledge it.
481
469
message .ack ()
482
470
@@ -590,8 +578,9 @@ def get_values(obj):
590
578
# Instantiate a client.
591
579
dlp = google .cloud .dlp_v2 .DlpServiceClient ()
592
580
593
- # Convert the project id into a full resource id.
594
- parent = dlp .project_path (project )
581
+ # Convert the project id into full resource ids.
582
+ topic = google .cloud .pubsub .PublisherClient .topic_path (project , topic_id )
583
+ parent = dlp .location_path (project , 'global' )
595
584
596
585
# Location info of the BigQuery table.
597
586
source_table = {
@@ -614,7 +603,7 @@ def map_fields(quasi_id, info_type):
614
603
quasi_ids = map (map_fields , quasi_ids , info_types )
615
604
616
605
# Tell the API where to send a notification when the job is complete.
617
- actions = [{"pub_sub" : {"topic" : "{}/topics/{}" . format ( parent , topic_id ) }}]
606
+ actions = [{"pub_sub" : {"topic" : topic }}]
618
607
619
608
# Configure risk analysis job
620
609
# Give the name of the numeric column to compute risk metrics for
@@ -633,11 +622,7 @@ def map_fields(quasi_id, info_type):
633
622
operation = dlp .create_dlp_job (parent , risk_job = risk_job )
634
623
635
624
def callback (message ):
636
- # The DlpJobName in the Pub/Sub message has the location indicator
637
- # and we need to remove that part for comparison.
638
- dlp_job_name = message .attributes ["DlpJobName" ].replace (
639
- '/locations/global' , '' )
640
- if dlp_job_name == operation .name :
625
+ if message .attributes ["DlpJobName" ] == operation .name :
641
626
# This is the message we're looking for, so acknowledge it.
642
627
message .ack ()
643
628
0 commit comments