Skip to content

Commit

Permalink
use parent with the global location specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Takashi Matsuo committed Jun 3, 2020
1 parent 26d4b4b commit e0ee53d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 62 deletions.
39 changes: 15 additions & 24 deletions dlp/inspect_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,12 @@ def inspect_gcs_file(
url = "gs://{}/{}".format(bucket, filename)
storage_config = {"cloud_storage_options": {"file_set": {"url": url}}}

# Convert the project id into a full resource id.
parent = dlp.project_path(project)
# Convert the project id into full resource ids.
topic = google.cloud.pubsub.PublisherClient.topic_path(project, topic_id)
parent = dlp.location_path(project, 'global')

# Tell the API where to send a notification when the job is complete.
actions = [{"pub_sub": {"topic": "{}/topics/{}".format(parent, topic_id)}}]
actions = [{"pub_sub": {"topic": topic}}]

# Construct the inspect_job, which defines the entire inspect content task.
inspect_job = {
Expand All @@ -486,11 +487,7 @@ def inspect_gcs_file(

def callback(message):
try:
# The DlpJobName in the Pub/Sub message has the location indicator
# and we need to remove that part for comparison.
dlp_job_name = message.attributes["DlpJobName"].replace(
'/locations/global', '')
if dlp_job_name == operation.name:
if message.attributes["DlpJobName"] == operation.name:
# This is the message we're looking for, so acknowledge it.
message.ack()

Expand Down Expand Up @@ -627,11 +624,12 @@ def inspect_datastore(
}
}

# Convert the project id into a full resource id.
parent = dlp.project_path(project)
# Convert the project id into full resource ids.
topic = google.cloud.pubsub.PublisherClient.topic_path(project, topic_id)
parent = dlp.location_path(project, 'global')

# Tell the API where to send a notification when the job is complete.
actions = [{"pub_sub": {"topic": "{}/topics/{}".format(parent, topic_id)}}]
actions = [{"pub_sub": {"topic": topic}}]

# Construct the inspect_job, which defines the entire inspect content task.
inspect_job = {
Expand All @@ -654,11 +652,7 @@ def inspect_datastore(

def callback(message):
try:
# The DlpJobName in the Pub/Sub message has the location indicator
# and we need to remove that part for comparison.
dlp_job_name = message.attributes["DlpJobName"].replace(
'/locations/global', '')
if dlp_job_name == operation.name:
if message.attributes["DlpJobName"] == operation.name:
# This is the message we're looking for, so acknowledge it.
message.ack()

Expand Down Expand Up @@ -798,11 +792,12 @@ def inspect_bigquery(
}
}

# Convert the project id into a full resource id.
parent = dlp.project_path(project)
# Convert the project id into full resource ids.
topic = google.cloud.pubsub.PublisherClient.topic_path(project, topic_id)
parent = dlp.location_path(project, 'global')

# Tell the API where to send a notification when the job is complete.
actions = [{"pub_sub": {"topic": "{}/topics/{}".format(parent, topic_id)}}]
actions = [{"pub_sub": {"topic": topic}}]

# Construct the inspect_job, which defines the entire inspect content task.
inspect_job = {
Expand All @@ -825,11 +820,7 @@ def inspect_bigquery(

def callback(message):
try:
# The DlpJobName in the Pub/Sub message has the location indicator
# and we need to remove that part for comparison.
dlp_job_name = message.attributes["DlpJobName"].replace(
'/locations/global', '')
if dlp_job_name == operation.name:
if message.attributes["DlpJobName"] == operation.name:
# This is the message we're looking for, so acknowledge it.
message.ack()

Expand Down
61 changes: 23 additions & 38 deletions dlp/risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ def numerical_risk_analysis(
# Instantiate a client.
dlp = google.cloud.dlp_v2.DlpServiceClient()

# Convert the project id into a full resource id.
parent = dlp.project_path(project)
# Convert the project id into full resource ids.
topic = google.cloud.pubsub.PublisherClient.topic_path(project, topic_id)
parent = dlp.location_path(project, 'global')

# Location info of the BigQuery table.
source_table = {
Expand All @@ -70,7 +71,7 @@ def numerical_risk_analysis(
}

# Tell the API where to send a notification when the job is complete.
actions = [{"pub_sub": {"topic": "{}/topics/{}".format(parent, topic_id)}}]
actions = [{"pub_sub": {"topic": topic}}]

# Configure risk analysis job
# Give the name of the numeric column to compute risk metrics for
Expand All @@ -86,11 +87,7 @@ def numerical_risk_analysis(
operation = dlp.create_dlp_job(parent, risk_job=risk_job)

def callback(message):
# The DlpJobName in the Pub/Sub message has the location indicator
# and we need to remove that part for comparison.
dlp_job_name = message.attributes["DlpJobName"].replace(
'/locations/global', '')
if dlp_job_name == operation.name:
if message.attributes["DlpJobName"] == operation.name:
# This is the message we're looking for, so acknowledge it.
message.ack()

Expand Down Expand Up @@ -173,8 +170,9 @@ def categorical_risk_analysis(
# Instantiate a client.
dlp = google.cloud.dlp_v2.DlpServiceClient()

# Convert the project id into a full resource id.
parent = dlp.project_path(project)
# Convert the project id into full resource ids.
topic = google.cloud.pubsub.PublisherClient.topic_path(project, topic_id)
parent = dlp.location_path(project, 'global')

# Location info of the BigQuery table.
source_table = {
Expand All @@ -184,7 +182,7 @@ def categorical_risk_analysis(
}

# Tell the API where to send a notification when the job is complete.
actions = [{"pub_sub": {"topic": "{}/topics/{}".format(parent, topic_id)}}]
actions = [{"pub_sub": {"topic": topic}}]

# Configure risk analysis job
# Give the name of the numeric column to compute risk metrics for
Expand All @@ -200,11 +198,7 @@ def categorical_risk_analysis(
operation = dlp.create_dlp_job(parent, risk_job=risk_job)

def callback(message):
# The DlpJobName in the Pub/Sub message has the location indicator
# and we need to remove that part for comparison.
dlp_job_name = message.attributes["DlpJobName"].replace(
'/locations/global', '')
if dlp_job_name == operation.name:
if message.attributes["DlpJobName"] == operation.name:
# This is the message we're looking for, so acknowledge it.
message.ack()

Expand Down Expand Up @@ -302,7 +296,8 @@ def get_values(obj):
dlp = google.cloud.dlp_v2.DlpServiceClient()

# Convert the project id into a full resource id.
parent = dlp.project_path(project)
topic = google.cloud.pubsub.PublisherClient.topic_path(project, topic_id)
parent = dlp.location_path(project, 'global')

# Location info of the BigQuery table.
source_table = {
Expand All @@ -318,7 +313,7 @@ def map_fields(field):
quasi_ids = map(map_fields, quasi_ids)

# Tell the API where to send a notification when the job is complete.
actions = [{"pub_sub": {"topic": "{}/topics/{}".format(parent, topic_id)}}]
actions = [{"pub_sub": {"topic": topic}}]

# Configure risk analysis job
# Give the name of the numeric column to compute risk metrics for
Expand All @@ -332,11 +327,7 @@ def map_fields(field):
operation = dlp.create_dlp_job(parent, risk_job=risk_job)

def callback(message):
# The DlpJobName in the Pub/Sub message has the location indicator
# and we need to remove that part for comparison.
dlp_job_name = message.attributes["DlpJobName"].replace(
'/locations/global', '')
if dlp_job_name == operation.name:
if message.attributes["DlpJobName"] == operation.name:
# This is the message we're looking for, so acknowledge it.
message.ack()

Expand Down Expand Up @@ -437,7 +428,8 @@ def get_values(obj):
dlp = google.cloud.dlp_v2.DlpServiceClient()

# Convert the project id into a full resource id.
parent = dlp.project_path(project)
topic = google.cloud.pubsub.PublisherClient.topic_path(project, topic_id)
parent = dlp.location_path(project, 'global')

# Location info of the BigQuery table.
source_table = {
Expand All @@ -453,7 +445,7 @@ def map_fields(field):
quasi_ids = map(map_fields, quasi_ids)

# Tell the API where to send a notification when the job is complete.
actions = [{"pub_sub": {"topic": "{}/topics/{}".format(parent, topic_id)}}]
actions = [{"pub_sub": {"topic": topic}}]

# Configure risk analysis job
# Give the name of the numeric column to compute risk metrics for
Expand All @@ -472,11 +464,7 @@ def map_fields(field):
operation = dlp.create_dlp_job(parent, risk_job=risk_job)

def callback(message):
# The DlpJobName in the Pub/Sub message has the location indicator
# and we need to remove that part for comparison.
dlp_job_name = message.attributes["DlpJobName"].replace(
'/locations/global', '')
if dlp_job_name == operation.name:
if message.attributes["DlpJobName"] == operation.name:
# This is the message we're looking for, so acknowledge it.
message.ack()

Expand Down Expand Up @@ -590,8 +578,9 @@ def get_values(obj):
# Instantiate a client.
dlp = google.cloud.dlp_v2.DlpServiceClient()

# Convert the project id into a full resource id.
parent = dlp.project_path(project)
# Convert the project id into full resource ids.
topic = google.cloud.pubsub.PublisherClient.topic_path(project, topic_id)
parent = dlp.location_path(project, 'global')

# Location info of the BigQuery table.
source_table = {
Expand All @@ -614,7 +603,7 @@ def map_fields(quasi_id, info_type):
quasi_ids = map(map_fields, quasi_ids, info_types)

# Tell the API where to send a notification when the job is complete.
actions = [{"pub_sub": {"topic": "{}/topics/{}".format(parent, topic_id)}}]
actions = [{"pub_sub": {"topic": topic}}]

# Configure risk analysis job
# Give the name of the numeric column to compute risk metrics for
Expand All @@ -633,11 +622,7 @@ def map_fields(quasi_id, info_type):
operation = dlp.create_dlp_job(parent, risk_job=risk_job)

def callback(message):
# The DlpJobName in the Pub/Sub message has the location indicator
# and we need to remove that part for comparison.
dlp_job_name = message.attributes["DlpJobName"].replace(
'/locations/global', '')
if dlp_job_name == operation.name:
if message.attributes["DlpJobName"] == operation.name:
# This is the message we're looking for, so acknowledge it.
message.ack()

Expand Down

0 comments on commit e0ee53d

Please sign in to comment.