use std::sync::Arc; use tokio::sync::Mutex; use tonic::transport::{Channel, ClientTlsConfig}; use crate::grpc::gen::flux_releaser_client::FluxReleaserClient; pub type FluxReleaserGrpcClient = Arc>>; pub async fn new_client(registry: impl Into) -> anyhow::Result { let registry: String = registry.into(); // Workaround: https://github.com/algesten/ureq/issues/765#issuecomment-2282921492 static INIT: std::sync::Once = std::sync::Once::new(); INIT.call_once(|| { rustls::crypto::aws_lc_rs::default_provider() .install_default() .unwrap(); }); let channel = if registry.starts_with("https") { let tls = ClientTlsConfig::new().with_native_roots(); Channel::from_shared(registry)? .tls_config(tls)? .connect() .await? } else { Channel::from_shared(registry)?.connect().await? }; let client = FluxReleaserClient::new(channel); Ok(Arc::new(Mutex::new(client))) }