1
0
mirror of https://github.com/pcvolkmer/docker-pps.git synced 2025-04-19 17:56:50 +00:00

Add SSH connection handling

This commit is contained in:
Paul-Christian Volkmer 2022-03-02 11:01:22 +01:00
parent f831c02e12
commit 693eeb8ebf
3 changed files with 13 additions and 0 deletions

1
go.mod
View File

@ -3,6 +3,7 @@ module github.com/pcvolkmer/docker-pps
go 1.17 go 1.17
require ( require (
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017
github.com/docker/docker v20.10.12+incompatible github.com/docker/docker v20.10.12+incompatible
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
) )

1
go.sum
View File

@ -289,6 +289,7 @@ github.com/dgrijalva/jwt-go v0.0.0-20170104182250-a601269ab70c/go.mod h1:E3ru+11
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017 h1:2HQmlpI3yI9deH18Q6xiSOIjXD4sLI55Y/gfpa8/558=
github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v0.0.0-20190905152932-14b96e55d84c/go.mod h1:0+TTO4EOBfRPhZXAeF1Vu+W3hHZ8eLp8PgKVZlcvtFY= github.com/docker/distribution v0.0.0-20190905152932-14b96e55d84c/go.mod h1:0+TTO4EOBfRPhZXAeF1Vu+W3hHZ8eLp8PgKVZlcvtFY=
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=

11
main.go
View File

@ -9,6 +9,7 @@ import (
flag "github.com/spf13/pflag" flag "github.com/spf13/pflag"
"github.com/docker/cli/cli/connhelper"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/client" "github.com/docker/docker/client"
) )
@ -146,6 +147,16 @@ func contains(uids []string, uid string) bool {
func getClientOpts(h *string) []client.Opt { func getClientOpts(h *string) []client.Opt {
var opts []client.Opt var opts []client.Opt
if *h != "" { if *h != "" {
// SSH
if strings.HasPrefix(*h, "ssh://") {
if helper, err := connhelper.GetConnectionHelper(*h); err == nil {
opts = append(opts, client.WithDialContext(helper.Dialer))
} else {
log.Fatal(err)
}
}
// TCP/HTTP
if !strings.Contains(*h, "//") { if !strings.Contains(*h, "//") {
*h = "tcp://" + *h *h = "tcp://" + *h
} }