summaryrefslogtreecommitdiffstats
path: root/models/ssh_key_deploy.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/ssh_key_deploy.go')
-rw-r--r--models/ssh_key_deploy.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/models/ssh_key_deploy.go b/models/ssh_key_deploy.go
index 4e3910d556..c31379dcb4 100644
--- a/models/ssh_key_deploy.go
+++ b/models/ssh_key_deploy.go
@@ -12,7 +12,6 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"xorm.io/builder"
- "xorm.io/xorm"
)
// ________ .__ ____ __.
@@ -90,7 +89,7 @@ func checkDeployKey(e db.Engine, keyID, repoID int64, name string) error {
}
// addDeployKey adds new key-repo relation.
-func addDeployKey(e *xorm.Session, keyID, repoID int64, name, fingerprint string, mode AccessMode) (*DeployKey, error) {
+func addDeployKey(e db.Engine, keyID, repoID int64, name, fingerprint string, mode AccessMode) (*DeployKey, error) {
if err := checkDeployKey(e, keyID, repoID, name); err != nil {
return nil, err
}
@@ -126,11 +125,13 @@ func AddDeployKey(repoID int64, name, content string, readOnly bool) (*DeployKey
accessMode = AccessModeWrite
}
- sess := db.NewSession(db.DefaultContext)
- defer sess.Close()
- if err = sess.Begin(); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
return nil, err
}
+ defer committer.Close()
+
+ sess := db.GetEngine(ctx)
pkey := &PublicKey{
Fingerprint: fingerprint,
@@ -160,7 +161,7 @@ func AddDeployKey(repoID int64, name, content string, readOnly bool) (*DeployKey
return nil, err
}
- return key, sess.Commit()
+ return key, committer.Commit()
}
// GetDeployKeyByID returns deploy key by given ID.
@@ -212,15 +213,16 @@ func UpdateDeployKey(key *DeployKey) error {
// DeleteDeployKey deletes deploy key from its repository authorized_keys file if needed.
func DeleteDeployKey(doer *User, id int64) error {
- sess := db.NewSession(db.DefaultContext)
- defer sess.Close()
- if err := sess.Begin(); err != nil {
+ ctx, committer, err := db.TxContext()
+ if err != nil {
return err
}
- if err := deleteDeployKey(sess, doer, id); err != nil {
+ defer committer.Close()
+
+ if err := deleteDeployKey(db.GetEngine(ctx), doer, id); err != nil {
return err
}
- return sess.Commit()
+ return committer.Commit()
}
func deleteDeployKey(sess db.Engine, doer *User, id int64) error {