mirror of https://github.com/tikv/client-rust.git
Merge branch 'master' into minor
This commit is contained in:
commit
cc3002c924
|
@ -18,6 +18,7 @@ integration-tests = []
|
||||||
name = "tikv_client"
|
name = "tikv_client"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
regex = "1"
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
futures-preview = { version = "0.3.0-alpha.15", features = ["compat"] }
|
futures-preview = { version = "0.3.0-alpha.15", features = ["compat"] }
|
||||||
grpcio = { version = "0.5.0-alpha", features = [ "secure", "prost-codec" ], default-features = false }
|
grpcio = { version = "0.5.0-alpha", features = [ "secure", "prost-codec" ], default-features = false }
|
||||||
|
|
|
@ -95,7 +95,7 @@ pub enum ErrorKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fail for Error {
|
impl Fail for Error {
|
||||||
fn cause(&self) -> Option<&Fail> {
|
fn cause(&self) -> Option<&dyn Fail> {
|
||||||
self.inner.cause()
|
self.inner.cause()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,16 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use grpcio::{Channel, ChannelBuilder, ChannelCredentialsBuilder, Environment};
|
use grpcio::{Channel, ChannelBuilder, ChannelCredentialsBuilder, Environment};
|
||||||
|
use lazy_static::*;
|
||||||
use log::*;
|
use log::*;
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref SCHEME_REG: Regex = Regex::new(r"^\s*(https?://)").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
fn check_pem_file(tag: &str, path: &Path) -> Result<File> {
|
fn check_pem_file(tag: &str, path: &Path) -> Result<File> {
|
||||||
File::open(path)
|
File::open(path)
|
||||||
.map_err(|e| internal_err!("failed to open {} to load {}: {:?}", path.display(), tag, e))
|
.map_err(|e| internal_err!("failed to open {} to load {}: {:?}", path.display(), tag, e))
|
||||||
|
@ -65,21 +71,21 @@ impl SecurityManager {
|
||||||
Factory: FnOnce(Channel) -> Client,
|
Factory: FnOnce(Channel) -> Client,
|
||||||
{
|
{
|
||||||
info!("connect to rpc server at endpoint: {:?}", addr);
|
info!("connect to rpc server at endpoint: {:?}", addr);
|
||||||
let addr = addr
|
|
||||||
.trim_start_matches("http://")
|
let addr = SCHEME_REG.replace(addr, "");
|
||||||
.trim_start_matches("https://");
|
|
||||||
let cb = ChannelBuilder::new(env)
|
let cb = ChannelBuilder::new(env)
|
||||||
.keepalive_time(Duration::from_secs(10))
|
.keepalive_time(Duration::from_secs(10))
|
||||||
.keepalive_timeout(Duration::from_secs(3));
|
.keepalive_timeout(Duration::from_secs(3));
|
||||||
|
|
||||||
let channel = if self.ca.is_empty() {
|
let channel = if self.ca.is_empty() {
|
||||||
cb.connect(addr)
|
cb.connect(&addr)
|
||||||
} else {
|
} else {
|
||||||
let cred = ChannelCredentialsBuilder::new()
|
let cred = ChannelCredentialsBuilder::new()
|
||||||
.root_cert(self.ca.clone())
|
.root_cert(self.ca.clone())
|
||||||
.cert(self.cert.clone(), load_pem_file("private key", &self.key)?)
|
.cert(self.cert.clone(), load_pem_file("private key", &self.key)?)
|
||||||
.build();
|
.build();
|
||||||
cb.secure_connect(addr, cred)
|
cb.secure_connect(&addr, cred)
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(factory(channel))
|
Ok(factory(channel))
|
||||||
|
|
Loading…
Reference in New Issue