Skip to content

Commit 4f68f93

Browse files
partheaohmayrvchudnov-g
authored
chore(librarian): clean up owlbot files and pin image sha (#861)
Additional clean up following #856 --------- Co-authored-by: ohmayr <omairn@google.com> Co-authored-by: Victor Chudnovsky <vchudnov@google.com>
1 parent 628003e commit 4f68f93

File tree

12 files changed

+112
-117
lines changed

12 files changed

+112
-117
lines changed

.github/auto-approve.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.librarian/config.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.librarian/state.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator:latest
1+
image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:c8612d3fffb3f6a32353b2d1abd16b61e87811866f7ec9d65b59b02eb452a620
22
libraries:
33
- id: google-api-core
44
version: 2.28.1

owlbot.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ ignore_missing_imports = true
9191
filterwarnings = [
9292
# treat all warnings as errors
9393
"error",
94+
# Prevent Python version warnings from interfering with tests
95+
"ignore:.* Python version .*:FutureWarning",
9496
# Remove once https://github.com/pytest-dev/pytest-cov/issues/621 is fixed
9597
"ignore:.*The --rsyncdir command line argument and rsyncdirs config variable are deprecated:DeprecationWarning",
9698
# Remove once https://github.com/protocolbuffers/protobuf/issues/12186 is fixed

tests/asyncio/gapic/test_method_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ async def test_wrap_method_with_overriding_timeout_as_a_number():
260260
actual_timeout = method.call_args[1]["timeout"]
261261
metadata = method.call_args[1]["metadata"]
262262
assert metadata == mock.ANY
263-
assert actual_timeout == pytest.approx(22, abs=0.01)
263+
assert actual_timeout == pytest.approx(22, abs=0.05)
264264

265265

266266
@pytest.mark.asyncio

tests/asyncio/test_grpc_helpers_async.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from unittest.mock import AsyncMock # pragma: NO COVER # noqa: F401
1818
except ImportError: # pragma: NO COVER
1919
import mock # type: ignore
20+
from ..helpers import warn_deprecated_credentials_file
2021
import pytest # noqa: I202
2122

2223
try:
@@ -522,11 +523,12 @@ def test_create_channel_explicit_with_duplicate_credentials():
522523
target = "example:443"
523524

524525
with pytest.raises(exceptions.DuplicateCredentialArgs) as excinfo:
525-
grpc_helpers_async.create_channel(
526-
target,
527-
credentials_file="credentials.json",
528-
credentials=mock.sentinel.credentials,
529-
)
526+
with warn_deprecated_credentials_file():
527+
grpc_helpers_async.create_channel(
528+
target,
529+
credentials_file="credentials.json",
530+
credentials=mock.sentinel.credentials,
531+
)
530532

531533
assert "mutually exclusive" in str(excinfo.value)
532534

@@ -641,9 +643,10 @@ def test_create_channel_with_credentials_file(
641643
credentials_file = "/path/to/credentials/file.json"
642644
composite_creds = composite_creds_call.return_value
643645

644-
channel = grpc_helpers_async.create_channel(
645-
target, credentials_file=credentials_file
646-
)
646+
with warn_deprecated_credentials_file():
647+
channel = grpc_helpers_async.create_channel(
648+
target, credentials_file=credentials_file
649+
)
647650

648651
google.auth.load_credentials_from_file.assert_called_once_with(
649652
credentials_file, scopes=None, default_scopes=None
@@ -670,9 +673,10 @@ def test_create_channel_with_credentials_file_and_scopes(
670673
credentials_file = "/path/to/credentials/file.json"
671674
composite_creds = composite_creds_call.return_value
672675

673-
channel = grpc_helpers_async.create_channel(
674-
target, credentials_file=credentials_file, scopes=scopes
675-
)
676+
with warn_deprecated_credentials_file():
677+
channel = grpc_helpers_async.create_channel(
678+
target, credentials_file=credentials_file, scopes=scopes
679+
)
676680

677681
google.auth.load_credentials_from_file.assert_called_once_with(
678682
credentials_file, scopes=scopes, default_scopes=None
@@ -699,9 +703,10 @@ def test_create_channel_with_credentials_file_and_default_scopes(
699703
credentials_file = "/path/to/credentials/file.json"
700704
composite_creds = composite_creds_call.return_value
701705

702-
channel = grpc_helpers_async.create_channel(
703-
target, credentials_file=credentials_file, default_scopes=default_scopes
704-
)
706+
with warn_deprecated_credentials_file():
707+
channel = grpc_helpers_async.create_channel(
708+
target, credentials_file=credentials_file, default_scopes=default_scopes
709+
)
705710

706711
google.auth.load_credentials_from_file.assert_called_once_with(
707712
credentials_file, scopes=None, default_scopes=default_scopes

tests/helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
"""Helpers for tests"""
1616

17+
import functools
1718
import logging
19+
import pytest # noqa: I202
1820
from typing import List
1921

2022
import proto
@@ -69,3 +71,12 @@ def parse_responses(response_message_cls, all_responses: List[proto.Message]) ->
6971
logging.info(f"Sending JSON stream: {json_responses}")
7072
ret_val = "[{}]".format(",".join(json_responses))
7173
return bytes(ret_val, "utf-8")
74+
75+
76+
warn_deprecated_credentials_file = functools.partial(
77+
# This is used to test that the auth credentials file deprecation
78+
# warning is emitted as expected.
79+
pytest.warns,
80+
DeprecationWarning,
81+
match="argument is deprecated because of a potential security risk",
82+
)

tests/unit/operations_v1/test_operations_rest_client.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import pytest
2525
from typing import Any, List
26+
from ...helpers import warn_deprecated_credentials_file
2627

2728
try:
2829
import grpc # noqa: F401
@@ -369,7 +370,8 @@ def test_operations_client_client_options(
369370
)
370371

371372
# Check the case credentials_file is provided
372-
options = client_options.ClientOptions(credentials_file="credentials.json")
373+
with warn_deprecated_credentials_file():
374+
options = client_options.ClientOptions(credentials_file="credentials.json")
373375
with mock.patch.object(transport_class, "__init__") as patched:
374376
patched.return_value = None
375377
client = client_class(client_options=options, transport=transport_name)
@@ -539,11 +541,14 @@ def test_operations_client_client_options_credentials_file(
539541
client_class, transport_class, transport_name
540542
):
541543
# Check the case credentials file is provided.
542-
options = client_options.ClientOptions(credentials_file="credentials.json")
544+
with warn_deprecated_credentials_file():
545+
options = client_options.ClientOptions(credentials_file="credentials.json")
543546
if "async" in str(client_class):
544547
# TODO(): Add support for credentials file to async REST transport.
545548
with pytest.raises(core_exceptions.AsyncRestUnsupportedParameterError):
546-
client_class(client_options=options, transport=transport_name)
549+
with warn_deprecated_credentials_file():
550+
551+
client_class(client_options=options, transport=transport_name)
547552
else:
548553
with mock.patch.object(transport_class, "__init__") as patched:
549554
patched.return_value = None
@@ -570,10 +575,18 @@ def test_operations_client_client_options_credentials_file(
570575
return_value=(mock.sentinel.credentials, mock.sentinel.project),
571576
)
572577
def test_list_operations_rest(google_auth_default, credentials_file):
573-
sync_transport = transports.rest.OperationsRestTransport(
574-
credentials_file=credentials_file,
575-
http_options=HTTP_OPTIONS,
576-
)
578+
if credentials_file:
579+
with warn_deprecated_credentials_file():
580+
sync_transport = transports.rest.OperationsRestTransport(
581+
credentials_file=credentials_file,
582+
http_options=HTTP_OPTIONS,
583+
)
584+
else:
585+
# no warning expected
586+
sync_transport = transports.rest.OperationsRestTransport(
587+
credentials_file=credentials_file,
588+
http_options=HTTP_OPTIONS,
589+
)
577590

578591
client = AbstractOperationsClient(transport=sync_transport)
579592

@@ -1130,10 +1143,11 @@ def test_transport_adc(client_class, transport_class, credentials):
11301143
def test_operations_base_transport_error():
11311144
# Passing both a credentials object and credentials_file should raise an error
11321145
with pytest.raises(core_exceptions.DuplicateCredentialArgs):
1133-
transports.OperationsTransport(
1134-
credentials=ga_credentials.AnonymousCredentials(),
1135-
credentials_file="credentials.json",
1136-
)
1146+
with warn_deprecated_credentials_file():
1147+
transports.OperationsTransport(
1148+
credentials=ga_credentials.AnonymousCredentials(),
1149+
credentials_file="credentials.json",
1150+
)
11371151

11381152

11391153
def test_operations_base_transport():
@@ -1171,10 +1185,11 @@ def test_operations_base_transport_with_credentials_file():
11711185
) as Transport:
11721186
Transport.return_value = None
11731187
load_creds.return_value = (ga_credentials.AnonymousCredentials(), None)
1174-
transports.OperationsTransport(
1175-
credentials_file="credentials.json",
1176-
quota_project_id="octopus",
1177-
)
1188+
with warn_deprecated_credentials_file():
1189+
transports.OperationsTransport(
1190+
credentials_file="credentials.json",
1191+
quota_project_id="octopus",
1192+
)
11781193
load_creds.assert_called_once_with(
11791194
"credentials.json",
11801195
scopes=None,

tests/unit/test_client_options.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from re import match
1616
import pytest
17+
from ..helpers import warn_deprecated_credentials_file
1718

1819
from google.api_core import client_options
1920

@@ -27,19 +28,19 @@ def get_client_encrypted_cert():
2728

2829

2930
def test_constructor():
30-
31-
options = client_options.ClientOptions(
32-
api_endpoint="foo.googleapis.com",
33-
client_cert_source=get_client_cert,
34-
quota_project_id="quote-proj",
35-
credentials_file="path/to/credentials.json",
36-
scopes=[
37-
"https://www.googleapis.com/auth/cloud-platform",
38-
"https://www.googleapis.com/auth/cloud-platform.read-only",
39-
],
40-
api_audience="foo2.googleapis.com",
41-
universe_domain="googleapis.com",
42-
)
31+
with warn_deprecated_credentials_file():
32+
options = client_options.ClientOptions(
33+
api_endpoint="foo.googleapis.com",
34+
client_cert_source=get_client_cert,
35+
quota_project_id="quote-proj",
36+
credentials_file="path/to/credentials.json",
37+
scopes=[
38+
"https://www.googleapis.com/auth/cloud-platform",
39+
"https://www.googleapis.com/auth/cloud-platform.read-only",
40+
],
41+
api_audience="foo2.googleapis.com",
42+
universe_domain="googleapis.com",
43+
)
4344

4445
assert options.api_endpoint == "foo.googleapis.com"
4546
assert options.client_cert_source() == (b"cert", b"key")
@@ -102,10 +103,11 @@ def test_constructor_with_api_key():
102103

103104
def test_constructor_with_both_api_key_and_credentials_file():
104105
with pytest.raises(ValueError):
105-
client_options.ClientOptions(
106-
api_key="api-key",
107-
credentials_file="path/to/credentials.json",
108-
)
106+
with warn_deprecated_credentials_file():
107+
client_options.ClientOptions(
108+
api_key="api-key",
109+
credentials_file="path/to/credentials.json",
110+
)
109111

110112

111113
def test_from_dict():

0 commit comments

Comments
 (0)