diff --git a/dlp/README.rst b/dlp/README.rst index 9ef0fc3fa147..6fcaf09887b8 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,redact} ... + 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 Redact 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 24ec6913eb36..d6afea08b430 100644 --- a/dlp/deid.py +++ b/dlp/deid.py @@ -500,13 +500,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_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. 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: @@ -552,7 +552,7 @@ def redact_sensitive_data(project, item, info_types): print(response.item.value) -# [END dlp_redact_sensitive_data] +# [END dlp_deidentify_replace_infotype] if __name__ == "__main__": @@ -768,12 +768,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_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." ) - redact_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 " @@ -782,13 +782,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_with_infotype_parser.add_argument( "project", help="The Google Cloud project id to use as a parent resource.", ) - redact_parser.add_argument( + replace_with_infotype_parser.add_argument( "item", - help="The string to redact." + help="The string to deidentify." "Example: 'My credit card is 4242 4242 4242 4242'", ) @@ -840,8 +840,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_with_infotype": + 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 3b0f4dd5b0e9..0a2c53829613 100644 --- a/dlp/deid_test.py +++ b/dlp/deid_test.py @@ -197,9 +197,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"],