mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-04-28 05:30:05 -05:00
d426c9316d
* chore: expose full client to context * chore: update protos * feat: add parent options to trigger * feat: example fanout worker * fix: typehint * feat: add spawn workflow to context * wip: polling and streaming * fix: correct request * chore: rm logging * feat: working polling * feat: functional polling * chore: separate connection * feat: functional streaming and listening * fix: get result payload * fix: increased initial poll interval * release (py): 0.19.0 --------- Co-authored-by: gabriel ruttner <gabe@hatchet.run>
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
from typing import Any
|
|
import grpc
|
|
|
|
|
|
def new_conn(config, aio=False):
|
|
|
|
credentials: grpc.ChannelCredentials | None = None
|
|
|
|
# load channel credentials
|
|
if config.tls_config.tls_strategy == 'tls':
|
|
root: Any | None = None
|
|
|
|
if config.tls_config.ca_file:
|
|
root = open(config.tls_config.ca_file, "rb").read()
|
|
|
|
credentials = grpc.ssl_channel_credentials(root_certificates=root)
|
|
elif config.tls_config.tls_strategy == 'mtls':
|
|
root = open(config.tls_config.ca_file, "rb").read()
|
|
private_key = open(config.tls_config.key_file, "rb").read()
|
|
certificate_chain = open(config.tls_config.cert_file, "rb").read()
|
|
|
|
credentials = grpc.ssl_channel_credentials(
|
|
root_certificates=root, private_key=private_key, certificate_chain=certificate_chain)
|
|
|
|
strat = grpc if not aio else grpc.aio
|
|
|
|
if config.tls_config.tls_strategy == 'none':
|
|
conn = strat.insecure_channel(
|
|
target=config.host_port,
|
|
)
|
|
else:
|
|
conn = strat.secure_channel(
|
|
target=config.host_port,
|
|
credentials=credentials,
|
|
options=[('grpc.ssl_target_name_override',
|
|
config.tls_config.server_name)],
|
|
)
|
|
return conn |