Class WorkerApiEndpoint
- Namespace
- Virtufin.Worker.DevKit
- Assembly
- Virtufin.Worker.DevKit.dll
How a worker reaches the API Gateway, and with which credential. A worker
runs inside its host process (WorkManager / WorkManager Runtime), whose
environment names the cluster's gateway (HostEnvVar,
PortEnvVar) and carries the host's own gateway key
(ApiKeyEnvVar, from the api-auth secret). The gateway
rejects every non-health call without a valid key once any key is
configured, so a client built without one cannot save state or publish.
The key is only attached when the target IS that configured
gateway: an api_host arriving in a command event or worker config
could otherwise steer the host's credential to an arbitrary endpoint.
Any other target gets no key.
TLS: in-cluster gateways are plaintext, but a worker run outside the
cluster (a notebook, a local test) reaches the gateway through its TLS
ingress. TlsEnvVar marks the host's gateway as TLS, and an
explicit endpoint of the form https://host[:port] (default port 443)
asks for TLS (ResolveEndpoint(string?, Func<string, string?>?)). A TLS gateway's key is never
sent in plaintext, nor a plaintext gateway's over TLS.
public static class WorkerApiEndpoint
- Inheritance
-
WorkerApiEndpoint
- Inherited Members
Fields
ApiKeyEnvVar
Env var carrying the host process's own gateway key.
public const string ApiKeyEnvVar = "VIRTUFIN_API_KEY"
Field Value
DefaultHost
Host used when HostEnvVar is unset (local development).
public const string DefaultHost = "localhost"
Field Value
DefaultPort
Port used when PortEnvVar is unset or invalid.
public const int DefaultPort = 5002
Field Value
DefaultTlsPort
Default port of an https:// endpoint.
public const int DefaultTlsPort = 443
Field Value
HostEnvVar
Env var naming the gateway host the host process uses.
public const string HostEnvVar = "VIRTUFIN_API_HOST"
Field Value
PortEnvVar
Env var naming the gateway gRPC port the host process uses.
public const string PortEnvVar = "VIRTUFIN_API_GRPC_PORT"
Field Value
TlsEnvVar
Env var: true/1 when the host's gateway speaks TLS (default plaintext).
public const string TlsEnvVar = "VIRTUFIN_API_TLS"
Field Value
Methods
ApiKeyFor(string, int)
The host process's gateway key if host:port
is the configured gateway, else null.
public static string? ApiKeyFor(string host, int port)
Parameters
Returns
ApiKeyFor(string, int, bool, Func<string, string?>?)
The host's gateway key, but only for its configured gateway dialled with its configured transport.
public static string? ApiKeyFor(string host, int port, bool tls, Func<string, string?>? getEnv = null)
Parameters
Returns
ApiKeyFor(string, int, Func<string, string?>)
The host process's gateway key if host:port
is the configured gateway, else null; the environment is read through getEnv.
public static string? ApiKeyFor(string host, int port, Func<string, string?> getEnv)
Parameters
Returns
Configured()
The gateway the host process is configured for.
public static (string Host, int Port) Configured()
Returns
Configured(Func<string, string?>)
The gateway the host process is configured for, reading the environment through getEnv.
public static (string Host, int Port) Configured(Func<string, string?> getEnv)
Parameters
Returns
ConfiguredTls(Func<string, string?>?)
Whether the host's gateway speaks TLS (TlsEnvVar).
public static bool ConfiguredTls(Func<string, string?>? getEnv = null)
Parameters
Returns
CreateClient()
A client for the configured gateway, with the host's key.
public static ApiClient CreateClient()
Returns
- ApiClient
CreateClient(string, int)
A plaintext (in-cluster) client for host:port,
carrying the host's key when that is the configured gateway.
public static ApiClient CreateClient(string host, int port)
Parameters
Returns
- ApiClient
CreateClient(string, int, bool)
A client for host:port over TLS or
plaintext, carrying the host's key only for its configured gateway and transport.
public static ApiClient CreateClient(string host, int port, bool tls)
Parameters
Returns
- ApiClient
ResolveEndpoint(string?, Func<string, string?>?)
The gateway to dial: an explicit endpoint
(host[:port] plaintext, http://host[:port], or
https://host[:port] with TLS, default port 443), else the host's
configured gateway with its TlsEnvVar setting.
public static (string Host, int Port, bool Tls) ResolveEndpoint(string? endpoint, Func<string, string?>? getEnv = null)