diff options
author | zeripath <art27@cantab.net> | 2020-04-06 11:44:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-06 11:44:47 +0100 |
commit | d26885e2bf0a53af1c5c97c9d062f329250d8d20 (patch) | |
tree | 7dfe7646b121c0c77bed52ebe3bb9c41a1af5250 /models/ssh_key.go | |
parent | 1648bf2b60126f7959d92d176bf7f3cf3ae1cfe6 (diff) | |
download | gitea-d26885e2bf0a53af1c5c97c9d062f329250d8d20.tar.gz gitea-d26885e2bf0a53af1c5c97c9d062f329250d8d20.zip |
Mulitple Gitea Doctor improvements (#10943)
* Add `gitea doctor --list` flag to list the checks that will be run, including those by default
* Add `gitea doctor --run` to run specific checks
* Add `gitea doctor --all` to run all checks
* Add db version checker
* Add non-default recalculate merge bases check/fixer to doctor
* Add hook checker (Fix #9878) and ensure hooks are executable (Fix #6319)
* Fix authorized_keys checker - slight change of functionality here because parsing the command is fragile and we should just check if the authorized_keys file is essentially the same as what gitea would produce. (This is still not perfect as order matters - we should probably just md5sum the two files.)
* Add SCRIPT_TYPE check (Fix #10977)
* Add `gitea doctor --fix` to attempt to fix what is possible to easily fix
* Add `gitea doctor --log-file` to set the log-file, be it a file, stdout or to switch off completely. (Fixes previously undetected bug with certain xorm logging configurations - see @6543 comment.)
Signed-off-by: Andrew Thornton <art27@cantab.net>
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 } // ________ .__ ____ __. |