Skip to content

Commit

Permalink
fix: set creds only if transport not provided (#1348)
Browse files Browse the repository at this point in the history
Co-authored-by: mukund-ananthu <[email protected]>
  • Loading branch information
ohmayr and mukund-ananthu authored Jan 29, 2025
1 parent 32d0998 commit 59965a4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion google/cloud/pubsub_v1/publisher/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@ def __init__(
# Sanity check: Is our goal to use the emulator?
# If so, create a grpc insecure channel with the emulator host
# as the target.
# TODO(https://github.com/googleapis/python-pubsub/issues/1349): Move the emulator
# code below to test files.
if os.environ.get("PUBSUB_EMULATOR_HOST"):
kwargs["client_options"] = {
"api_endpoint": os.environ.get("PUBSUB_EMULATOR_HOST")
}
kwargs["credentials"] = AnonymousCredentials()
# Configure credentials directly to transport, if provided.
if "transport" not in kwargs:
kwargs["credentials"] = AnonymousCredentials()

# For a transient failure, retry publishing the message infinitely.
self.publisher_options = types.PublisherOptions(*publisher_options)
Expand Down
6 changes: 5 additions & 1 deletion google/cloud/pubsub_v1/subscriber/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ def __init__(
# Sanity check: Is our goal to use the emulator?
# If so, create a grpc insecure channel with the emulator host
# as the target.
# TODO(https://github.com/googleapis/python-pubsub/issues/1349): Move the emulator
# code below to test files.
if os.environ.get("PUBSUB_EMULATOR_HOST"):
kwargs["client_options"] = {
"api_endpoint": os.environ.get("PUBSUB_EMULATOR_HOST")
}
kwargs["credentials"] = AnonymousCredentials()
# Configure credentials directly to transport, if provided.
if "transport" not in kwargs:
kwargs["credentials"] = AnonymousCredentials()

# Instantiate the underlying GAPIC client.
super().__init__(**kwargs)
Expand Down
2 changes: 2 additions & 0 deletions owlbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
if count < len(clients_to_patch):
raise Exception(err_msg)

# TODO(https://github.com/googleapis/python-pubsub/issues/1349): Move the emulator
# code below to test files.
count = s.replace(
clients_to_patch,
r"# initialize with the provided callable or the passed in class",
Expand Down

0 comments on commit 59965a4

Please sign in to comment.