Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow host_port to override the server_url from the JWT #243

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions hatchet_sdk/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from .token import get_addresses_from_jwt, get_tenant_id_from_jwt


class ClientTLSConfig:
def __init__(
self,
Expand All @@ -28,14 +27,14 @@ class ClientConfig:

def __init__(
self,
tenant_id: str = None,
tls_config: ClientTLSConfig = None,
token: str = None,
host_port: str = "localhost:7070",
tenant_id: str | None = None,
tls_config: ClientTLSConfig | None = None,
token: str | None = None,
host_port: str | None = None,
server_url: str = "https://app.dev.hatchet-tools.com",
namespace: str = None,
listener_v2_timeout: int = None,
logger: Logger = None,
listener_v2_timeout: int | None = None,
logger: Logger | None = None,
grpc_max_recv_message_length: int = 4 * 1024 * 1024, # 4MB
grpc_max_send_message_length: int = 4 * 1024 * 1024, # 4MB
):
Expand Down Expand Up @@ -87,6 +86,8 @@ def get_config_value(key, env_var):

namespace = get_config_value("namespace", "HATCHET_CLIENT_NAMESPACE")

## TODO: `tenantId` is not an attribute of `ClientConfig`, so `get_config_value` will always return `None`
## if it's not set in the config file or as an environment variable. This should probably be changed to `tenant_id`.
tenant_id = get_config_value("tenantId", "HATCHET_CLIENT_TENANT_ID")
token = get_config_value("token", "HATCHET_CLIENT_TOKEN")
listener_v2_timeout = get_config_value(
Expand All @@ -99,7 +100,7 @@ def get_config_value(key, env_var):
"Token must be set via HATCHET_CLIENT_TOKEN environment variable"
)

host_port = get_config_value("hostPort", "HATCHET_CLIENT_HOST_PORT")
host_port = get_config_value("host_port", "HATCHET_CLIENT_HOST_PORT")
server_url: str | None = None

grpc_max_recv_message_length = get_config_value(
Expand All @@ -117,7 +118,10 @@ def get_config_value(key, env_var):
if grpc_max_send_message_length:
grpc_max_send_message_length = int(grpc_max_send_message_length)

if not host_port:
if host_port:
# if host_port is set, use it to override the server_url
server_url = host_port
else:
# extract host and port from token
server_url, grpc_broadcast_address = get_addresses_from_jwt(token)
host_port = grpc_broadcast_address
Expand Down