From 2057507a4bd2206516cdf6cc2221aebde5df058d Mon Sep 17 00:00:00 2001 From: amigin Date: Fri, 5 Apr 2024 19:49:37 +0300 Subject: [PATCH] Fixing Ability to runs https requests --- my-grpc-extensions/Cargo.toml | 2 ++ my-grpc-extensions/src/grpc_channel/grpc_channel.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/my-grpc-extensions/Cargo.toml b/my-grpc-extensions/Cargo.toml index db30674..0440efc 100644 --- a/my-grpc-extensions/Cargo.toml +++ b/my-grpc-extensions/Cargo.toml @@ -22,6 +22,8 @@ my-logger = { tag = "1.1.0", git = "https://github.com/MyJetTools/my-logger.git" rust-extensions = { tag = "0.1.4", git = "https://github.com/MyJetTools/rust-extensions.git", features = [ "with-tokio", ] } + +my-tls = { tag = "0.1.1", git = "https://github.com/MyJetTools/my-tls.git" } tokio = { version = "*", features = ["full"] } tonic = { version = "0", features = ["tls", "tls-roots", "prost"] } hyper = { version = "0" } diff --git a/my-grpc-extensions/src/grpc_channel/grpc_channel.rs b/my-grpc-extensions/src/grpc_channel/grpc_channel.rs index 2dd0b9f..76387be 100644 --- a/my-grpc-extensions/src/grpc_channel/grpc_channel.rs +++ b/my-grpc-extensions/src/grpc_channel/grpc_channel.rs @@ -5,7 +5,7 @@ use my_logger::LogEventCtx; use my_telemetry::MyTelemetryContext; use tokio::{sync::Mutex, time::error::Elapsed}; -use tonic::transport::Channel; +use tonic::transport::{Certificate, Channel, ClientTlsConfig}; use crate::{GrpcChannelPool, RentedChannel}; @@ -100,7 +100,13 @@ impl<'s, TService: Send + Sync + 'static> GrpcChannel { ) } - let end_point = end_point.unwrap(); + let mut end_point = end_point.unwrap(); + + if connect_url.to_lowercase().starts_with("https") { + let cert = Certificate::from_pem(my_tls::ALL_CERTIFICATES); + let tls = ClientTlsConfig::new().ca_certificate(cert); + end_point = end_point.tls_config(tls).unwrap(); + } match tokio::time::timeout(self.request_timeout, end_point.connect()).await { Ok(channel) => match channel {