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

Function build_oidc_channel

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

Build an HTTPS channel for OIDC-authenticated gateways. Tries mTLS client certs for the transport layer when available (the server may still require them alongside the bearer token), falls back to CA-only or system roots.

(name: &str, endpoint: &str)

Source from the content-addressed store, hash-verified

529/// may still require them alongside the bearer token), falls back to CA-only
530/// or system roots.
531async fn build_oidc_channel(name: &str, endpoint: &str) -> Result<Channel> {
532 let mtls_dir = gateway_mtls_dir(name);
533
534 let tls_config = mtls_dir.as_ref().map_or_else(
535 || ClientTlsConfig::new().with_enabled_roots(),
536 |dir| {
537 let ca = std::fs::read(dir.join("ca.crt")).ok();
538 let cert = std::fs::read(dir.join("tls.crt")).ok();
539 let key = std::fs::read(dir.join("tls.key")).ok();
540
541 match (ca, cert, key) {
542 (Some(ca), Some(cert), Some(key)) => ClientTlsConfig::new()
543 .ca_certificate(Certificate::from_pem(ca))
544 .identity(Identity::from_pem(cert, key)),
545 (Some(ca), _, _) => {
546 ClientTlsConfig::new().ca_certificate(Certificate::from_pem(ca))
547 }
548 _ => ClientTlsConfig::new().with_enabled_roots(),
549 }
550 },
551 );
552
553 Endpoint::from_shared(endpoint.to_string())
554 .into_diagnostic()?
555 .connect_timeout(Duration::from_secs(10))
556 .http2_keep_alive_interval(Duration::from_secs(10))
557 .keep_alive_while_idle(true)
558 .tls_config(tls_config)
559 .into_diagnostic()?
560 .connect()
561 .await
562 .into_diagnostic()
563}
564
565/// Build a gRPC channel using mTLS client certificates.
566async fn build_mtls_channel(name: &str, endpoint: &str) -> Result<Channel> {

Callers 1

connect_to_gatewayFunction · 0.85

Calls 2

gateway_mtls_dirFunction · 0.85
connectMethod · 0.45

Tested by

no test coverage detected