Skip to content

Commit 6ef52fc

Browse files
sync from upstream (#7)
Signed-off-by: Elena Kolevska <[email protected]> Signed-off-by: Elena Kolevska <[email protected]>
1 parent 60c4633 commit 6ef52fc

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414

1515
### Changes
1616

17-
- Protos are compiled with gRPC 1.62.3 / protobuf 3.25.X instead of the latest release. This ensures compatibility with a wider range of grpcio versions for better compatibility with other packages / libraries.
17+
- Protos are compiled with gRPC 1.62.3 / protobuf 3.25.X instead of the latest release. This ensures compatibility with a wider range of grpcio versions for better compatibility with other packages / libraries ([#36](https://github.com/microsoft/durabletask-python/pull/36)) - by [@berndverst](https://github.com/berndverst)
18+
- Http and grpc protocols and their secure variants are stripped from the host name parameter if provided. Secure mode is enabled if the protocol provided is https or grpcs ([#38](https://github.com/microsoft/durabletask-python/pull/38) - by [@berndverst)(https://github.com/berndverst)
1819

1920
### Updates
2021

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Orchestrations can specify retry policies for activities and sub-orchestrations.
134134

135135
### Prerequisites
136136

137-
- Python 3.8
137+
- Python 3.9
138138
- A Durable Task-compatible sidecar, like [Dapr Workflow](https://docs.dapr.io/developing-applications/building-blocks/workflow/workflow-overview/)
139139

140140
### Installing the Durable Task Python client SDK

durabletask/internal/shared.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
# and should be deserialized as a SimpleNamespace
1616
AUTO_SERIALIZED = "__durabletask_autoobject__"
1717

18+
SECURE_PROTOCOLS = ["https://", "grpcs://"]
19+
INSECURE_PROTOCOLS = ["http://", "grpc://"]
20+
1821

1922
def get_default_host_address() -> str:
2023
return "localhost:4001"
@@ -27,6 +30,20 @@ def get_grpc_channel(
2730
if host_address is None:
2831
host_address = get_default_host_address()
2932

33+
for protocol in SECURE_PROTOCOLS:
34+
if host_address.lower().startswith(protocol):
35+
secure_channel = True
36+
# remove the protocol from the host name
37+
host_address = host_address[len(protocol):]
38+
break
39+
40+
for protocol in INSECURE_PROTOCOLS:
41+
if host_address.lower().startswith(protocol):
42+
secure_channel = False
43+
# remove the protocol from the host name
44+
host_address = host_address[len(protocol):]
45+
break
46+
3047
if secure_channel:
3148
channel = grpc.secure_channel(host_address, grpc.ssl_channel_credentials())
3249
else:

tests/test_client.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from unittest.mock import patch
1+
from unittest.mock import patch, ANY
22

33
from durabletask.internal.shared import (DefaultClientInterceptorImpl,
44
get_default_host_address,
@@ -39,3 +39,50 @@ def test_get_grpc_channel_with_metadata():
3939
assert args[0] == mock_channel.return_value
4040
assert isinstance(args[1], DefaultClientInterceptorImpl)
4141
assert args[1]._metadata == METADATA
42+
43+
44+
def test_grpc_channel_with_host_name_protocol_stripping():
45+
with patch('grpc.insecure_channel') as mock_insecure_channel, patch(
46+
'grpc.secure_channel') as mock_secure_channel:
47+
48+
host_name = "myserver.com:1234"
49+
50+
prefix = "grpc://"
51+
get_grpc_channel(prefix + host_name, METADATA)
52+
mock_insecure_channel.assert_called_with(host_name)
53+
54+
prefix = "http://"
55+
get_grpc_channel(prefix + host_name, METADATA)
56+
mock_insecure_channel.assert_called_with(host_name)
57+
58+
prefix = "HTTP://"
59+
get_grpc_channel(prefix + host_name, METADATA)
60+
mock_insecure_channel.assert_called_with(host_name)
61+
62+
prefix = "GRPC://"
63+
get_grpc_channel(prefix + host_name, METADATA)
64+
mock_insecure_channel.assert_called_with(host_name)
65+
66+
prefix = ""
67+
get_grpc_channel(prefix + host_name, METADATA)
68+
mock_insecure_channel.assert_called_with(host_name)
69+
70+
prefix = "grpcs://"
71+
get_grpc_channel(prefix + host_name, METADATA)
72+
mock_secure_channel.assert_called_with(host_name, ANY)
73+
74+
prefix = "https://"
75+
get_grpc_channel(prefix + host_name, METADATA)
76+
mock_secure_channel.assert_called_with(host_name, ANY)
77+
78+
prefix = "HTTPS://"
79+
get_grpc_channel(prefix + host_name, METADATA)
80+
mock_secure_channel.assert_called_with(host_name, ANY)
81+
82+
prefix = "GRPCS://"
83+
get_grpc_channel(prefix + host_name, METADATA)
84+
mock_secure_channel.assert_called_with(host_name, ANY)
85+
86+
prefix = ""
87+
get_grpc_channel(prefix + host_name, METADATA, True)
88+
mock_secure_channel.assert_called_with(host_name, ANY)

0 commit comments

Comments
 (0)