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

feat: Add temporal API key #1028

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
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 = 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 = 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
Loading