@@ -59,8 +59,9 @@ def numerical_risk_analysis(
5959 # Instantiate a client.
6060 dlp = google .cloud .dlp_v2 .DlpServiceClient ()
6161
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' )
6465
6566 # Location info of the BigQuery table.
6667 source_table = {
@@ -70,7 +71,7 @@ def numerical_risk_analysis(
7071 }
7172
7273 # 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 }}]
7475
7576 # Configure risk analysis job
7677 # Give the name of the numeric column to compute risk metrics for
@@ -86,11 +87,7 @@ def numerical_risk_analysis(
8687 operation = dlp .create_dlp_job (parent , risk_job = risk_job )
8788
8889 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 :
9491 # This is the message we're looking for, so acknowledge it.
9592 message .ack ()
9693
@@ -173,8 +170,9 @@ def categorical_risk_analysis(
173170 # Instantiate a client.
174171 dlp = google .cloud .dlp_v2 .DlpServiceClient ()
175172
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' )
178176
179177 # Location info of the BigQuery table.
180178 source_table = {
@@ -184,7 +182,7 @@ def categorical_risk_analysis(
184182 }
185183
186184 # 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 }}]
188186
189187 # Configure risk analysis job
190188 # Give the name of the numeric column to compute risk metrics for
@@ -200,11 +198,7 @@ def categorical_risk_analysis(
200198 operation = dlp .create_dlp_job (parent , risk_job = risk_job )
201199
202200 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 :
208202 # This is the message we're looking for, so acknowledge it.
209203 message .ack ()
210204
@@ -302,7 +296,8 @@ def get_values(obj):
302296 dlp = google .cloud .dlp_v2 .DlpServiceClient ()
303297
304298 # 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' )
306301
307302 # Location info of the BigQuery table.
308303 source_table = {
@@ -318,7 +313,7 @@ def map_fields(field):
318313 quasi_ids = map (map_fields , quasi_ids )
319314
320315 # 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 }}]
322317
323318 # Configure risk analysis job
324319 # Give the name of the numeric column to compute risk metrics for
@@ -332,11 +327,7 @@ def map_fields(field):
332327 operation = dlp .create_dlp_job (parent , risk_job = risk_job )
333328
334329 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 :
340331 # This is the message we're looking for, so acknowledge it.
341332 message .ack ()
342333
@@ -437,7 +428,8 @@ def get_values(obj):
437428 dlp = google .cloud .dlp_v2 .DlpServiceClient ()
438429
439430 # 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' )
441433
442434 # Location info of the BigQuery table.
443435 source_table = {
@@ -453,7 +445,7 @@ def map_fields(field):
453445 quasi_ids = map (map_fields , quasi_ids )
454446
455447 # 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 }}]
457449
458450 # Configure risk analysis job
459451 # Give the name of the numeric column to compute risk metrics for
@@ -472,11 +464,7 @@ def map_fields(field):
472464 operation = dlp .create_dlp_job (parent , risk_job = risk_job )
473465
474466 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 :
480468 # This is the message we're looking for, so acknowledge it.
481469 message .ack ()
482470
@@ -590,8 +578,9 @@ def get_values(obj):
590578 # Instantiate a client.
591579 dlp = google .cloud .dlp_v2 .DlpServiceClient ()
592580
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' )
595584
596585 # Location info of the BigQuery table.
597586 source_table = {
@@ -614,7 +603,7 @@ def map_fields(quasi_id, info_type):
614603 quasi_ids = map (map_fields , quasi_ids , info_types )
615604
616605 # 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 }}]
618607
619608 # Configure risk analysis job
620609 # Give the name of the numeric column to compute risk metrics for
@@ -633,11 +622,7 @@ def map_fields(quasi_id, info_type):
633622 operation = dlp .create_dlp_job (parent , risk_job = risk_job )
634623
635624 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 :
641626 # This is the message we're looking for, so acknowledge it.
642627 message .ack ()
643628
0 commit comments