Skip to content

Commit

Permalink
Merge pull request #1028 from julep-ai/f/temporal-api-key
Browse files Browse the repository at this point in the history
feat: Add temporal API key
  • Loading branch information
whiterabbit1983 authored Jan 8, 2025
2 parents 7ba1056 + 8029c00 commit 544f5f8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions agents-api/agents_api/clients/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ..common.protocol.tasks import ExecutionInput
from ..common.retry_policies import DEFAULT_RETRY_POLICY
from ..env import (
temporal_api_key,
temporal_client_cert,
temporal_metrics_bind_host,
temporal_metrics_bind_port,
Expand All @@ -33,18 +34,24 @@ async def get_client(
data_converter=pydantic_data_converter,
):
tls_config = False
rpc_metadata = {}

if temporal_private_key and temporal_client_cert:
tls_config = TLSConfig(
client_cert=temporal_client_cert.encode(),
client_private_key=temporal_private_key.encode(),
)
elif temporal_api_key:
tls_config = True
rpc_metadata = {"temporal-namespace": namespace}

return await Client.connect(
worker_url,
namespace=namespace,
tls=tls_config,
data_converter=data_converter,
api_key=temporal_api_key or None,
rpc_metadata=rpc_metadata,
)


Expand All @@ -54,12 +61,16 @@ async def get_client_with_metrics(
data_converter=pydantic_data_converter,
):
tls_config = False
rpc_metadata = {}

if temporal_private_key and temporal_client_cert:
tls_config = TLSConfig(
client_cert=temporal_client_cert.encode(),
client_private_key=temporal_private_key.encode(),
)
elif temporal_api_key:
tls_config = True
rpc_metadata = {"temporal-namespace": namespace}

new_runtime = Runtime(
telemetry=TelemetryConfig(
Expand All @@ -76,6 +87,8 @@ async def get_client_with_metrics(
data_converter=data_converter,
runtime=new_runtime,
interceptors=[TracingInterceptor()],
api_key=temporal_api_key or None,
rpc_metadata=rpc_metadata,
)


Expand Down
1 change: 1 addition & 0 deletions agents-api/agents_api/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
temporal_namespace: str = env.str("TEMPORAL_NAMESPACE", default="default")
temporal_client_cert: str = env.str("TEMPORAL_CLIENT_CERT", default=None)
temporal_private_key: str = env.str("TEMPORAL_PRIVATE_KEY", default=None)
temporal_api_key: str = env.str("TEMPORAL_API_KEY", default=None)
temporal_endpoint: Any = env.str("TEMPORAL_ENDPOINT", default="localhost:7233")
temporal_task_queue: Any = env.str("TEMPORAL_TASK_QUEUE", default="julep-task-queue")
temporal_schedule_to_close_timeout: int = env.int(
Expand Down
1 change: 1 addition & 0 deletions agents-api/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ x--shared-environment: &shared-environment
TEMPORAL_NAMESPACE: ${TEMPORAL_NAMESPACE:-default}
TEMPORAL_TASK_QUEUE: ${TEMPORAL_TASK_QUEUE:-julep-task-queue}
TEMPORAL_WORKER_URL: ${TEMPORAL_WORKER_URL:-temporal:7233}
TEMPORAL_API_KEY: ${TEMPORAL_API_KEY:-}
TEMPORAL_SCHEDULE_TO_CLOSE_TIMEOUT: ${TEMPORAL_SCHEDULE_TO_CLOSE_TIMEOUT:-3600}
TEMPORAL_METRICS_BIND_HOST: ${TEMPORAL_METRICS_BIND_HOST:-0.0.0.0}
TEMPORAL_METRICS_BIND_PORT: ${TEMPORAL_METRICS_BIND_PORT:-14000}
Expand Down

0 comments on commit 544f5f8

Please sign in to comment.