Skip to content

Commit 2288f41

Browse files
authored
Use host:port instead of URL and TLS test fixes (#86)
1 parent a569582 commit 2288f41

File tree

8 files changed

+373
-204
lines changed

8 files changed

+373
-204
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Also see:
1313

1414
* [Code Samples](https://github.com/temporalio/samples-python)
1515
* [API Documentation](https://python.temporal.io)
16+
* [Application Development Guide](https://docs.temporal.io/application-development?lang=python)
1617

1718
In addition to features common across all Temporal SDKs, the Python SDK also has the following interesting features:
1819

@@ -89,7 +90,7 @@ class SayHello:
8990

9091
async def main():
9192
# Create client connected to server at the given address
92-
client = await Client.connect("http://localhost:7233")
93+
client = await Client.connect("localhost:7233")
9394

9495
# Run the worker
9596
worker = Worker(client, task_queue="my-task-queue", workflows=[SayHello], activities=[say_hello])
@@ -117,7 +118,7 @@ from my_worker_package import SayHello
117118

118119
async def main():
119120
# Create client connected to server at the given address
120-
client = await Client.connect("http://localhost:7233")
121+
client = await Client.connect("localhost:7233")
121122

122123
# Execute a workflow
123124
result = await client.execute_workflow(SayHello.run, "my name", id="my-workflow-id", task_queue="my-task-queue")
@@ -147,7 +148,7 @@ from temporalio.client import Client
147148

148149
async def main():
149150
# Create client connected to server at the given address and namespace
150-
client = await Client.connect("http://localhost:7233", namespace="my-namespace")
151+
client = await Client.connect("localhost:7233", namespace="my-namespace")
151152

152153
# Start a workflow
153154
handle = await client.start_workflow(MyWorkflow.run, "some arg", id="my-workflow-id", task_queue="my-task-queue")
@@ -160,6 +161,7 @@ async def main():
160161
Some things to note about the above code:
161162

162163
* A `Client` does not have an explicit "close"
164+
* To enable TLS, the `tls` argument to `connect` can be set to `True` or a `TLSConfig` object
163165
* A single positional argument can be passed to `start_workflow`. If there are multiple arguments, only the
164166
non-type-safe form of `start_workflow` can be used (i.e. the one accepting a string workflow name) and it must be in
165167
the `args` keyword argument.
@@ -213,7 +215,7 @@ from my_workflow_package import MyWorkflow, my_activity
213215

214216
async def run_worker(stop_event: asyncio.Event):
215217
# Create client connected to server at the given address
216-
client = await Client.connect("http://localhost:7233", namespace="my-namespace")
218+
client = await Client.connect("localhost:7233", namespace="my-namespace")
217219

218220
# Run the worker until the event is set
219221
worker = Worker(client, task_queue="my-task-queue", workflows=[MyWorkflow], activities=[my_activity])
@@ -677,7 +679,7 @@ class SayHello:
677679
return f"Hello, {name}!"
678680

679681
async def main():
680-
client = await Client.connect("http://localhost:7233")
682+
client = await Client.connect("localhost:7233")
681683
async with Worker(client, task_queue="my-task-queue", workflows=[SayHello]):
682684
result = await client.execute_workflow(SayHello.run, "Temporal",
683685
id="my-workflow-id", task_queue="my-task-queue")

temporalio/client.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
overload,
2323
)
2424

25-
from typing_extensions import Concatenate, ParamSpec, TypedDict
25+
from typing_extensions import Concatenate, TypedDict
2626

2727
import temporalio.api.common.v1
2828
import temporalio.api.enums.v1
@@ -61,7 +61,7 @@ class Client:
6161

6262
@staticmethod
6363
async def connect(
64-
target_url: str,
64+
target_host: str,
6565
*,
6666
namespace: str = "default",
6767
data_converter: temporalio.converter.DataConverter = temporalio.converter.default(),
@@ -71,16 +71,16 @@ async def connect(
7171
default_workflow_query_reject_condition: Optional[
7272
temporalio.common.QueryRejectCondition
7373
] = None,
74-
tls_config: Optional[TLSConfig] = None,
74+
tls: Union[bool, TLSConfig] = False,
7575
retry_config: Optional[RetryConfig] = None,
7676
static_headers: Mapping[str, str] = {},
7777
identity: Optional[str] = None,
7878
) -> Client:
7979
"""Connect to a Temporal server.
8080
8181
Args:
82-
target_url: URL for the Temporal server. For local development, this
83-
is often "http://localhost:7233".
82+
target_host: `host:port` for the Temporal server. For local
83+
development, this is often "localhost:7233".
8484
namespace: Namespace to use for client calls.
8585
data_converter: Data converter to use for all data conversions
8686
to/from payloads.
@@ -96,8 +96,9 @@ async def connect(
9696
condition for workflow queries if not set during query. See
9797
:py:meth:`WorkflowHandle.query` for details on the rejection
9898
condition.
99-
tls_config: TLS configuration for connecting to the server. If unset
100-
no TLS connection will be used.
99+
tls: If false, the default, do not use TLS. If true, use system
100+
default TLS configuration. If TLS configuration present, that
101+
TLS configuration will be used.
101102
retry_config: Retry configuration for direct service calls (when
102103
opted in) or all high-level calls made by this client (which all
103104
opt-in to retries by default). If unset, a default retry
@@ -107,8 +108,8 @@ async def connect(
107108
based on the version of the SDK.
108109
"""
109110
connect_config = temporalio.workflow_service.ConnectConfig(
110-
target_url=target_url,
111-
tls_config=tls_config,
111+
target_host=target_host,
112+
tls=tls,
112113
retry_config=retry_config,
113114
static_headers=static_headers,
114115
identity=identity or "",

temporalio/workflow_service.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import logging
66
import os
77
import socket
8+
import warnings
89
from abc import ABC, abstractmethod
910
from dataclasses import dataclass, field
1011
from enum import IntEnum
11-
from typing import Generic, Mapping, Optional, Type, TypeVar
12+
from typing import Generic, Mapping, Optional, Type, TypeVar, Union
1213

1314
import google.protobuf.message
1415
import grpc
@@ -94,8 +95,8 @@ def _to_bridge_config(self) -> temporalio.bridge.client.ClientRetryConfig:
9495
class ConnectConfig:
9596
"""Config for connecting to the server."""
9697

97-
target_url: str
98-
tls_config: Optional[TLSConfig] = None
98+
target_host: str
99+
tls: Union[bool, TLSConfig] = False
99100
retry_config: Optional[RetryConfig] = None
100101
static_headers: Mapping[str, str] = field(default_factory=dict)
101102
identity: str = ""
@@ -106,9 +107,34 @@ def __post_init__(self) -> None:
106107
self.identity = f"{os.getpid()}@{socket.gethostname()}"
107108

108109
def _to_bridge_config(self) -> temporalio.bridge.client.ClientConfig:
110+
# Need to create the URL from the host:port. We allowed scheme in the
111+
# past so we'll leave it for only one more version with a warning.
112+
# Otherwise we'll prepend the scheme.
113+
target_url: str
114+
tls_config: Optional[temporalio.bridge.client.ClientTlsConfig]
115+
if "://" in self.target_host:
116+
warnings.warn(
117+
"Target host as URL with scheme no longer supported. This will be an error in future versions."
118+
)
119+
target_url = self.target_host
120+
tls_config = (
121+
self.tls._to_bridge_config()
122+
if isinstance(self.tls, TLSConfig)
123+
else None
124+
)
125+
elif isinstance(self.tls, TLSConfig):
126+
target_url = f"https://{self.target_host}"
127+
tls_config = self.tls._to_bridge_config()
128+
elif self.tls:
129+
target_url = f"https://{self.target_host}"
130+
tls_config = TLSConfig()._to_bridge_config()
131+
else:
132+
target_url = f"http://{self.target_host}"
133+
tls_config = None
134+
109135
return temporalio.bridge.client.ClientConfig(
110-
target_url=self.target_url,
111-
tls_config=self.tls_config._to_bridge_config() if self.tls_config else None,
136+
target_url=target_url,
137+
tls_config=tls_config,
112138
retry_config=self.retry_config._to_bridge_config()
113139
if self.retry_config
114140
else None,

tests/helpers/golangserver/go.mod

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
module github.com/temporalio/sdk-python/tests/fixtures/golangserver
22

3-
go 1.17
3+
go 1.18
44

55
replace github.com/cactus/go-statsd-client => github.com/cactus/go-statsd-client v3.2.1+incompatible
66

77
require (
8-
github.com/DataDog/temporalite v0.0.0-20220526022626-0f25777b0ee7
9-
go.temporal.io/server v1.16.2
8+
github.com/temporalio/temporalite v0.0.0-20220729234035-c93d79bb8f4d
9+
go.temporal.io/server v1.17.1
1010
)
1111

1212
require (
13-
cloud.google.com/go v0.100.2 // indirect
14-
cloud.google.com/go/compute v1.2.0 // indirect
15-
cloud.google.com/go/iam v0.1.1 // indirect
16-
cloud.google.com/go/storage v1.20.0 // indirect
13+
cloud.google.com/go v0.102.1 // indirect
14+
cloud.google.com/go/compute v1.7.0 // indirect
15+
cloud.google.com/go/iam v0.3.0 // indirect
16+
cloud.google.com/go/storage v1.23.0 // indirect
1717
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7 // indirect
18-
github.com/aws/aws-sdk-go v1.42.52 // indirect
18+
github.com/aws/aws-sdk-go v1.44.41 // indirect
1919
github.com/benbjohnson/clock v1.3.0 // indirect
2020
github.com/beorn7/perks v1.0.1 // indirect
2121
github.com/blang/semver/v4 v4.0.0 // indirect
@@ -24,83 +24,98 @@ require (
2424
github.com/davecgh/go-spew v1.1.1 // indirect
2525
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
2626
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
27-
github.com/go-logr/logr v1.2.2 // indirect
27+
github.com/go-logr/logr v1.2.3 // indirect
2828
github.com/go-logr/stdr v1.2.2 // indirect
29-
github.com/gocql/gocql v0.0.0-20211222173705-d73e6b1002a7 // indirect
29+
github.com/gocql/gocql v1.1.0 // indirect
3030
github.com/gogo/googleapis v1.4.1 // indirect
3131
github.com/gogo/protobuf v1.3.2 // indirect
32-
github.com/gogo/status v1.1.0 // indirect
33-
github.com/golang-jwt/jwt/v4 v4.3.0 // indirect
32+
github.com/gogo/status v1.1.1 // indirect
33+
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
3434
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3535
github.com/golang/mock v1.6.0 // indirect
3636
github.com/golang/protobuf v1.5.2 // indirect
3737
github.com/golang/snappy v0.0.4 // indirect
38-
github.com/google/go-cmp v0.5.7 // indirect
38+
github.com/google/go-cmp v0.5.8 // indirect
3939
github.com/google/uuid v1.3.0 // indirect
40-
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
40+
github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect
41+
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
42+
github.com/googleapis/go-type-adapters v1.0.0 // indirect
4143
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
4244
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
4345
github.com/iancoleman/strcase v0.2.0 // indirect
4446
github.com/jmespath/go-jmespath v0.4.0 // indirect
4547
github.com/jmoiron/sqlx v1.3.4 // indirect
46-
github.com/jonboulle/clockwork v0.2.2 // indirect
48+
github.com/jonboulle/clockwork v0.3.0 // indirect
4749
github.com/josharian/intern v1.0.0 // indirect
50+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
4851
github.com/mailru/easyjson v0.7.7 // indirect
49-
github.com/mattn/go-sqlite3 v1.14.11 // indirect
52+
github.com/mattn/go-isatty v0.0.14 // indirect
5053
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
5154
github.com/olivere/elastic v6.2.37+incompatible // indirect
52-
github.com/olivere/elastic/v7 v7.0.31 // indirect
55+
github.com/olivere/elastic/v7 v7.0.32 // indirect
5356
github.com/opentracing/opentracing-go v1.2.0 // indirect
5457
github.com/pborman/uuid v1.2.1 // indirect
5558
github.com/pkg/errors v0.9.1 // indirect
5659
github.com/pmezard/go-difflib v1.0.0 // indirect
57-
github.com/prometheus/client_golang v1.12.1 // indirect
60+
github.com/prometheus/client_golang v1.12.2 // indirect
5861
github.com/prometheus/client_model v0.2.0 // indirect
59-
github.com/prometheus/common v0.32.1 // indirect
62+
github.com/prometheus/common v0.35.0 // indirect
6063
github.com/prometheus/procfs v0.7.3 // indirect
6164
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
65+
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
6266
github.com/robfig/cron v1.2.0 // indirect
6367
github.com/robfig/cron/v3 v3.0.1 // indirect
6468
github.com/sirupsen/logrus v1.8.1 // indirect
65-
github.com/stretchr/objx v0.3.0 // indirect
66-
github.com/stretchr/testify v1.7.0 // indirect
69+
github.com/stretchr/objx v0.4.0 // indirect
70+
github.com/stretchr/testify v1.8.0 // indirect
6771
github.com/temporalio/ringpop-go v0.0.0-20211012191444-6f91b5915e95 // indirect
6872
github.com/twmb/murmur3 v1.1.6 // indirect
6973
github.com/uber-common/bark v1.3.0 // indirect
70-
github.com/uber-go/tally/v4 v4.1.1 // indirect
71-
github.com/uber/tchannel-go v1.22.2 // indirect
74+
github.com/uber-go/tally/v4 v4.1.2 // indirect
75+
github.com/uber/tchannel-go v1.22.3 // indirect
7276
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 // indirect
7377
go.opencensus.io v0.23.0 // indirect
74-
go.opentelemetry.io/otel v1.4.0 // indirect
75-
go.opentelemetry.io/otel/exporters/prometheus v0.27.0 // indirect
76-
go.opentelemetry.io/otel/internal/metric v0.27.0 // indirect
77-
go.opentelemetry.io/otel/metric v0.27.0 // indirect
78-
go.opentelemetry.io/otel/sdk v1.4.0 // indirect
79-
go.opentelemetry.io/otel/sdk/export/metric v0.27.0 // indirect
80-
go.opentelemetry.io/otel/sdk/metric v0.27.0 // indirect
81-
go.opentelemetry.io/otel/trace v1.4.0 // indirect
82-
go.temporal.io/api v1.7.1-0.20220326004856-88a7c92fb8b4 // indirect
83-
go.temporal.io/sdk v1.14.0 // indirect
78+
go.opentelemetry.io/otel v1.7.0 // indirect
79+
go.opentelemetry.io/otel/exporters/prometheus v0.30.0 // indirect
80+
go.opentelemetry.io/otel/metric v0.30.0 // indirect
81+
go.opentelemetry.io/otel/sdk v1.7.0 // indirect
82+
go.opentelemetry.io/otel/sdk/metric v0.30.0 // indirect
83+
go.opentelemetry.io/otel/trace v1.7.0 // indirect
84+
go.temporal.io/api v1.8.1-0.20220603192404-e65836719706 // indirect
85+
go.temporal.io/sdk v1.15.0 // indirect
8486
go.temporal.io/version v0.3.0 // indirect
8587
go.uber.org/atomic v1.9.0 // indirect
86-
go.uber.org/dig v1.13.0 // indirect
87-
go.uber.org/fx v1.16.0 // indirect
88-
go.uber.org/multierr v1.7.0 // indirect
88+
go.uber.org/dig v1.14.1 // indirect
89+
go.uber.org/fx v1.17.1 // indirect
90+
go.uber.org/multierr v1.8.0 // indirect
8991
go.uber.org/zap v1.21.0 // indirect
90-
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
91-
golang.org/x/net v0.0.0-20220325170049-de3da57026de // indirect
92-
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
93-
golang.org/x/sys v0.0.0-20220325203850-36772127a21f // indirect
92+
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
93+
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d // indirect
94+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
95+
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
96+
golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2 // indirect
97+
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e // indirect
9498
golang.org/x/text v0.3.7 // indirect
95-
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
96-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
97-
google.golang.org/api v0.68.0 // indirect
99+
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
100+
golang.org/x/tools v0.1.11 // indirect
101+
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
102+
google.golang.org/api v0.85.0 // indirect
98103
google.golang.org/appengine v1.6.7 // indirect
99-
google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb // indirect
100-
google.golang.org/grpc v1.45.0 // indirect
104+
google.golang.org/genproto v0.0.0-20220712132514-bdd2acd4974d // indirect
105+
google.golang.org/grpc v1.48.0 // indirect
101106
google.golang.org/protobuf v1.28.0 // indirect
102107
gopkg.in/inf.v0 v0.9.1 // indirect
103108
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
104-
gopkg.in/validator.v2 v2.0.0-20210331031555-b37d688a7fb0 // indirect
105-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
109+
gopkg.in/validator.v2 v2.0.1 // indirect
110+
gopkg.in/yaml.v3 v3.0.1 // indirect
111+
lukechampine.com/uint128 v1.2.0 // indirect
112+
modernc.org/cc/v3 v3.36.0 // indirect
113+
modernc.org/ccgo/v3 v3.16.6 // indirect
114+
modernc.org/libc v1.16.10 // indirect
115+
modernc.org/mathutil v1.4.1 // indirect
116+
modernc.org/memory v1.1.1 // indirect
117+
modernc.org/opt v0.1.3 // indirect
118+
modernc.org/sqlite v1.17.3 // indirect
119+
modernc.org/strutil v1.1.2 // indirect
120+
modernc.org/token v1.0.0 // indirect
106121
)

0 commit comments

Comments
 (0)