Skip to content

Commit d221e02

Browse files
authored
Merge branch 'master' into rpc
2 parents 2ebf3c0 + 89b1242 commit d221e02

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ integration-tests = []
1818
name = "tikv_client"
1919

2020
[dependencies]
21+
regex = "1"
2122
failure = "0.1"
2223
futures-preview = { version = "0.3.0-alpha.15", features = ["compat"] }
2324
grpcio = { version = "0.5.0-alpha", features = [ "secure", "prost-codec" ], default-features = false }

src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub enum ErrorKind {
9595
}
9696

9797
impl Fail for Error {
98-
fn cause(&self) -> Option<&Fail> {
98+
fn cause(&self) -> Option<&dyn Fail> {
9999
self.inner.cause()
100100
}
101101

src/rpc/security.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ use std::{
99
};
1010

1111
use grpcio::{Channel, ChannelBuilder, ChannelCredentialsBuilder, Environment};
12+
use lazy_static::*;
1213
use log::*;
14+
use regex::Regex;
1315

1416
use crate::Result;
1517

18+
lazy_static! {
19+
static ref SCHEME_REG: Regex = Regex::new(r"^\s*(https?://)").unwrap();
20+
}
21+
1622
fn check_pem_file(tag: &str, path: &Path) -> Result<File> {
1723
File::open(path)
1824
.map_err(|e| internal_err!("failed to open {} to load {}: {:?}", path.display(), tag, e))
@@ -65,21 +71,21 @@ impl SecurityManager {
6571
Factory: FnOnce(Channel) -> Client,
6672
{
6773
info!("connect to rpc server at endpoint: {:?}", addr);
68-
let addr = addr
69-
.trim_start_matches("http://")
70-
.trim_start_matches("https://");
74+
75+
let addr = SCHEME_REG.replace(addr, "");
76+
7177
let cb = ChannelBuilder::new(env)
7278
.keepalive_time(Duration::from_secs(10))
7379
.keepalive_timeout(Duration::from_secs(3));
7480

7581
let channel = if self.ca.is_empty() {
76-
cb.connect(addr)
82+
cb.connect(&addr)
7783
} else {
7884
let cred = ChannelCredentialsBuilder::new()
7985
.root_cert(self.ca.clone())
8086
.cert(self.cert.clone(), load_pem_file("private key", &self.key)?)
8187
.build();
82-
cb.secure_connect(addr, cred)
88+
cb.secure_connect(&addr, cred)
8389
};
8490

8591
Ok(factory(channel))

0 commit comments

Comments
 (0)