MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / build_mtls_channel

Function build_mtls_channel

crates/openshell-tui/src/lib.rs:566–594  ·  view source on GitHub ↗

Build a gRPC channel using mTLS client certificates.

(name: &str, endpoint: &str)

Source from the content-addressed store, hash-verified

564
565/// Build a gRPC channel using mTLS client certificates.
566async fn build_mtls_channel(name: &str, endpoint: &str) -> Result<Channel> {
567 let mtls_dir = gateway_mtls_dir(name)
568 .ok_or_else(|| miette::miette!("cannot determine config directory for gateway {name}"))?;
569
570 let ca = std::fs::read(mtls_dir.join("ca.crt"))
571 .into_diagnostic()
572 .map_err(|_| miette::miette!("missing CA cert for gateway {name}"))?;
573 let cert = std::fs::read(mtls_dir.join("tls.crt"))
574 .into_diagnostic()
575 .map_err(|_| miette::miette!("missing client cert for gateway {name}"))?;
576 let key = std::fs::read(mtls_dir.join("tls.key"))
577 .into_diagnostic()
578 .map_err(|_| miette::miette!("missing client key for gateway {name}"))?;
579
580 let tls_config = ClientTlsConfig::new()
581 .ca_certificate(Certificate::from_pem(ca))
582 .identity(Identity::from_pem(cert, key));
583
584 Endpoint::from_shared(endpoint.to_string())
585 .into_diagnostic()?
586 .connect_timeout(Duration::from_secs(10))
587 .http2_keep_alive_interval(Duration::from_secs(10))
588 .keep_alive_while_idle(true)
589 .tls_config(tls_config)
590 .into_diagnostic()?
591 .connect()
592 .await
593 .into_diagnostic()
594}
595
596/// Resolve the mTLS cert directory for a gateway.
597fn gateway_mtls_dir(name: &str) -> Option<PathBuf> {

Callers 1

connect_to_gatewayFunction · 0.85

Calls 2

gateway_mtls_dirFunction · 0.85
connectMethod · 0.45

Tested by

no test coverage detected