Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename DLP code samples from 'redact' to 'replace' #4020

Merged
merged 9 commits into from
Jun 9, 2020
26 changes: 13 additions & 13 deletions dlp/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
30 changes: 15 additions & 15 deletions dlp/deid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_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:
Expand Down Expand Up @@ -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_infotype]


if __name__ == "__main__":
Expand Down Expand Up @@ -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_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 "
Expand All @@ -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_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'",
)

Expand Down Expand Up @@ -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_with_infotype":
deidentify_with_replace_infotype(
args.project,
item=args.item,
info_types=args.info_types,
Expand Down
4 changes: 2 additions & 2 deletions dlp/deid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down