Skip to content
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

Make Unix socket support optional #92

Merged
merged 2 commits into from
Sep 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ byteorder = "1.0.0"
flate2 = "0.2"
hyper = "0.10"
hyper-openssl = "0.2"
hyperlocal = "0.3"
hyperlocal = { version = "0.3", optional = true }
jed = "0.1"
log = "0.3"
openssl = "0.9"
Expand All @@ -27,3 +27,7 @@ serde_derive = "1.0"

[dev-dependencies]
env_logger = "0.4.0"

[features]
default = ["unix-socket"]
unix-socket = ["hyperlocal"]
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
extern crate log;
extern crate hyper;
extern crate hyper_openssl;
#[cfg(feature = "unix-socket")]
extern crate hyperlocal;
extern crate flate2;
extern crate jed;
Expand Down Expand Up @@ -49,7 +50,6 @@ use hyper::header::ContentType;
use hyper::method::Method;
use hyper::net::HttpsConnector;
use hyper_openssl::OpensslClient;
use hyperlocal::UnixSocketConnector;
use openssl::ssl::{SslConnectorBuilder, SslMethod};
use openssl::x509::X509_FILETYPE_PEM;
use rep::{Change, Container as ContainerRep, ContainerCreateInfo,
Expand Down Expand Up @@ -641,14 +641,19 @@ impl Docker {
/// constructs a new Docker instance for docker host listening at the given host url
pub fn host(host: Url) -> Docker {
match host.scheme() {
#[cfg(feature = "unix-socket")]
"unix" => {
Docker {
transport: Transport::Unix {
client: Client::with_connector(UnixSocketConnector),
client: Client::with_connector(hyperlocal::UnixSocketConnector),
path: host.path().to_owned(),
},
}
}

#[cfg(not(feature = "unix-socket"))]
"unix" => panic!("Unix socket support is disabled"),
softprops marked this conversation as resolved.
Show resolved Hide resolved

_ => {
let client = if let Some(ref certs) = env::var(
"DOCKER_CERT_PATH",
Expand Down
8 changes: 6 additions & 2 deletions src/transport.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Transports for communicating with the docker daemon

extern crate hyper;
#[cfg(feature = "unix-socket")]
extern crate hyperlocal;

use self::hyper::buffer::BufReader;
use self::hyper::header::ContentType;
Expand All @@ -12,7 +14,6 @@ use hyper::client::response::Response;
use hyper::header;
use hyper::method::Method;
use hyper::mime;
use hyperlocal::DomainUrl;
use rustc_serialize::json;
use std::fmt;
use std::io::Read;
Expand All @@ -31,13 +32,15 @@ pub enum Transport {
/// A network tcp interface
Tcp { client: Client, host: String },
/// A Unix domain socket
#[cfg(feature = "unix-socket")]
Unix { client: Client, path: String },
}

impl fmt::Debug for Transport {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Transport::Tcp { ref host, .. } => write!(f, "Tcp({})", host),
#[cfg(feature = "unix-socket")]
Transport::Unix { ref path, .. } => write!(f, "Unix({})", path),
}
}
Expand Down Expand Up @@ -82,10 +85,11 @@ impl Transport {
ref client,
ref host,
} => client.request(method, &format!("{}{}", host, endpoint)[..]),
#[cfg(feature = "unix-socket")]
Transport::Unix {
ref client,
ref path,
} => client.request(method, DomainUrl::new(&path, endpoint)),
} => client.request(method, hyperlocal::DomainUrl::new(&path, endpoint)),
}.headers(headers);

let embodied = match body {
Expand Down