Skip to content
Draft
Show file tree
Hide file tree
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
36 changes: 36 additions & 0 deletions client_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
from temporalio.client import Client, TLSConfig

async def get_temporal_client() -> Client:
cert_path = os.getenv("TEMPORAL_TLS_CERT")
key_path = os.getenv("TEMPORAL_TLS_KEY")
api_key = os.getenv("TEMPORAL_API_KEY")

# Check for mTLS authentication
if cert_path and key_path:
with open(cert_path, "rb") as f:
client_cert = f.read()
with open(key_path, "rb") as f:
client_key = f.read()

return await Client.connect(
os.getenv("TEMPORAL_ADDRESS"),
namespace=os.getenv("TEMPORAL_NAMESPACE"),
tls=TLSConfig(
client_cert=client_cert,
client_private_key=client_key,
),
)
elif api_key:
return await Client.connect(
os.getenv("TEMPORAL_ADDRESS"),
namespace=os.getenv("TEMPORAL_NAMESPACE"),
api_key=api_key,
tls=True,
)

else:
return await Client.connect(
os.getenv("TEMPORAL_ADDRESS", "localhost:7233"),
namespace=os.getenv("TEMPORAL_NAMESPACE", "default"),
)
3 changes: 2 additions & 1 deletion run_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
from temporalio.client import Client
from temporalio.worker import Worker

from client_provider import get_temporal_client
from activities import BankingActivities
from shared import MONEY_TRANSFER_TASK_QUEUE_NAME
from workflows import MoneyTransfer


async def main() -> None:
client: Client = await Client.connect("localhost:7233", namespace="default")
client = await get_temporal_client()
# Run the worker
activities = BankingActivities()
worker: Worker = Worker(
Expand Down
4 changes: 2 additions & 2 deletions run_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

from temporalio.client import Client, WorkflowFailureError

from client_provider import get_temporal_client
from shared import MONEY_TRANSFER_TASK_QUEUE_NAME, PaymentDetails
from workflows import MoneyTransfer


async def main() -> None:
# Create client connected to server at the given address
client: Client = await Client.connect("localhost:7233")
client = await get_temporal_client()

data: PaymentDetails = PaymentDetails(
source_account="85-150",
Expand Down