diff options
Diffstat (limited to 'models/ssh_key.go')
-rw-r--r-- | models/ssh_key.go | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/models/ssh_key.go b/models/ssh_key.go index 33ba86c5bf..64b859fa02 100644 --- a/models/ssh_key.go +++ b/models/ssh_key.go @@ -15,6 +15,7 @@ import ( "encoding/pem" "errors" "fmt" + "io" "io/ioutil" "math/big" "os" @@ -701,7 +702,21 @@ func rewriteAllPublicKeys(e Engine) error { } } - err = e.Iterate(new(PublicKey), func(idx int, bean interface{}) (err error) { + if err := regeneratePublicKeys(e, t); err != nil { + return err + } + + t.Close() + return os.Rename(tmpPath, fPath) +} + +// RegeneratePublicKeys regenerates the authorized_keys file +func RegeneratePublicKeys(t io.StringWriter) error { + return regeneratePublicKeys(x, t) +} + +func regeneratePublicKeys(e Engine, t io.StringWriter) error { + err := e.Iterate(new(PublicKey), func(idx int, bean interface{}) (err error) { _, err = t.WriteString((bean.(*PublicKey)).AuthorizedString()) return err }) @@ -709,6 +724,7 @@ func rewriteAllPublicKeys(e Engine) error { return err } + fPath := filepath.Join(setting.SSH.RootPath, "authorized_keys") if com.IsExist(fPath) { f, err := os.Open(fPath) if err != nil { @@ -729,9 +745,7 @@ func rewriteAllPublicKeys(e Engine) error { } f.Close() } - - t.Close() - return os.Rename(tmpPath, fPath) + return nil } // ________ .__ ____ __. |