mirror of https://github.com/tikv/client-rust.git
Resolving the TLS url issue (#459)
* resolving the url issue Signed-off-by: limbooverlambda <schakra1@gmail.com> * fix formatting Signed-off-by: limbooverlambda <schakra1@gmail.com> * make check fixes Signed-off-by: limbooverlambda <schakra1@gmail.com> --------- Signed-off-by: limbooverlambda <schakra1@gmail.com>
This commit is contained in:
parent
54fd72001b
commit
ec8dbccaa3
|
|
@ -8,10 +8,10 @@ use std::time::Duration;
|
|||
|
||||
use log::info;
|
||||
use regex::Regex;
|
||||
use tonic::transport::Certificate;
|
||||
use tonic::transport::Channel;
|
||||
use tonic::transport::ClientTlsConfig;
|
||||
use tonic::transport::Identity;
|
||||
use tonic::transport::{Certificate, Endpoint};
|
||||
|
||||
use crate::internal_err;
|
||||
use crate::Result;
|
||||
|
|
@ -77,28 +77,41 @@ impl SecurityManager {
|
|||
where
|
||||
Factory: FnOnce(Channel) -> Client,
|
||||
{
|
||||
let addr = "http://".to_string() + &SCHEME_REG.replace(addr, "");
|
||||
|
||||
info!("connect to rpc server at endpoint: {:?}", addr);
|
||||
|
||||
let mut builder = Channel::from_shared(addr)?
|
||||
.tcp_keepalive(Some(Duration::from_secs(10)))
|
||||
.keep_alive_timeout(Duration::from_secs(3));
|
||||
|
||||
if !self.ca.is_empty() {
|
||||
let tls = ClientTlsConfig::new()
|
||||
.ca_certificate(Certificate::from_pem(&self.ca))
|
||||
.identity(Identity::from_pem(
|
||||
&self.cert,
|
||||
load_pem_file("private key", &self.key)?,
|
||||
));
|
||||
builder = builder.tls_config(tls)?;
|
||||
let channel = if !self.ca.is_empty() {
|
||||
self.tls_channel(addr).await?
|
||||
} else {
|
||||
self.default_channel(addr).await?
|
||||
};
|
||||
|
||||
let ch = builder.connect().await?;
|
||||
let ch = channel.connect().await?;
|
||||
|
||||
Ok(factory(ch))
|
||||
}
|
||||
|
||||
async fn tls_channel(&self, addr: &str) -> Result<Endpoint> {
|
||||
let addr = "https://".to_string() + &SCHEME_REG.replace(addr, "");
|
||||
let builder = self.endpoint(addr.to_string())?;
|
||||
let tls = ClientTlsConfig::new()
|
||||
.ca_certificate(Certificate::from_pem(&self.ca))
|
||||
.identity(Identity::from_pem(
|
||||
&self.cert,
|
||||
load_pem_file("private key", &self.key)?,
|
||||
));
|
||||
let builder = builder.tls_config(tls)?;
|
||||
Ok(builder)
|
||||
}
|
||||
|
||||
async fn default_channel(&self, addr: &str) -> Result<Endpoint> {
|
||||
let addr = "http://".to_string() + &SCHEME_REG.replace(addr, "");
|
||||
self.endpoint(addr)
|
||||
}
|
||||
|
||||
fn endpoint(&self, addr: String) -> Result<Endpoint> {
|
||||
let endpoint = Channel::from_shared(addr)?
|
||||
.tcp_keepalive(Some(Duration::from_secs(10)))
|
||||
.keep_alive_timeout(Duration::from_secs(3));
|
||||
Ok(endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use std::fmt;
|
||||
use std::ops::Bound;
|
||||
use std::u8;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
|
||||
use std::fmt;
|
||||
use std::u8;
|
||||
|
||||
mod bound_range;
|
||||
pub mod codec;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
use core::ops::Range;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::u32;
|
||||
|
||||
use futures::StreamExt;
|
||||
use log::debug;
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ pub fn new_prewrite_request(
|
|||
req.start_version = start_version;
|
||||
req.lock_ttl = lock_ttl;
|
||||
// FIXME: Lite resolve lock is currently disabled
|
||||
req.txn_size = std::u64::MAX;
|
||||
req.txn_size = u64::MAX;
|
||||
|
||||
req
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue