clientFromDiscovery function
Creates a gRPC KumihoClient using Control Plane discovery.
- Uses discovery to find the correct data-plane endpoint.
- Sets
tenantIdso the base client injectsx-tenant-id. - If
tokenis omitted, the client falls back to the standard token loader.
Implementation
Future<KumihoClient> clientFromDiscovery({
String? token,
String? tenantHint,
String? controlPlaneUrl,
bool forceRefresh = false,
}) async {
final record = await discoverTenant(
controlPlaneUrl: controlPlaneUrl,
tenantHint: tenantHint,
forceRefresh: forceRefresh,
);
final uri = record.serverUrl;
final secure = uri.scheme.toLowerCase() == 'https';
final port = uri.hasPort ? uri.port : (secure ? 443 : 80);
return KumihoClient(
host: uri.host,
port: port,
secure: secure,
token: token,
tenantId: record.tenantId,
);
}