-
-
Notifications
You must be signed in to change notification settings - Fork 118
Replace some of the unwrap() calls #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
ffe7a9a
1311ce2
c7f964d
f1e58cc
f681d70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,24 +48,18 @@ fn get_http_connector() -> HttpConnector { | |
} | ||
|
||
#[cfg(feature = "tls")] | ||
fn get_docker_for_tcp(tcp_host_str: String) -> Docker { | ||
fn get_docker_for_tcp(tcp_host_str: String) -> Result<Docker> { | ||
let http = get_http_connector(); | ||
if let Ok(ref certs) = env::var("DOCKER_CERT_PATH") { | ||
// fixme: don't unwrap before you know what's in the box | ||
// https://github.com/hyperium/hyper/blob/master/src/net.rs#L427-L428 | ||
let mut connector = SslConnector::builder(SslMethod::tls()).unwrap(); | ||
connector.set_cipher_list("DEFAULT").unwrap(); | ||
let mut connector = SslConnector::builder(SslMethod::tls())?; | ||
connector.set_cipher_list("DEFAULT")?; | ||
let cert = &format!("{}/cert.pem", certs); | ||
let key = &format!("{}/key.pem", certs); | ||
connector | ||
.set_certificate_file(&Path::new(cert), SslFiletype::PEM) | ||
.unwrap(); | ||
connector | ||
.set_private_key_file(&Path::new(key), SslFiletype::PEM) | ||
.unwrap(); | ||
connector.set_certificate_file(&Path::new(cert), SslFiletype::PEM)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of the generic Ssl error, we could map to a variant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SSL error can be returned not just here, it will be generated, for example in docker.rs at line 54: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we would need more than one variant, not just Which is why I said "feel free to ignore if you think it becomes too verbose" :) A general Ssl error is certainly more concise but the error messages will be less helpful because it is not as clear where the error originated. |
||
connector.set_private_key_file(&Path::new(key), SslFiletype::PEM)?; | ||
if env::var("DOCKER_TLS_VERIFY").is_ok() { | ||
let ca = &format!("{}/ca.pem", certs); | ||
connector.set_ca_file(&Path::new(ca)).unwrap(); | ||
connector.set_ca_file(&Path::new(ca))?; | ||
} | ||
|
||
// If we are attempting to connec to the docker daemon via tcp | ||
|
@@ -78,32 +72,31 @@ fn get_docker_for_tcp(tcp_host_str: String) -> Docker { | |
tcp_host_str | ||
}; | ||
|
||
Docker { | ||
Ok(Docker { | ||
transport: Transport::EncryptedTcp { | ||
client: Client::builder() | ||
.build(HttpsConnector::with_connector(http, connector).unwrap()), | ||
client: Client::builder().build(HttpsConnector::with_connector(http, connector)?), | ||
host: tcp_host_str, | ||
}, | ||
} | ||
}) | ||
} else { | ||
Docker { | ||
Ok(Docker { | ||
transport: Transport::Tcp { | ||
client: Client::builder().build(http), | ||
host: tcp_host_str, | ||
}, | ||
} | ||
}) | ||
} | ||
} | ||
|
||
#[cfg(not(feature = "tls"))] | ||
fn get_docker_for_tcp(tcp_host_str: String) -> Docker { | ||
fn get_docker_for_tcp(tcp_host_str: String) -> Result<Docker> { | ||
let http = get_http_connector(); | ||
Docker { | ||
Ok(Docker { | ||
transport: Transport::Tcp { | ||
client: Client::builder().build(http), | ||
host: tcp_host_str, | ||
}, | ||
} | ||
}) | ||
} | ||
|
||
// https://docs.docker.com/reference/api/docker_remote_api_v1.17/ | ||
|
@@ -165,7 +158,7 @@ impl Docker { | |
#[cfg(not(feature = "unix-socket"))] | ||
Some("unix") => panic!("Unix socket support is disabled"), | ||
|
||
_ => get_docker_for_tcp(tcp_host_str), | ||
_ => get_docker_for_tcp(tcp_host_str).unwrap(), | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this actually ever fail?
unwrap
/expect
seems to be ok here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is right. Thanks for your advice a lot