Skip to content

Commit

Permalink
Add a link to the info types docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmoo committed Jun 5, 2020
1 parent 81d2287 commit 66e8b42
Showing 1 changed file with 39 additions and 37 deletions.
76 changes: 39 additions & 37 deletions dlp/custom_infotype.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def omit_name_if_also_email(
project,
content_string,
):
"""Marches PERSON_NAME and EMAIL_ADDRESS, but not both.
"""Marches PERSON_NAME and EMAIL_ADDRESS, but not both.
Uses the Data Loss Prevention API omit matches on PERSON_NAME if the
EMAIL_ADDRESS detector also matches.
Expand All @@ -35,49 +35,51 @@ def omit_name_if_also_email(
None; the response from the API is printed to the terminal.
"""

# Import the client library.
import google.cloud.dlp
# Import the client library.
import google.cloud.dlp

# Instantiate a client.
dlp = google.cloud.dlp_v2.DlpServiceClient()
# Instantiate a client.
dlp = google.cloud.dlp_v2.DlpServiceClient()

# Construct a list of infoTypes for DLP to locate in `content_string`
info_types_to_locate = [{"name": "PERSON_NAME"}, {"name": "EMAIL_ADDRESS"}]
# Construct a list of infoTypes for DLP to locate in `content_string`. See
# https://cloud.google.com/dlp/docs/concepts-infotypes for more information
# about supported infoTypes.
info_types_to_locate = [{"name": "PERSON_NAME"}, {"name": "EMAIL_ADDRESS"}]

# Construct the configuration dictionary that will only match on PERSON_NAME
# if the EMAIL_ADDRESS doesn't also match. This configuration helps reduce
# the total number of findings when there is a large overlap between different
# infoTypes.
inspect_config = {
"info_types":
info_types_to_locate,
"rule_set": [{
"info_types": [{
"name": "PERSON_NAME"
}],
"rules": [{
"exclusion_rule": {
"exclude_info_types": {
"info_types": [{
"name": "EMAIL_ADDRESS"
}]
},
"matching_type": "MATCHING_TYPE_PARTIAL_MATCH"
}
}]
}]
}
# Construct the configuration dictionary that will only match on PERSON_NAME
# if the EMAIL_ADDRESS doesn't also match. This configuration helps reduce
# the total number of findings when there is a large overlap between different
# infoTypes.
inspect_config = {
"info_types":
info_types_to_locate,
"rule_set": [{
"info_types": [{
"name": "PERSON_NAME"
}],
"rules": [{
"exclusion_rule": {
"exclude_info_types": {
"info_types": [{
"name": "EMAIL_ADDRESS"
}]
},
"matching_type": "MATCHING_TYPE_PARTIAL_MATCH"
}
}]
}]
}

# Construct the `item`.
item = {"value": content_string}
# Construct the `item`.
item = {"value": content_string}

# Convert the project id into a full resource id.
parent = dlp.project_path(project)
# Convert the project id into a full resource id.
parent = dlp.project_path(project)

# Call the API.
response = dlp.inspect_content(parent, inspect_config, item)
# Call the API.
response = dlp.inspect_content(parent, inspect_config, item)

return [f.info_type.name for f in response.result.findings]
return [f.info_type.name for f in response.result.findings]


# [END dlp_omit_name_if_also_email]

0 comments on commit 66e8b42

Please sign in to comment.