Skip to content

Commit 173b50a

Browse files
committed
feat(api-core): add endpoint routing logic to gapic_v1 public helpers
1 parent d461da7 commit 173b50a

30 files changed

Lines changed: 843 additions & 1047 deletions

File tree

.github/workflows/import-profiler.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ jobs:
2626
with:
2727
python-version: "3.15"
2828
allow-prereleases: true
29-
cache: 'pip'
3029
- name: Run import profiler
3130
env:
3231
BUILD_TYPE: presubmit

ci/run_single_test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ case ${TEST_TYPE} in
101101
echo "Creating temporary virtualenv for import profile..."
102102
python3 -m venv .venv-profiler
103103
source .venv-profiler/bin/activate
104-
export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
105104
python -m pip install --upgrade pip setuptools
106105

107106
PACKAGE_NAME=$(basename $(pwd))

packages/gapic-generator/noxfile.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -474,24 +474,6 @@ def showcase_mtls(
474474
)
475475

476476

477-
# TODO(https://github.com/googleapis/google-cloud-python/issues/17752):
478-
# Remove showcase_pqc once grpcio >= 1.83.0 is enforced by default.
479-
@nox.session(python=NEWEST_PYTHON)
480-
def showcase_pqc(
481-
session,
482-
templates="DEFAULT",
483-
other_opts: typing.Iterable[str] = (),
484-
env: typing.Optional[typing.Dict[str, str]] = {},
485-
):
486-
"""Run the Showcase PQC verification test suite against grpcio 1.83+ over standard TLS."""
487-
with showcase_library(session, templates=templates, other_opts=other_opts):
488-
session.install("pytest", "pytest-asyncio")
489-
# TODO(https://github.com/googleapis/google-cloud-python/issues/17751):
490-
# Update the version below to `1.83.0` once released, and remove `--pre`.
491-
session.install("--pre", "--upgrade", "grpcio>=1.83.0rc0", "grpcio-status>=1.83.0rc0")
492-
session.run("py.test", "--quiet", "--tls", *(session.posargs or ["tests/system/test_pqc.py"]), env=env)
493-
494-
495477
def run_showcase_unit_tests(session, fail_under=100, rest_async_io_enabled=False):
496478
session.install(
497479
"coverage",

packages/gapic-generator/tests/system/conftest.py

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import os
1919
import pytest
2020
import pytest_asyncio
21-
from requests.adapters import HTTPAdapter
2221

2322
from typing import Sequence, Tuple
2423

@@ -114,18 +113,15 @@ def async_identity(use_mtls, request, event_loop):
114113
)
115114

116115

117-
base_dir = os.path.dirname(__file__)
118-
CERT_PATH = os.path.join(base_dir, "../cert/mtls.crt")
119-
KEY_PATH = os.path.join(base_dir, "../cert/mtls.key")
120-
with open(CERT_PATH, "rb") as fh:
116+
dir = os.path.dirname(__file__)
117+
with open(os.path.join(dir, "../cert/mtls.crt"), "rb") as fh:
121118
cert = fh.read()
122-
with open(KEY_PATH, "rb") as fh:
119+
with open(os.path.join(dir, "../cert/mtls.key"), "rb") as fh:
123120
key = fh.read()
124121

125122
ssl_credentials = grpc.ssl_channel_credentials(
126123
root_certificates=cert, certificate_chain=cert, private_key=key
127124
)
128-
tls_credentials = grpc.ssl_channel_credentials(root_certificates=cert)
129125

130126

131127
def callback():
@@ -140,9 +136,6 @@ def pytest_addoption(parser):
140136
parser.addoption(
141137
"--mtls", action="store_true", help="Run system test with mutual TLS channel"
142138
)
143-
parser.addoption(
144-
"--tls", action="store_true", help="Run system test with standard one-way TLS channel"
145-
)
146139

147140

148141
# TODO: Need to test without passing in a transport class
@@ -196,11 +189,6 @@ def use_mtls(request):
196189
return request.config.getoption("--mtls")
197190

198191

199-
@pytest.fixture
200-
def use_tls(request):
201-
return request.config.getoption("--tls") or request.config.getoption("--mtls")
202-
203-
204192
@pytest.fixture
205193
def parametrized_echo(
206194
use_mtls,
@@ -340,7 +328,7 @@ def _read_response_metadata_stream(self):
340328
def intercept_unary_unary(self, continuation, client_call_details, request):
341329
self._add_request_metadata(client_call_details)
342330
response = continuation(client_call_details, request)
343-
metadata = [(k, str(v)) for k, v in response.initial_metadata()] + [(k, str(v)) for k, v in response.trailing_metadata()]
331+
metadata = [(k, str(v)) for k, v in response.trailing_metadata()]
344332
self.response_metadata = metadata
345333
return response
346334

@@ -399,7 +387,7 @@ async def _add_request_metadata(self, client_call_details):
399387
async def intercept_unary_unary(self, continuation, client_call_details, request):
400388
await self._add_request_metadata(client_call_details)
401389
response = await continuation(client_call_details, request)
402-
metadata = [(k, str(v)) for k, v in await response.initial_metadata()] + [(k, str(v)) for k, v in await response.trailing_metadata()]
390+
metadata = [(k, str(v)) for k, v in await response.trailing_metadata()]
403391
self.response_metadata = metadata
404392
return response
405393

@@ -424,7 +412,7 @@ async def intercept_stream_stream(
424412

425413

426414
@pytest.fixture
427-
def intercepted_echo_grpc(use_mtls, use_tls):
415+
def intercepted_echo_grpc(use_mtls):
428416
# The interceptor adds 'showcase-trailer' client metadata. Showcase server
429417
# echoes any metadata with key 'showcase-trailer', so the same metadata
430418
# should appear as trailing metadata in the response.
@@ -433,12 +421,11 @@ def intercepted_echo_grpc(use_mtls, use_tls):
433421
"intercepted",
434422
)
435423
host = "localhost:7469"
436-
if use_mtls:
437-
channel = grpc.secure_channel(host, ssl_credentials)
438-
elif use_tls:
439-
channel = grpc.secure_channel(host, tls_credentials)
440-
else:
441-
channel = grpc.insecure_channel(host)
424+
channel = (
425+
grpc.secure_channel(host, ssl_credentials)
426+
if use_mtls
427+
else grpc.insecure_channel(host)
428+
)
442429
intercept_channel = grpc.intercept_channel(channel, interceptor)
443430
transport = EchoClient.get_transport_class("grpc")(
444431
credentials=ga_credentials.AnonymousCredentials(),
@@ -448,7 +435,7 @@ def intercepted_echo_grpc(use_mtls, use_tls):
448435

449436

450437
@pytest_asyncio.fixture
451-
async def intercepted_echo_grpc_async(use_mtls, use_tls):
438+
async def intercepted_echo_grpc_async():
452439
# The interceptor adds 'showcase-trailer' client metadata. Showcase server
453440
# echoes any metadata with key 'showcase-trailer', so the same metadata
454441
# should appear as trailing metadata in the response.
@@ -457,45 +444,28 @@ async def intercepted_echo_grpc_async(use_mtls, use_tls):
457444
"intercepted",
458445
)
459446
host = "localhost:7469"
460-
if use_mtls:
461-
channel = grpc.aio.secure_channel(host, ssl_credentials, interceptors=[interceptor])
462-
elif use_tls:
463-
channel = grpc.aio.secure_channel(host, tls_credentials, interceptors=[interceptor])
464-
else:
465-
channel = grpc.aio.insecure_channel(host, interceptors=[interceptor])
447+
channel = grpc.aio.insecure_channel(host, interceptors=[interceptor])
448+
# intercept_channel = grpc.aio.intercept_channel(channel, interceptor)
466449
transport = EchoAsyncClient.get_transport_class("grpc_asyncio")(
467450
credentials=ga_credentials.AnonymousCredentials(),
468451
channel=channel,
469452
)
470453
return EchoAsyncClient(transport=transport), interceptor
471454

472455

473-
class HostNameIgnoringAdapter(HTTPAdapter):
474-
"""Custom HTTPAdapter that disables hostname verification for local self-signed certs."""
475-
def cert_verify(self, conn, url, verify, cert):
476-
super().cert_verify(conn, url, verify, cert)
477-
conn.assert_hostname = False
478-
479-
480456
@pytest.fixture
481-
def intercepted_echo_rest(use_mtls, use_tls):
457+
def intercepted_echo_rest():
482458
transport_name = "rest"
483459
transport_cls = EchoClient.get_transport_class(transport_name)
484460
interceptor = EchoMetadataClientRestInterceptor()
485461

486-
url_scheme = "https" if (use_mtls or use_tls) else "http"
462+
# The custom host explicitly bypasses https.
487463
transport = transport_cls(
488464
credentials=ga_credentials.AnonymousCredentials(),
489465
host="localhost:7469",
490-
url_scheme=url_scheme,
466+
url_scheme="http",
491467
interceptor=interceptor,
492468
)
493-
if use_mtls or use_tls:
494-
transport._session.verify = CERT_PATH
495-
transport._session.mount("https://", HostNameIgnoringAdapter())
496-
if use_mtls:
497-
transport._session.cert = (CERT_PATH, KEY_PATH)
498-
499469
return EchoClient(transport=transport), interceptor
500470

501471

@@ -508,11 +478,11 @@ def intercepted_echo_rest_async():
508478
transport_cls = EchoAsyncClient.get_transport_class(transport_name)
509479
interceptor = EchoMetadataClientRestAsyncInterceptor()
510480

481+
# The custom host explicitly bypasses https.
511482
transport = transport_cls(
512483
credentials=async_anonymous_credentials(),
513484
host="localhost:7469",
514485
url_scheme="http",
515486
interceptor=interceptor,
516487
)
517-
518488
return EchoAsyncClient(transport=transport), interceptor

packages/gapic-generator/tests/system/test_pqc.py

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

packages/google-api-core/.coveragerc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
branch = True
33

44
[report]
5-
fail_under = 100
5+
fail_under = 99
66
show_missing = True
7-
omit =
8-
tests/*
9-
*/tests/*
107
exclude_lines =
118
# Re-enable the standard pragma
129
pragma: NO COVER

packages/google-api-core/google/api_core/gapic_v1/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
# Older Python versions safely ignore this variable.
2626
__lazy_modules__: Set[str] = {
2727
"google.api_core.gapic_v1.client_info",
28+
"google.api_core.gapic_v1.client_utils",
2829
"google.api_core.gapic_v1.requests",
2930
"google.api_core.gapic_v1.routing_header",
3031
}
31-
__all__ = ["client_info", "requests", "routing_header"]
32+
__all__ = ["client_info", "client_utils", "requests", "routing_header"]
33+
3234

3335
if _has_grpc:
3436
__lazy_modules__.update(
@@ -42,6 +44,7 @@
4244

4345
from google.api_core.gapic_v1 import ( # noqa: E402
4446
client_info,
47+
client_utils,
4548
requests,
4649
routing_header,
4750
)

0 commit comments

Comments
 (0)