diff --git a/api/http/handler/websocket/websocket_dial.go b/api/http/handler/websocket/websocket_dial.go new file mode 100644 index 000000000..d5c085787 --- /dev/null +++ b/api/http/handler/websocket/websocket_dial.go @@ -0,0 +1,11 @@ +// +build !windows + +package websocket + +import ( + "net" +) + +func createDial(scheme, host string) (net.Conn, error) { + return net.Dial(scheme, host) +} diff --git a/api/http/handler/websocket/websocket_dial_windows.go b/api/http/handler/websocket/websocket_dial_windows.go new file mode 100644 index 000000000..49a9afd28 --- /dev/null +++ b/api/http/handler/websocket/websocket_dial_windows.go @@ -0,0 +1,16 @@ +// +build windows + +package websocket + +import ( + "net" + + "github.com/Microsoft/go-winio" +) + +func createDial(scheme, host string) (net.Conn, error) { + if scheme == "npipe" { + return winio.DialPipe(host, nil) + } + return net.Dial(scheme, host) +} diff --git a/api/http/handler/websocket/websocket_exec.go b/api/http/handler/websocket/websocket_exec.go index ab0390238..80c62b9d9 100644 --- a/api/http/handler/websocket/websocket_exec.go +++ b/api/http/handler/websocket/websocket_exec.go @@ -127,7 +127,7 @@ func (handler *Handler) proxyWebsocketRequest(w http.ResponseWriter, r *http.Req } func hijackExecStartOperation(websocketConn *websocket.Conn, endpoint *portainer.Endpoint, execID string) error { - dial, err := createDial(endpoint) + dial, err := initDial(endpoint) if err != nil { return err } @@ -158,7 +158,7 @@ func hijackExecStartOperation(websocketConn *websocket.Conn, endpoint *portainer return nil } -func createDial(endpoint *portainer.Endpoint) (net.Conn, error) { +func initDial(endpoint *portainer.Endpoint) (net.Conn, error) { url, err := url.Parse(endpoint.URL) if err != nil { return nil, err @@ -170,26 +170,16 @@ func createDial(endpoint *portainer.Endpoint) (net.Conn, error) { host = url.Path } - var ( - dial net.Conn - dialErr error - ) - if endpoint.TLSConfig.TLS { tlsConfig, err := crypto.CreateTLSConfigurationFromDisk(endpoint.TLSConfig.TLSCACertPath, endpoint.TLSConfig.TLSCertPath, endpoint.TLSConfig.TLSKeyPath, endpoint.TLSConfig.TLSSkipVerify) if err != nil { return nil, err } - dial, dialErr = tls.Dial(url.Scheme, host, tlsConfig) - } else { - if url.Scheme == "npipe" { - dial, dialErr = createWinDial(host) - } else { - dial, dialErr = net.Dial(url.Scheme, host) - } + + return tls.Dial(url.Scheme, host, tlsConfig) } - return dial, dialErr + return createDial(url.Scheme, host) } func createExecStartRequest(execID string) (*http.Request, error) { diff --git a/api/http/handler/websocket/websocket_exec_linux.go b/api/http/handler/websocket/websocket_exec_linux.go deleted file mode 100644 index 99b3e9e7a..000000000 --- a/api/http/handler/websocket/websocket_exec_linux.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build linux - -package websocket - -import ( - "net" -) - -func createWinDial(host string) (net.Conn, error) { - return nil, nil -} diff --git a/api/http/handler/websocket/websocket_exec_windows.go b/api/http/handler/websocket/websocket_exec_windows.go deleted file mode 100644 index 3c9122d98..000000000 --- a/api/http/handler/websocket/websocket_exec_windows.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build windows - -package websocket - -import ( - "net" - - "github.com/Microsoft/go-winio" -) - -func createWinDial(host string) (net.Conn, error) { - return winio.DialPipe(host, nil) -} diff --git a/api/http/proxy/local_linux.go b/api/http/proxy/local_linux.go index af8ed07d6..da154e03c 100644 --- a/api/http/proxy/local_linux.go +++ b/api/http/proxy/local_linux.go @@ -1,4 +1,4 @@ -// +build linux +// +build !windows package proxy