passivized_docker_engine_client/imp/
env.rs

1use std::env::VarError;
2use log::warn;
3
4/// A default configuration is only available on Linux and Mac systems.
5///
6/// Docker Engine on Windows uses named pipes by default, but this Rust
7/// library does not support named pipes.
8#[cfg(not(windows))]
9pub(crate) fn default_server() -> String {
10    #[cfg(unix)]
11    return "/var/run/docker.sock".to_string();
12
13    #[cfg(not(unix))]
14    return "tcp://localhost:2375".to_string();
15}
16
17pub(crate) fn docker_host() -> Option<String> {
18    match std::env::var("DOCKER_HOST") {
19        Err(e) => {
20            match e {
21                VarError::NotPresent => {
22                    None
23                }
24                _ => {
25                    warn!("Unable to read DOCKER_HOST environment variable: {}", e);
26                    None
27                }
28            }
29        },
30        Ok(value) => {
31            Some(value)
32        }
33    }
34}
35
36#[cfg(test)]
37mod test_docker_host {
38    use super::docker_host;
39
40    #[test]
41    fn gets() {
42        // While it may not be present on the machine running the tests,
43        // attempting to get the value should never fail.
44
45        docker_host();
46    }
47
48}