Skip to content

Commit b1e5703

Browse files
sync from upstream
Signed-off-by: Elena Kolevska <[email protected]>
1 parent 4fc38e2 commit b1e5703

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Added `set_custom_status` orchestrator API ([#31](https://github.com/microsoft/durabletask-python/pull/31)) - contributed by [@famarting](https://github.com/famarting)
1313
- Added `purge_orchestration` client API ([#34](https://github.com/microsoft/durabletask-python/pull/34)) - contributed by [@famarting](https://github.com/famarting)
1414

15+
### Changes
16+
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)
19+
1520
### Updates
1621

1722
- Updated `durabletask-protobuf` submodule reference to latest

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"
@@ -24,6 +27,20 @@ def get_grpc_channel(host_address: Union[str, None], metadata: Union[List[Tuple[
2427
if host_address is None:
2528
host_address = get_default_host_address()
2629

30+
for protocol in SECURE_PROTOCOLS:
31+
if host_address.lower().startswith(protocol):
32+
secure_channel = True
33+
# remove the protocol from the host name
34+
host_address = host_address[len(protocol):]
35+
break
36+
37+
for protocol in INSECURE_PROTOCOLS:
38+
if host_address.lower().startswith(protocol):
39+
secure_channel = False
40+
# remove the protocol from the host name
41+
host_address = host_address[len(protocol):]
42+
break
43+
2744
if secure_channel:
2845
channel = grpc.secure_channel(host_address, grpc.ssl_channel_credentials())
2946
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)