Skip to content

Commit a0eea3b

Browse files
authored
Merge branch 'main' into renovate/grpcio-1.x
2 parents 940f261 + fa5a949 commit a0eea3b

File tree

11 files changed

+81
-9
lines changed

11 files changed

+81
-9
lines changed

automl/beta/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google-cloud-automl==2.9.0
1+
google-cloud-automl==2.11.1

automl/snippets/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
google-cloud-translate==3.8.4
22
google-cloud-storage==2.8.0
3-
google-cloud-automl==2.9.0
3+
google-cloud-automl==2.11.1

automl/tables/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google-cloud-automl==2.9.0
1+
google-cloud-automl==2.11.1

batch/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
google-cloud-batch==0.5.0
1+
google-cloud-batch==0.10.0
22
google-cloud-logging==3.5.0

cloud-sql/mysql/sqlalchemy/connect_connector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def connect_with_connector() -> sqlalchemy.engine.base.Engine:
3333
# keep secrets safe.
3434

3535
instance_connection_name = os.environ["INSTANCE_CONNECTION_NAME"] # e.g. 'project:region:instance'
36-
db_user = os.environ.get("DB_USER", "") # e.g. 'my-db-user'
36+
db_user = os.environ["DB_USER"] # e.g. 'my-db-user'
3737
db_pass = os.environ["DB_PASS"] # e.g. 'my-db-password'
3838
db_name = os.environ["DB_NAME"] # e.g. 'my-database'
3939

dlp/snippets/redact.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,52 @@ def redact_image_listed_info_types(
277277
# [END dlp_redact_image_listed_infotypes]
278278

279279

280+
# [START dlp_redact_image_all_infotypes]
281+
def redact_image_all_info_types(
282+
project,
283+
filename,
284+
output_filename,
285+
):
286+
"""Uses the Data Loss Prevention API to redact protected data in an image.
287+
Args:
288+
project: The Google Cloud project id to use as a parent resource.
289+
filename: The path to the file to inspect.
290+
output_filename: The path to which the redacted image will be written.
291+
A full list of info type categories can be fetched from the API.
292+
Returns:
293+
None; the response from the API is printed to the terminal.
294+
"""
295+
296+
# Import the client library
297+
import google.cloud.dlp
298+
299+
# Instantiate a client.
300+
dlp = google.cloud.dlp_v2.DlpServiceClient()
301+
302+
# Construct the byte_item, containing the file's byte data.
303+
with open(filename, mode="rb") as f:
304+
byte_item = {"type_": google.cloud.dlp_v2.FileType.IMAGE, "data": f.read()}
305+
306+
# Convert the project id into a full resource id.
307+
parent = f"projects/{project}"
308+
309+
# Call the API.
310+
response = dlp.redact_image(
311+
request={
312+
"parent": parent,
313+
"byte_item": byte_item,
314+
}
315+
)
316+
317+
# Write out the results.
318+
with open(output_filename, mode="wb") as f:
319+
f.write(response.redacted_image)
320+
print(f"Wrote {len(response.redacted_image)} to {output_filename}")
321+
322+
323+
# [END dlp_redact_image_all_infotypes]
324+
325+
280326
if __name__ == "__main__":
281327
default_project = os.environ.get("GOOGLE_CLOUD_PROJECT")
282328

@@ -364,6 +410,12 @@ def redact_image_listed_info_types(
364410
default=None,
365411
)
366412

413+
all_info_types_parser = subparsers.add_parser(
414+
"all_info_types",
415+
help="Redact all infoTypes from an image.",
416+
parents=[common_args_parser],
417+
)
418+
367419
args = parser.parse_args()
368420

369421
if args.content == "info_types":
@@ -390,3 +442,9 @@ def redact_image_listed_info_types(
390442
min_likelihood=args.min_likelihood,
391443
mime_type=args.mime_type,
392444
)
445+
elif args.content == "all_info_types":
446+
redact_image_all_info_types(
447+
args.project,
448+
args.filename,
449+
args.output_filename,
450+
)

dlp/snippets/redact_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,17 @@ def test_redact_image_listed_info_types(tempdir, capsys):
7373

7474
out, _ = capsys.readouterr()
7575
assert output_filepath in out
76+
77+
78+
def test_redact_image_all_info_types(tempdir, capsys):
79+
test_filepath = os.path.join(RESOURCE_DIRECTORY, "test.png")
80+
output_filepath = os.path.join(tempdir, "redacted.png")
81+
82+
redact.redact_image_all_info_types(
83+
GCLOUD_PROJECT,
84+
test_filepath,
85+
output_filepath,
86+
)
87+
88+
out, _ = capsys.readouterr()
89+
assert output_filepath in out
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
google==3.0.0
2-
google-cloud-retail==1.16.0
2+
google-cloud-retail==1.16.1
33
google-cloud-storage==2.8.0
44
google-cloud-bigquery==3.5.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
google==3.0.0
2-
google-cloud-retail==1.16.0
2+
google-cloud-retail==1.16.1
33
google-cloud-storage==2.8.0
44
google-cloud-bigquery==3.5.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
google==3.0.0
2-
google-cloud-retail==1.16.0
2+
google-cloud-retail==1.16.1
33
google-cloud-storage==2.8.0
44
google-cloud-bigquery==3.5.0

0 commit comments

Comments
 (0)