@@ -28,6 +28,7 @@ type sshfsVolume struct {
28
28
29
29
Mountpoint string
30
30
connections int
31
+ ID_RSA string
31
32
}
32
33
33
34
type sshfsDriver struct {
@@ -90,6 +91,8 @@ func (d *sshfsDriver) Create(r *volume.CreateRequest) error {
90
91
v .Password = val
91
92
case "port" :
92
93
v .Port = val
94
+ case "id_rsa" :
95
+ v .ID_RSA = val
93
96
default :
94
97
if val != "" {
95
98
v .Options = append (v .Options , key + "=" + val )
@@ -128,6 +131,11 @@ func (d *sshfsDriver) Remove(r *volume.RemoveRequest) error {
128
131
if err := os .RemoveAll (v .Mountpoint ); err != nil {
129
132
return logError (err .Error ())
130
133
}
134
+
135
+ if err := os .RemoveAll (v .Mountpoint + "_id_rsa" ); err != nil {
136
+ return logError (err .Error ())
137
+ }
138
+
131
139
delete (d .volumes , r .Name )
132
140
d .saveState ()
133
141
return nil
@@ -163,6 +171,17 @@ func (d *sshfsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, erro
163
171
if os .IsNotExist (err ) {
164
172
if err := os .MkdirAll (v .Mountpoint , 0755 ); err != nil {
165
173
return & volume.MountResponse {}, logError (err .Error ())
174
+ } else {
175
+ if v .ID_RSA != "" {
176
+ id_rsa := v .Mountpoint + "_id_rsa"
177
+ f , err := os .Create (id_rsa )
178
+ if err != nil {
179
+ logrus .Error (err )
180
+ }
181
+ f .WriteString (v .ID_RSA )
182
+ f .Chmod (0600 )
183
+ f .Close ()
184
+ }
166
185
}
167
186
} else if err != nil {
168
187
return & volume.MountResponse {}, logError (err .Error ())
@@ -239,14 +258,17 @@ func (d *sshfsDriver) Capabilities() *volume.CapabilitiesResponse {
239
258
240
259
func (d * sshfsDriver ) mountVolume (v * sshfsVolume ) error {
241
260
cmd := exec .Command ("sshfs" , "-oStrictHostKeyChecking=no" , v .Sshcmd , v .Mountpoint )
261
+
242
262
if v .Port != "" {
243
263
cmd .Args = append (cmd .Args , "-p" , v .Port )
244
264
}
245
265
if v .Password != "" {
246
266
cmd .Args = append (cmd .Args , "-o" , "workaround=rename" , "-o" , "password_stdin" )
247
267
cmd .Stdin = strings .NewReader (v .Password )
248
268
}
249
-
269
+ if v .ID_RSA != "" {
270
+ cmd .Args = append (cmd .Args , "-o" , "IdentityFile=" + v .Mountpoint + "_id_rsa" )
271
+ }
250
272
for _ , option := range v .Options {
251
273
cmd .Args = append (cmd .Args , "-o" , option )
252
274
}
0 commit comments