(daemonURL string, sshFlags []string)
| 40 | } |
| 41 | |
| 42 | func getConnectionHelper(daemonURL string, sshFlags []string) (*ConnectionHelper, error) { |
| 43 | u, err := url.Parse(daemonURL) |
| 44 | if err != nil { |
| 45 | return nil, err |
| 46 | } |
| 47 | if u.Scheme == "ssh" { |
| 48 | sp, err := ssh.NewSpec(u) |
| 49 | if err != nil { |
| 50 | return nil, fmt.Errorf("ssh host connection is not valid: %w", err) |
| 51 | } |
| 52 | sshFlags = addSSHTimeout(sshFlags) |
| 53 | sshFlags = disablePseudoTerminalAllocation(sshFlags) |
| 54 | |
| 55 | remoteCommand := []string{"docker", "system", "dial-stdio"} |
| 56 | socketPath := sp.Path |
| 57 | if strings.Trim(sp.Path, "/") != "" { |
| 58 | remoteCommand = []string{"docker", "--host=unix://" + socketPath, "system", "dial-stdio"} |
| 59 | } |
| 60 | sshArgs, err := sp.Command(sshFlags, remoteCommand...) |
| 61 | if err != nil { |
| 62 | return nil, err |
| 63 | } |
| 64 | return &ConnectionHelper{ |
| 65 | Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) { |
| 66 | return commandconn.New(ctx, "ssh", sshArgs...) |
| 67 | }, |
| 68 | Host: "http://docker.example.com", |
| 69 | }, nil |
| 70 | } |
| 71 | // Future version may support plugins via ~/.docker/config.json. e.g. "dind" |
| 72 | // See docker/cli#889 for the previous discussion. |
| 73 | return nil, err |
| 74 | } |
| 75 | |
| 76 | // GetCommandConnectionHelper returns Docker-specific connection helper constructed from an arbitrary command. |
| 77 | func GetCommandConnectionHelper(cmd string, flags ...string) (*ConnectionHelper, error) { |
no test coverage detected
searching dependent graphs…