From 66e8b424523c2c94d5d9dc0f429a8b7a59206024 Mon Sep 17 00:00:00 2001 From: Seth Moore Date: Fri, 5 Jun 2020 16:43:13 -0700 Subject: [PATCH] Add a link to the info types docs --- dlp/custom_infotype.py | 76 ++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/dlp/custom_infotype.py b/dlp/custom_infotype.py index 24c1ae276465..d1cc921a1dd8 100644 --- a/dlp/custom_infotype.py +++ b/dlp/custom_infotype.py @@ -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. @@ -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]