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

fix: Add emulator support to schema service #658

Merged
merged 17 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions google/pubsub_v1/services/schema_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
#
from collections import OrderedDict
import functools
import os
import re
from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union
Expand All @@ -39,6 +40,8 @@
from google.pubsub_v1.services.schema_service import pagers
from google.pubsub_v1.types import schema
from google.pubsub_v1.types import schema as gp_schema

import grpc
from .transports.base import SchemaServiceTransport, DEFAULT_CLIENT_INFO
from .transports.grpc import SchemaServiceGrpcTransport
from .transports.grpc_asyncio import SchemaServiceGrpcAsyncIOTransport
Expand Down Expand Up @@ -411,6 +414,15 @@ def __init__(
)

Transport = type(self).get_transport_class(transport)

emulator_host = os.environ.get("PUBSUB_EMULATOR_HOST")
if emulator_host:
if issubclass(Transport, type(self)._transport_registry["grpc"]):
channel = grpc.insecure_channel(target=emulator_host)
else:
channel = grpc.aio.insecure_channel(target=emulator_host)
Transport = functools.partial(Transport, channel=channel)

self._transport = Transport(
credentials=credentials,
credentials_file=client_options.credentials_file,
Expand Down
5 changes: 3 additions & 2 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
clients_to_patch = [
library / f"google/pubsub_{library.name}/services/publisher/client.py",
library / f"google/pubsub_{library.name}/services/subscriber/client.py",
library / f"google/pubsub_{library.name}/services/schema_service/client.py",
]
err_msg = (
"Expected replacements for gRPC channel to use with the emulator not made."
Expand All @@ -97,8 +98,8 @@

count = s.replace(
clients_to_patch,
f"from google\.pubsub_{library.name}\.types import pubsub",
"\g<0>\n\nimport grpc",
f"from \.transports\.base",
"\nimport grpc\n\g<0>",
)

if count < len(clients_to_patch):
Expand Down