diff --git a/go.mod b/go.mod index f7c4b33..e8360be 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/pcvolkmer/docker-pps go 1.17 require ( + github.com/docker/cli v0.0.0-20191017083524-a8ff7f821017 github.com/docker/docker v20.10.12+incompatible github.com/spf13/pflag v1.0.5 ) diff --git a/go.sum b/go.sum index af28ade..057c91f 100644 --- a/go.sum +++ b/go.sum @@ -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/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/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/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= diff --git a/main.go b/main.go index afbd452..c855e43 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( flag "github.com/spf13/pflag" + "github.com/docker/cli/cli/connhelper" "github.com/docker/docker/api/types" "github.com/docker/docker/client" ) @@ -146,6 +147,16 @@ func contains(uids []string, uid string) bool { func getClientOpts(h *string) []client.Opt { var opts []client.Opt 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, "//") { *h = "tcp://" + *h }