1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-25 08:19:40 +02:00

feat(api): Add npipe support (#2018)

This commit is contained in:
Olli Janatuinen 2018-07-20 12:02:06 +03:00 committed by Anthony Lapenna
parent 0368c4e937
commit 4129550d44
17 changed files with 133 additions and 43 deletions

View file

@ -2,8 +2,8 @@ package endpoints
import (
"net/http"
"runtime"
"strconv"
"strings"
"github.com/portainer/portainer"
"github.com/portainer/portainer/crypto"
@ -109,7 +109,7 @@ func (payload *endpointCreatePayload) Validate(r *http.Request) error {
}
payload.AzureAuthenticationKey = azureAuthenticationKey
default:
url, err := request.RetrieveMultiPartFormValue(r, "URL", false)
url, err := request.RetrieveMultiPartFormValue(r, "URL", true)
if err != nil {
return portainer.Error("Invalid endpoint URL")
}
@ -192,7 +192,12 @@ func (handler *Handler) createAzureEndpoint(payload *endpointCreatePayload) (*po
func (handler *Handler) createUnsecuredEndpoint(payload *endpointCreatePayload) (*portainer.Endpoint, *httperror.HandlerError) {
endpointType := portainer.DockerEnvironment
if !strings.HasPrefix(payload.URL, "unix://") {
if payload.URL == "" {
payload.URL = "unix:///var/run/docker.sock"
if runtime.GOOS == "windows" {
payload.URL = "npipe:////./pipe/docker_engine"
}
} else {
agentOnDockerEnvironment, err := client.ExecutePingOperation(payload.URL, nil)
if err != nil {
return nil, &httperror.HandlerError{http.StatusInternalServerError, "Unable to ping Docker environment", err}

View file

@ -164,22 +164,32 @@ func createDial(endpoint *portainer.Endpoint) (net.Conn, error) {
return nil, err
}
var host string
if url.Scheme == "tcp" {
host = url.Host
} else if url.Scheme == "unix" {
host := url.Host
if url.Scheme == "unix" || url.Scheme == "npipe" {
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
}
return tls.Dial(url.Scheme, host, tlsConfig)
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 net.Dial(url.Scheme, host)
return dial, dialErr
}
func createExecStartRequest(execID string) (*http.Request, error) {

View file

@ -0,0 +1,11 @@
// +build linux
package websocket
import (
"net"
)
func createWinDial(host string) (net.Conn, error) {
return nil, nil
}

View file

@ -0,0 +1,13 @@
// +build windows
package websocket
import (
"net"
"github.com/Microsoft/go-winio"
)
func createWinDial(host string) (net.Conn, error) {
return winio.DialPipe(host, nil)
}