Skip to content

Commit 09a409c

Browse files
fix: fix mtls issue in handwritten layer (googleapis#226)
* fix: fix mtls issue in handwritten layer * chore: update scripts * chore: update noxfile.py
1 parent ec8f5f2 commit 09a409c

12 files changed

Lines changed: 82 additions & 28 deletions

File tree

.kokoro/docs/common.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ env_vars: {
3030

3131
env_vars: {
3232
key: "V2_STAGING_BUCKET"
33-
value: "docs-staging-v2-staging"
33+
value: "docs-staging-v2"
3434
}
3535

3636
# It will upload the docker image after successful builds.

.kokoro/samples/python3.6/common.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ env_vars: {
1313
value: "py-3.6"
1414
}
1515

16+
# Declare build specific Cloud project.
17+
env_vars: {
18+
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
19+
value: "python-docs-samples-tests-py36"
20+
}
21+
1622
env_vars: {
1723
key: "TRAMPOLINE_BUILD_FILE"
1824
value: "github/python-pubsub/.kokoro/test-samples.sh"

.kokoro/samples/python3.7/common.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ env_vars: {
1313
value: "py-3.7"
1414
}
1515

16+
# Declare build specific Cloud project.
17+
env_vars: {
18+
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
19+
value: "python-docs-samples-tests-py37"
20+
}
21+
1622
env_vars: {
1723
key: "TRAMPOLINE_BUILD_FILE"
1824
value: "github/python-pubsub/.kokoro/test-samples.sh"

.kokoro/samples/python3.8/common.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ env_vars: {
1313
value: "py-3.8"
1414
}
1515

16+
# Declare build specific Cloud project.
17+
env_vars: {
18+
key: "BUILD_SPECIFIC_GCLOUD_PROJECT"
19+
value: "python-docs-samples-tests-py38"
20+
}
21+
1622
env_vars: {
1723
key: "TRAMPOLINE_BUILD_FILE"
1824
value: "github/python-pubsub/.kokoro/test-samples.sh"

.kokoro/test-samples.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then
2828
git checkout $LATEST_RELEASE
2929
fi
3030

31+
# Exit early if samples directory doesn't exist
32+
if [ ! -d "./samples" ]; then
33+
echo "No tests run. `./samples` not found"
34+
exit 0
35+
fi
36+
3137
# Disable buffering, so that the logs stream through.
3238
export PYTHONUNBUFFERED=1
3339

@@ -101,4 +107,4 @@ cd "$ROOT"
101107
# Workaround for Kokoro permissions issue: delete secrets
102108
rm testing/{test-env.sh,client-secrets.json,service-account.json}
103109

104-
exit "$RTN"
110+
exit "$RTN"

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"sphinx.ext.autosummary",
4040
"sphinx.ext.intersphinx",
4141
"sphinx.ext.coverage",
42+
"sphinx.ext.doctest",
4243
"sphinx.ext.napoleon",
4344
"sphinx.ext.todo",
4445
"sphinx.ext.viewcode",

google/cloud/pubsub_v1/publisher/client.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,19 @@ def __init__(self, batch_settings=(), publisher_options=(), **kwargs):
130130
target=os.environ.get("PUBSUB_EMULATOR_HOST")
131131
)
132132

133+
# The GAPIC client has mTLS logic to determine the api endpoint and the
134+
# ssl credentials to use. Here we create a GAPIC client to help compute the
135+
# api endpoint and ssl credentials. The api endpoint will be used to set
136+
# `self._target`, and ssl credentials will be passed to
137+
# `grpc_helpers.create_channel` to establish a mTLS channel (if ssl
138+
# credentials is not None).
133139
client_options = kwargs.get("client_options", None)
134-
if (
135-
client_options
136-
and "api_endpoint" in client_options
137-
and isinstance(client_options["api_endpoint"], six.string_types)
138-
):
139-
self._target = client_options["api_endpoint"]
140-
else:
141-
self._target = publisher_client.PublisherClient.SERVICE_ADDRESS
140+
credentials = kwargs.get("credentials", None)
141+
client_for_mtls_info = publisher_client.PublisherClient(
142+
credentials=credentials, client_options=client_options
143+
)
144+
145+
self._target = client_for_mtls_info._transport._host
142146

143147
# Use a custom channel.
144148
# We need this in order to set appropriate default message size and
@@ -149,6 +153,7 @@ def __init__(self, batch_settings=(), publisher_options=(), **kwargs):
149153
channel = grpc_helpers.create_channel(
150154
credentials=kwargs.pop("credentials", None),
151155
target=self.target,
156+
ssl_credentials=client_for_mtls_info._transport._ssl_channel_credentials,
152157
scopes=publisher_client.PublisherClient._DEFAULT_SCOPES,
153158
options={
154159
"grpc.max_send_message_length": -1,

google/cloud/pubsub_v1/subscriber/client.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import os
1818
import pkg_resources
19-
import six
2019

2120
import grpc
2221

@@ -82,16 +81,19 @@ def __init__(self, **kwargs):
8281
target=os.environ.get("PUBSUB_EMULATOR_HOST")
8382
)
8483

85-
# api_endpoint wont be applied if 'transport' is passed in.
84+
# The GAPIC client has mTLS logic to determine the api endpoint and the
85+
# ssl credentials to use. Here we create a GAPIC client to help compute the
86+
# api endpoint and ssl credentials. The api endpoint will be used to set
87+
# `self._target`, and ssl credentials will be passed to
88+
# `grpc_helpers.create_channel` to establish a mTLS channel (if ssl
89+
# credentials is not None).
8690
client_options = kwargs.get("client_options", None)
87-
if (
88-
client_options
89-
and "api_endpoint" in client_options
90-
and isinstance(client_options["api_endpoint"], six.string_types)
91-
):
92-
self._target = client_options["api_endpoint"]
93-
else:
94-
self._target = subscriber_client.SubscriberClient.SERVICE_ADDRESS
91+
credentials = kwargs.get("credentials", None)
92+
client_for_mtls_info = subscriber_client.SubscriberClient(
93+
credentials=credentials, client_options=client_options
94+
)
95+
96+
self._target = client_for_mtls_info._transport._host
9597

9698
# Use a custom channel.
9799
# We need this in order to set appropriate default message size and
@@ -102,6 +104,7 @@ def __init__(self, **kwargs):
102104
channel = grpc_helpers.create_channel(
103105
credentials=kwargs.pop("credentials", None),
104106
target=self.target,
107+
ssl_credentials=client_for_mtls_info._transport._ssl_channel_credentials,
105108
scopes=subscriber_client.SubscriberClient._DEFAULT_SCOPES,
106109
options={
107110
"grpc.max_send_message_length": -1,

samples/snippets/noxfile.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ def _get_repo_root():
199199
break
200200
if Path(p / ".git").exists():
201201
return str(p)
202+
# .git is not available in repos cloned via Cloud Build
203+
# setup.py is always in the library's root, so use that instead
204+
# https://github.com/googleapis/synthtool/issues/792
205+
if Path(p / "setup.py").exists():
206+
return str(p)
202207
p = p.parent
203208
raise Exception("Unable to detect repository root.")
204209

synth.metadata

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44
"git": {
55
"name": ".",
66
"remote": "https://github.com/googleapis/python-pubsub.git",
7-
"sha": "c957047c84c5586e4a782e9ae297094be6cdba2e"
7+
"sha": "0bf5d593573afea43bba7de90d2bb40ee0fc101e"
88
}
99
},
1010
{
1111
"git": {
1212
"name": "synthtool",
1313
"remote": "https://github.com/googleapis/synthtool.git",
14-
"sha": "6abb59097be84599a1d6091fe534a49e5c5cf948"
14+
"sha": "901ddd44e9ef7887ee681b9183bbdea99437fdcc"
1515
}
1616
},
1717
{
1818
"git": {
1919
"name": "synthtool",
2020
"remote": "https://github.com/googleapis/synthtool.git",
21-
"sha": "6abb59097be84599a1d6091fe534a49e5c5cf948"
21+
"sha": "901ddd44e9ef7887ee681b9183bbdea99437fdcc"
2222
}
2323
},
2424
{
2525
"git": {
2626
"name": "synthtool",
2727
"remote": "https://github.com/googleapis/synthtool.git",
28-
"sha": "6abb59097be84599a1d6091fe534a49e5c5cf948"
28+
"sha": "901ddd44e9ef7887ee681b9183bbdea99437fdcc"
2929
}
3030
}
3131
],

0 commit comments

Comments
 (0)