TemporalEx.Client.Connection (temporal_ex v0.2.1)

Copy Markdown

Pure functions for building gRPC connection options, TLS credentials, and request metadata.

Ported from Temporalio.Client — all side-effect-free except for temporary PEM file writes in resolve_client_mtls_files/1.

Summary

Functions

Converts an API key string to a Bearer authorization header value.

Builds a GRPC.Credential for TLS/mTLS, along with a list of temporary PEM file paths to clean up on shutdown.

Removes temporary PEM files created during mTLS setup.

Formats a gRPC connection error into a human-readable string.

Builds the base gRPC connection options including adapter opts and retry config.

Normalizes a server address, auto-prepending https:// for known Temporal Cloud domains.

Builds gRPC request metadata map from namespace and authorization.

Resolves mTLS client certificate and key from base64-encoded config values.

Functions

authorization_from_api_key(auth)

@spec authorization_from_api_key(String.t() | nil) :: String.t() | nil

Converts an API key string to a Bearer authorization header value.

build_credential(server, config)

@spec build_credential(String.t(), map()) :: {GRPC.Credential.t() | nil, [String.t()]}

Builds a GRPC.Credential for TLS/mTLS, along with a list of temporary PEM file paths to clean up on shutdown.

Returns {credential | nil, temp_pem_file_paths}.

cleanup_temp_pem_files(paths)

@spec cleanup_temp_pem_files([String.t()]) :: :ok

Removes temporary PEM files created during mTLS setup.

format_connect_error(reason)

@spec format_connect_error(term()) :: String.t()

Formats a gRPC connection error into a human-readable string.

grpc_connect_opts(server, config)

@spec grpc_connect_opts(String.t(), map()) :: {keyword(), [String.t()]}

Builds the base gRPC connection options including adapter opts and retry config.

Returns {connect_opts, temp_pem_file_paths}.

normalize_server_address(server)

@spec normalize_server_address(String.t()) :: String.t()

Normalizes a server address, auto-prepending https:// for known Temporal Cloud domains.

Examples

iex> normalize_server_address("my-ns.tmprl.cloud:7233")
"https://my-ns.tmprl.cloud:7233"

iex> normalize_server_address("localhost:7233")
"localhost:7233"

iex> normalize_server_address("https://custom.host:7233")
"https://custom.host:7233"

request_metadata(namespace, authorization)

@spec request_metadata(String.t() | nil, String.t() | nil) :: map()

Builds gRPC request metadata map from namespace and authorization.

resolve_client_mtls_files(config)

@spec resolve_client_mtls_files(map()) ::
  {String.t() | nil, String.t() | nil, [String.t()]}

Resolves mTLS client certificate and key from base64-encoded config values.

Writes decoded PEM data to temporary files and returns their paths.

Returns {cert_path | nil, key_path | nil, temp_file_paths}.