tikv-ctl: improve cert error messages
@@ -2262,17 +2262,16 @@ fn new_security_mgr(matches: &ArgMatches<'_>) -> Arc<SecurityManager> {
let key_path = matches.value_of("key_path");
let mut cfg = SecurityConfig::default();
- if ca_path.is_none() && cert_path.is_none() && key_path.is_none() {
- return Arc::new(SecurityManager::new(&cfg).unwrap());
- }
-
if ca_path.is_some() || cert_path.is_some() || key_path.is_some() {
- if ca_path.is_none() || cert_path.is_none() || key_path.is_none() {
- panic!("CA certificate and private key should all be set.");
- }
- cfg.ca_path = ca_path.unwrap().to_owned();
- cfg.cert_path = cert_path.unwrap().to_owned();
- cfg.key_path = key_path.unwrap().to_owned();
+ cfg.ca_path = ca_path
+ .expect("CA path should be set when cert path or key path is set.")
+ .to_owned();
+ cfg.cert_path = cert_path
+ .expect("cert path should be set when CA path or key path is set.")
+ .to_owned();
+ cfg.key_path = key_path
+ .expect("key path should be set when cert path or CA path is set.")
+ .to_owned();
}
Arc::new(SecurityManager::new(&cfg).expect("failed to initialize security manager"))
