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

Add a Docker::connect_with_url() method #395

Open
xfbs opened this issue Mar 25, 2024 · 2 comments
Open

Add a Docker::connect_with_url() method #395

xfbs opened this issue Mar 25, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@xfbs
Copy link

xfbs commented Mar 25, 2024

Could we have a connect_with_url() method? I'm thinking to basically move use what you are doing in connect_with_defaults, and then call this method from connect with defaults().

    pub fn connect_with_defaults() -> Result<Docker, Error> {
        let host = env::var("DOCKER_HOST").unwrap_or_else(|_| DEFAULT_DOCKER_HOST.to_string());
        Self::connect_with_url(host)
    }

    pub fn connect_with_url(host: &str) -> Result<Docker, Error> {
        match host {
            #[cfg(unix)]
            h if h.starts_with("unix://") => {
                Docker::connect_with_unix(&h, DEFAULT_TIMEOUT, API_DEFAULT_VERSION)
            }
            #[cfg(windows)]
            h if h.starts_with("npipe://") => {
                Docker::connect_with_named_pipe(&h, DEFAULT_TIMEOUT, API_DEFAULT_VERSION)
            }
            h if h.starts_with("tcp://") || h.starts_with("http://") => {
                #[cfg(feature = "ssl")]
                if env::var("DOCKER_TLS_VERIFY").is_ok() {
                    return Docker::connect_with_ssl_defaults();
                }
                Docker::connect_with_http_defaults()
            }
            #[cfg(feature = "ssl")]
            h if h.starts_with("https://") => Docker::connect_with_ssl_defaults(),
            _ => Err(UnsupportedURISchemeError {
                uri: host.to_string(),
            }),
        }
    }
@fussybeaver
Copy link
Owner

We recently added a connect_with_defaults method which sources that DOCKER_HOST environment variable

pub fn connect_with_defaults() -> Result<Docker, Error> {
. I'd be happy for a PR that extends or refactors this method to accept a connect_with_url invocation

@fussybeaver fussybeaver added the enhancement New feature or request label Mar 29, 2024
@eddumelendez
Copy link

Hi, jumping here because I'm also interested in this issue. It would be nice to allow setting headers as well to set custom User-Agent from clients consuming the library. It would be even much better to accept a http request to make the client fully configurable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants