Skip to content

Commit

Permalink
Add ca_certificate option
Browse files Browse the repository at this point in the history
  • Loading branch information
c410-f3r committed Dec 16, 2024
1 parent 3192b55 commit 74981d5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions examples/rust/src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use {
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
},
tokio::{fs, sync::Mutex},
tonic::transport::channel::ClientTlsConfig,
tonic::transport::{channel::ClientTlsConfig, Certificate},
yellowstone_grpc_client::{GeyserGrpcClient, GeyserGrpcClientError, Interceptor},
yellowstone_grpc_proto::{
convert_from,
Expand Down Expand Up @@ -48,6 +48,9 @@ type BlocksMetaFilterMap = HashMap<String, SubscribeRequestFilterBlocksMeta>;
#[derive(Debug, Clone, Parser)]
#[clap(author, version, about)]
struct Args {
#[clap(long)]
ca_certificate: Option<String>,

#[clap(short, long, default_value_t = String::from("http://127.0.0.1:10000"))]
/// Service endpoint
endpoint: String,
Expand Down Expand Up @@ -117,9 +120,14 @@ impl Args {
}

async fn connect(&self) -> anyhow::Result<GeyserGrpcClient<impl Interceptor>> {
let mut tls_config = ClientTlsConfig::new().with_native_roots();
if let Some(file_name) = &self.ca_certificate {
let contents = fs::read_to_string(file_name).await?;
tls_config = tls_config.ca_certificate(Certificate::from_pem(contents.as_bytes()));
}
let mut builder = GeyserGrpcClient::build_from_shared(self.endpoint.clone())?
.x_token(self.x_token.clone())?
.tls_config(ClientTlsConfig::new().with_native_roots())?
.tls_config(tls_config)?
.max_decoding_message_size(self.max_decoding_message_size);

if let Some(duration) = self.connect_timeout_ms {
Expand Down

0 comments on commit 74981d5

Please sign in to comment.