aboutsummaryrefslogtreecommitdiffstats
path: root/models/ssh_key_authorized_keys.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-09-19 19:49:59 +0800
committerGitHub <noreply@github.com>2021-09-19 19:49:59 +0800
commita4bfef265d9e512830350635a0489c2cdcd6508f (patch)
tree1e3c2ec94276dfcb2f8ba73a2ac075ba39c4a34a /models/ssh_key_authorized_keys.go
parent462306e263db5a809dbe2cdf62e99307aeff28de (diff)
downloadgitea-a4bfef265d9e512830350635a0489c2cdcd6508f.tar.gz
gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.zip
Move db related basic functions to models/db (#17075)
* Move db related basic functions to models/db * Fix lint * Fix lint * Fix test * Fix lint * Fix lint * revert unnecessary change * Fix test * Fix wrong replace string * Use *Context * Correct committer spelling and fix wrong replaced words Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/ssh_key_authorized_keys.go')
-rw-r--r--models/ssh_key_authorized_keys.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/models/ssh_key_authorized_keys.go b/models/ssh_key_authorized_keys.go
index 5736477a0d..e490f21180 100644
--- a/models/ssh_key_authorized_keys.go
+++ b/models/ssh_key_authorized_keys.go
@@ -14,6 +14,7 @@ import (
"sync"
"time"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
@@ -114,13 +115,13 @@ func appendAuthorizedKeysToFile(keys ...*PublicKey) error {
}
// RewriteAllPublicKeys removes any authorized key and rewrite all keys from database again.
-// Note: x.Iterate does not get latest data after insert/delete, so we have to call this function
+// Note: db.DefaultContext().Engine().Iterate does not get latest data after insert/delete, so we have to call this function
// outside any session scope independently.
func RewriteAllPublicKeys() error {
- return rewriteAllPublicKeys(x)
+ return rewriteAllPublicKeys(db.DefaultContext().Engine())
}
-func rewriteAllPublicKeys(e Engine) error {
+func rewriteAllPublicKeys(e db.Engine) error {
// Don't rewrite key if internal server
if setting.SSH.StartBuiltinServer || !setting.SSH.CreateAuthorizedKeysFile {
return nil
@@ -178,10 +179,10 @@ func rewriteAllPublicKeys(e Engine) error {
// RegeneratePublicKeys regenerates the authorized_keys file
func RegeneratePublicKeys(t io.StringWriter) error {
- return regeneratePublicKeys(x, t)
+ return regeneratePublicKeys(db.DefaultContext().Engine(), t)
}
-func regeneratePublicKeys(e Engine, t io.StringWriter) error {
+func regeneratePublicKeys(e db.Engine, t io.StringWriter) error {
if err := e.Where("type != ?", KeyTypePrincipal).Iterate(new(PublicKey), func(idx int, bean interface{}) (err error) {
_, err = t.WriteString((bean.(*PublicKey)).AuthorizedString())
return err