Skip to content

Commit 21a25b9

Browse files
authored
Rename DLP code samples from 'redact' to 'replace' (#4020)
In the DLP API, redaction and replacement are two separate, named concepts. Code samples recently added by #3964 were named 'redact' but are actually examples of replacement. This change renames those samples for clarity.
1 parent a365fad commit 21a25b9

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

dlp/README.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -339,26 +339,26 @@ To run this sample:
339339
.. code-block:: bash
340340
341341
$ python deid.py
342-
usage: deid.py [-h] {deid_mask,deid_fpe,reid_fpe,deid_date_shift,redact} ...
342+
usage: deid.py [-h] {deid_mask,deid_fpe,reid_fpe,deid_date_shift,replace_with_infotype} ...
343343
344344
Uses of the Data Loss Prevention API for deidentifying sensitive data.
345345
346346
positional arguments:
347347
{deid_mask,deid_fpe,reid_fpe,deid_date_shift,redact}
348-
Select how to submit content to the API.
349-
deid_mask Deidentify sensitive data in a string by masking it
350-
with a character.
351-
deid_fpe Deidentify sensitive data in a string using Format
352-
Preserving Encryption (FPE).
353-
reid_fpe Reidentify sensitive data in a string using Format
354-
Preserving Encryption (FPE).
355-
deid_date_shift Deidentify dates in a CSV file by pseudorandomly
356-
shifting them.
357-
redact Redact sensitive data in a string by replacing it with
358-
the info type of the data.
348+
Select how to submit content to the API.
349+
deid_mask Deidentify sensitive data in a string by masking it
350+
with a character.
351+
deid_fpe Deidentify sensitive data in a string using Format
352+
Preserving Encryption (FPE).
353+
reid_fpe Reidentify sensitive data in a string using Format
354+
Preserving Encryption (FPE).
355+
deid_date_shift Deidentify dates in a CSV file by pseudorandomly
356+
shifting them.
357+
replace_with_infotype Deidentify sensitive data in a string by replacing it with
358+
the info type of the data.
359359
360360
optional arguments:
361-
-h, --help show this help message and exit
361+
-h, --help show this help message and exit
362362
363363
364364

dlp/deid.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -500,13 +500,13 @@ def write_data(data):
500500
# [END dlp_deidentify_date_shift]
501501

502502

503-
# [START dlp_redact_sensitive_data]
504-
def redact_sensitive_data(project, item, info_types):
505-
"""Uses the Data Loss Prevention API to redact sensitive data in a
503+
# [START dlp_deidentify_replace_infotype]
504+
def deidentify_with_replace_infotype(project, item, info_types):
505+
"""Uses the Data Loss Prevention API to deidentify sensitive data in a
506506
string by replacing it with the info type.
507507
Args:
508508
project: The Google Cloud project id to use as a parent resource.
509-
item: The string to redact (will be treated as text).
509+
item: The string to deidentify (will be treated as text).
510510
info_types: A list of strings representing info types to look for.
511511
A full list of info type categories can be fetched from the API.
512512
Returns:
@@ -552,7 +552,7 @@ def redact_sensitive_data(project, item, info_types):
552552
print(response.item.value)
553553

554554

555-
# [END dlp_redact_sensitive_data]
555+
# [END dlp_deidentify_replace_infotype]
556556

557557

558558
if __name__ == "__main__":
@@ -768,12 +768,12 @@ def redact_sensitive_data(project, item, info_types):
768768
"key_name.",
769769
)
770770

771-
redact_parser = subparsers.add_parser(
772-
"redact",
773-
help="Redact sensitive data in a string by replacing it with the "
774-
"info type of the data.",
771+
replace_with_infotype_parser = subparsers.add_parser(
772+
"replace_with_infotype",
773+
help="Deidentify sensitive data in a string by replacing it with the "
774+
"info type of the data."
775775
)
776-
redact_parser.add_argument(
776+
replace_with_infotype_parser.add_argument(
777777
"--info_types",
778778
action="append",
779779
help="Strings representing info types to look for. A full list of "
@@ -782,13 +782,13 @@ def redact_sensitive_data(project, item, info_types):
782782
"If unspecified, the three above examples will be used.",
783783
default=["FIRST_NAME", "LAST_NAME", "EMAIL_ADDRESS"],
784784
)
785-
redact_parser.add_argument(
785+
replace_with_infotype_parser.add_argument(
786786
"project",
787787
help="The Google Cloud project id to use as a parent resource.",
788788
)
789-
redact_parser.add_argument(
789+
replace_with_infotype_parser.add_argument(
790790
"item",
791-
help="The string to redact."
791+
help="The string to deidentify."
792792
"Example: 'My credit card is 4242 4242 4242 4242'",
793793
)
794794

@@ -840,8 +840,8 @@ def redact_sensitive_data(project, item, info_types):
840840
wrapped_key=args.wrapped_key,
841841
key_name=args.key_name,
842842
)
843-
elif args.content == "redact":
844-
redact_sensitive_data(
843+
elif args.content == "replace_with_infotype":
844+
deidentify_with_replace_infotype(
845845
args.project,
846846
item=args.item,
847847
info_types=args.info_types,

dlp/deid_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ def test_reidentify_with_fpe(capsys):
197197
assert "731997681" not in out
198198

199199

200-
def test_redact_sensitive_data(capsys):
200+
def test_deidentify_with_replace_infotype(capsys):
201201
url_to_redact = "https://cloud.google.com"
202-
deid.redact_sensitive_data(
202+
deid.deidentify_with_replace_infotype(
203203
GCLOUD_PROJECT,
204204
"My favorite site is " + url_to_redact,
205205
["URL"],

0 commit comments

Comments
 (0)