From 96005b0f655eea3adc19bec72a480f0512ae767a Mon Sep 17 00:00:00 2001 From: Conner Swann <2635475+yourbuddyconner@users.noreply.github.com> Date: Wed, 16 Oct 2024 22:30:08 -0700 Subject: [PATCH 1/2] fix: add support for tls rpc connections --- crates/sdk/src/network-v2/client.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/crates/sdk/src/network-v2/client.rs b/crates/sdk/src/network-v2/client.rs index a2ad18a2a8..9588c91a06 100644 --- a/crates/sdk/src/network-v2/client.rs +++ b/crates/sdk/src/network-v2/client.rs @@ -14,7 +14,9 @@ use std::str::FromStr; use std::time::{SystemTime, UNIX_EPOCH}; use tokio::sync::OnceCell; use tokio::try_join; +use tonic::transport::channel::ClientTlsConfig; use tonic::transport::Channel; +use tonic::transport::Endpoint; use crate::network_v2::proto::artifact::{ artifact_store_client::ArtifactStoreClient, CreateArtifactRequest, @@ -58,14 +60,32 @@ impl NetworkClient { /// Get a connected RPC client. async fn get_rpc(&self) -> Result> { let rpc_url = Self::rpc_url(); - let channel = Channel::from_shared(rpc_url)?.connect().await?; - Ok(ProverNetworkClient::new(channel.clone())) + let mut endpoint = Channel::from_shared(rpc_url.clone())?; + + // Check if the URL scheme is HTTPS and configure TLS + if rpc_url.starts_with("https://") { + println!("Using TLS"); + let tls_config = ClientTlsConfig::new().with_enabled_roots(); + endpoint = endpoint.tls_config(tls_config)?; + } + + let channel = endpoint.connect().await?; + Ok(ProverNetworkClient::new(channel)) } /// Get a connected artifact store client. async fn get_store(&self) -> Result> { let rpc_url = Self::rpc_url(); - let channel = Channel::from_shared(rpc_url)?.connect().await?; + let mut endpoint = Channel::from_shared(rpc_url.clone())?; + + // Check if the URL scheme is HTTPS and configure TLS + if rpc_url.starts_with("https://") { + println!("Using TLS"); + let tls_config = ClientTlsConfig::new().with_enabled_roots(); + endpoint = endpoint.tls_config(tls_config)?; + } + + let channel = endpoint.connect().await?; Ok(ArtifactStoreClient::new(channel.clone())) } @@ -203,6 +223,9 @@ impl NetworkClient { let response = self.http.put(&presigned_url).body(bincode::serialize::(item)?).send().await?; + if !response.status().is_success() { + log::debug!("Artifact upload failed with status: {}", response.status()); + } assert!(response.status().is_success()); Ok(uri) From cad7ed8a74d950e4f98089ecb5fa2588629f9e50 Mon Sep 17 00:00:00 2001 From: Conner Swann <2635475+yourbuddyconner@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:18:15 -0700 Subject: [PATCH 2/2] nits --- crates/sdk/src/network-v2/client.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/sdk/src/network-v2/client.rs b/crates/sdk/src/network-v2/client.rs index 9588c91a06..362d7a08c5 100644 --- a/crates/sdk/src/network-v2/client.rs +++ b/crates/sdk/src/network-v2/client.rs @@ -16,7 +16,6 @@ use tokio::sync::OnceCell; use tokio::try_join; use tonic::transport::channel::ClientTlsConfig; use tonic::transport::Channel; -use tonic::transport::Endpoint; use crate::network_v2::proto::artifact::{ artifact_store_client::ArtifactStoreClient, CreateArtifactRequest, @@ -62,7 +61,7 @@ impl NetworkClient { let rpc_url = Self::rpc_url(); let mut endpoint = Channel::from_shared(rpc_url.clone())?; - // Check if the URL scheme is HTTPS and configure TLS + // Check if the URL scheme is HTTPS and configure TLS. if rpc_url.starts_with("https://") { println!("Using TLS"); let tls_config = ClientTlsConfig::new().with_enabled_roots(); @@ -78,7 +77,7 @@ impl NetworkClient { let rpc_url = Self::rpc_url(); let mut endpoint = Channel::from_shared(rpc_url.clone())?; - // Check if the URL scheme is HTTPS and configure TLS + // Check if the URL scheme is HTTPS and configure TLS. if rpc_url.starts_with("https://") { println!("Using TLS"); let tls_config = ClientTlsConfig::new().with_enabled_roots();