diff options
Diffstat (limited to 'models/ssh_key_principals.go')
-rw-r--r-- | models/ssh_key_principals.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/models/ssh_key_principals.go b/models/ssh_key_principals.go index 50456b72db..55d8e40397 100644 --- a/models/ssh_key_principals.go +++ b/models/ssh_key_principals.go @@ -25,11 +25,12 @@ import ( // AddPrincipalKey adds new principal to database and authorized_principals file. func AddPrincipalKey(ownerID int64, content string, loginSourceID int64) (*PublicKey, error) { - 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) // Principals cannot be duplicated. has, err := sess. @@ -53,11 +54,11 @@ func AddPrincipalKey(ownerID int64, content string, loginSourceID int64) (*Publi return nil, fmt.Errorf("addKey: %v", err) } - if err = sess.Commit(); err != nil { + if err = committer.Commit(); err != nil { return nil, err } - sess.Close() + committer.Close() return key, RewriteAllPrincipalKeys() } |