From f5c8d201219f8ae314c00b9bbcfaab5d5af0b86f Mon Sep 17 00:00:00 2001 From: Jessica Date: Tue, 9 Jun 2020 01:21:52 +0000 Subject: [PATCH 1/2] Rename from 'redact' to 'replace' in deid code samples --- dlp/README.rst | 4 ++-- dlp/deid.py | 30 +++++++++++++++--------------- dlp/deid_test.py | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dlp/README.rst b/dlp/README.rst index 9ef0fc3fa14..02c6f63bec6 100644 --- a/dlp/README.rst +++ b/dlp/README.rst @@ -339,7 +339,7 @@ To run this sample: .. code-block:: bash $ python deid.py - usage: deid.py [-h] {deid_mask,deid_fpe,reid_fpe,deid_date_shift,redact} ... + usage: deid.py [-h] {deid_mask,deid_fpe,reid_fpe,deid_date_shift,replace} ... Uses of the Data Loss Prevention API for deidentifying sensitive data. @@ -354,7 +354,7 @@ To run this sample: Preserving Encryption (FPE). deid_date_shift Deidentify dates in a CSV file by pseudorandomly shifting them. - redact Redact sensitive data in a string by replacing it with + redact Deidentify sensitive data in a string by replacing it with the info type of the data. optional arguments: diff --git a/dlp/deid.py b/dlp/deid.py index 81847690866..a4512383390 100644 --- a/dlp/deid.py +++ b/dlp/deid.py @@ -435,13 +435,13 @@ def write_data(data): # [END dlp_deidentify_date_shift] -# [START dlp_redact_sensitive_data] -def redact_sensitive_data(project, item, info_types): - """Uses the Data Loss Prevention API to redact sensitive data in a +# [START dlp_deidentify_replace] +def deidentify_with_replace_infotype(project, item, info_types): + """Uses the Data Loss Prevention API to deidentify sensitive data in a string by replacing it with the info type. Args: project: The Google Cloud project id to use as a parent resource. - item: The string to redact (will be treated as text). + item: The string to deidentify (will be treated as text). info_types: A list of strings representing info types to look for. A full list of info type categories can be fetched from the API. Returns: @@ -487,7 +487,7 @@ def redact_sensitive_data(project, item, info_types): print(response.item.value) -# [END dlp_redact_sensitive_data] +# [END dlp_deidentify_replace] if __name__ == "__main__": @@ -681,12 +681,12 @@ def redact_sensitive_data(project, item, info_types): "key_name.", ) - redact_parser = subparsers.add_parser( - "redact", - help="Redact sensitive data in a string by replacing it with the " - "info type of the data.", + replace_parser = subparsers.add_parser( + "replace", + help="Deidentify sensitive data in a string by replacing it with the " + "info type of the data." ) - redact_parser.add_argument( + replace_parser.add_argument( "--info_types", action="append", help="Strings representing info types to look for. A full list of " @@ -695,13 +695,13 @@ def redact_sensitive_data(project, item, info_types): "If unspecified, the three above examples will be used.", default=["FIRST_NAME", "LAST_NAME", "EMAIL_ADDRESS"], ) - redact_parser.add_argument( + replace_parser.add_argument( "project", help="The Google Cloud project id to use as a parent resource.", ) - redact_parser.add_argument( + replace_parser.add_argument( "item", - help="The string to redact." + help="The string to deidentify." "Example: 'My credit card is 4242 4242 4242 4242'", ) @@ -746,8 +746,8 @@ def redact_sensitive_data(project, item, info_types): wrapped_key=args.wrapped_key, key_name=args.key_name, ) - elif args.content == "redact": - redact_sensitive_data( + elif args.content == "replace": + deidentify_with_replace_infotype( args.project, item=args.item, info_types=args.info_types, diff --git a/dlp/deid_test.py b/dlp/deid_test.py index db0c94e35dd..5780ab88d36 100644 --- a/dlp/deid_test.py +++ b/dlp/deid_test.py @@ -187,9 +187,9 @@ def test_reidentify_with_fpe(capsys): assert "731997681" not in out -def test_redact_sensitive_data(capsys): +def test_deidentify_with_replace_infotype(capsys): url_to_redact = "https://cloud.google.com" - deid.redact_sensitive_data( + deid.deidentify_with_replace_infotype( GCLOUD_PROJECT, "My favorite site is " + url_to_redact, ["URL"], From ea61701a51a99ef35f44db51a158f4f02b99a550 Mon Sep 17 00:00:00 2001 From: Jessica Date: Tue, 9 Jun 2020 01:46:10 +0000 Subject: [PATCH 2/2] More renaming missed in the first pass --- dlp/README.rst | 26 +++++++++++++------------- dlp/deid.py | 16 ++++++++-------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/dlp/README.rst b/dlp/README.rst index 02c6f63bec6..6fcaf09887b 100644 --- a/dlp/README.rst +++ b/dlp/README.rst @@ -339,26 +339,26 @@ To run this sample: .. code-block:: bash $ python deid.py - usage: deid.py [-h] {deid_mask,deid_fpe,reid_fpe,deid_date_shift,replace} ... + usage: deid.py [-h] {deid_mask,deid_fpe,reid_fpe,deid_date_shift,replace_with_infotype} ... Uses of the Data Loss Prevention API for deidentifying sensitive data. positional arguments: {deid_mask,deid_fpe,reid_fpe,deid_date_shift,redact} - Select how to submit content to the API. - deid_mask Deidentify sensitive data in a string by masking it - with a character. - deid_fpe Deidentify sensitive data in a string using Format - Preserving Encryption (FPE). - reid_fpe Reidentify sensitive data in a string using Format - Preserving Encryption (FPE). - deid_date_shift Deidentify dates in a CSV file by pseudorandomly - shifting them. - redact Deidentify sensitive data in a string by replacing it with - the info type of the data. + Select how to submit content to the API. + deid_mask Deidentify sensitive data in a string by masking it + with a character. + deid_fpe Deidentify sensitive data in a string using Format + Preserving Encryption (FPE). + reid_fpe Reidentify sensitive data in a string using Format + Preserving Encryption (FPE). + deid_date_shift Deidentify dates in a CSV file by pseudorandomly + shifting them. + replace_with_infotype Deidentify sensitive data in a string by replacing it with + the info type of the data. optional arguments: - -h, --help show this help message and exit + -h, --help show this help message and exit diff --git a/dlp/deid.py b/dlp/deid.py index a4512383390..537730de08e 100644 --- a/dlp/deid.py +++ b/dlp/deid.py @@ -435,7 +435,7 @@ def write_data(data): # [END dlp_deidentify_date_shift] -# [START dlp_deidentify_replace] +# [START dlp_deidentify_replace_infotype] def deidentify_with_replace_infotype(project, item, info_types): """Uses the Data Loss Prevention API to deidentify sensitive data in a string by replacing it with the info type. @@ -487,7 +487,7 @@ def deidentify_with_replace_infotype(project, item, info_types): print(response.item.value) -# [END dlp_deidentify_replace] +# [END dlp_deidentify_replace_infotype] if __name__ == "__main__": @@ -681,12 +681,12 @@ def deidentify_with_replace_infotype(project, item, info_types): "key_name.", ) - replace_parser = subparsers.add_parser( - "replace", + replace_with_infotype_parser = subparsers.add_parser( + "replace_with_infotype", help="Deidentify sensitive data in a string by replacing it with the " "info type of the data." ) - replace_parser.add_argument( + replace_with_infotype_parser.add_argument( "--info_types", action="append", help="Strings representing info types to look for. A full list of " @@ -695,11 +695,11 @@ def deidentify_with_replace_infotype(project, item, info_types): "If unspecified, the three above examples will be used.", default=["FIRST_NAME", "LAST_NAME", "EMAIL_ADDRESS"], ) - replace_parser.add_argument( + replace_with_infotype_parser.add_argument( "project", help="The Google Cloud project id to use as a parent resource.", ) - replace_parser.add_argument( + replace_with_infotype_parser.add_argument( "item", help="The string to deidentify." "Example: 'My credit card is 4242 4242 4242 4242'", @@ -746,7 +746,7 @@ def deidentify_with_replace_infotype(project, item, info_types): wrapped_key=args.wrapped_key, key_name=args.key_name, ) - elif args.content == "replace": + elif args.content == "replace_with_infotype": deidentify_with_replace_infotype( args.project, item=args.item,