Skip to content
This repository was archived by the owner on Oct 19, 2022. It is now read-only.

Commit acb66a4

Browse files
authored
Merge pull request #13 from vieux/add_port
Add port
2 parents 82eed71 + e32908d commit acb66a4

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $ docker plugin install vieux/sshfs # or docker plugin install vieux/sshfs DEBUG
1515
2 - Create a volume
1616

1717
```
18-
$ docker volume create -d vieux/sshfs -o sshcmd=<user@host:path> -o password=<password> sshvolume
18+
$ docker volume create -d vieux/sshfs -o sshcmd=<user@host:path> -o password=<password> [-o port=<port>] sshvolume
1919
sshvolume
2020
$ docker volume ls
2121
DRIVER VOLUME NAME

main.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const socketAddress = "/run/docker/plugins/sshfs.sock"
2121
type sshfsVolume struct {
2222
Password string
2323
Sshcmd string
24+
Port string
2425

2526
Mountpoint string
2627
connections int
@@ -77,11 +78,23 @@ func (d *sshfsDriver) Create(r volume.Request) volume.Response {
7778
d.Lock()
7879
defer d.Unlock()
7980
v := &sshfsVolume{}
80-
if r.Options == nil || r.Options["sshcmd"] == "" {
81-
return responseError("ssh option required")
81+
82+
for key, val := range r.Options {
83+
switch key {
84+
case "sshcmd":
85+
v.Sshcmd = val
86+
case "password":
87+
v.Password = val
88+
case "port":
89+
v.Port = val
90+
default:
91+
return responseError(fmt.Sprintf("unknown option %q", val))
92+
}
93+
}
94+
95+
if v.Sshcmd == "" {
96+
return responseError("'sshcmd' option required")
8297
}
83-
v.Sshcmd = r.Options["sshcmd"]
84-
v.Password = r.Options["password"]
8598
v.Mountpoint = filepath.Join(d.root, fmt.Sprintf("%x", md5.Sum([]byte(v.Sshcmd))))
8699

87100
d.volumes[r.Name] = v
@@ -219,6 +232,9 @@ func (d *sshfsDriver) Capabilities(r volume.Request) volume.Response {
219232

220233
func (d *sshfsDriver) mountVolume(v *sshfsVolume) error {
221234
cmd := fmt.Sprintf("sshfs -oStrictHostKeyChecking=no %s %s", v.Sshcmd, v.Mountpoint)
235+
if v.Port != "" {
236+
cmd = fmt.Sprintf("%s -p %s", cmd, v.Port)
237+
}
222238
if v.Password != "" {
223239
cmd = fmt.Sprintf("echo %s | %s -o workaround=rename -o password_stdin", v.Password, cmd)
224240
}

0 commit comments

Comments
 (0)