diff options
author | JakobDev <jakobdev@gmx.de> | 2023-10-14 10:37:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-14 08:37:24 +0000 |
commit | 76a85a4ce90fead1eb2b743a42b41617b4592889 (patch) | |
tree | ef172bbbc48c24e0d95cd5c689426bad16205a69 /models/asymkey/ssh_key_principals.go | |
parent | ae419fa49403537725c806a5f3f1e5b274f52eb7 (diff) | |
download | gitea-76a85a4ce90fead1eb2b743a42b41617b4592889.tar.gz gitea-76a85a4ce90fead1eb2b743a42b41617b4592889.zip |
Final round of `db.DefaultContext` refactor (#27587)
Last part of #27065
Diffstat (limited to 'models/asymkey/ssh_key_principals.go')
-rw-r--r-- | models/asymkey/ssh_key_principals.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/models/asymkey/ssh_key_principals.go b/models/asymkey/ssh_key_principals.go index 150b77c7b2..92789e26f8 100644 --- a/models/asymkey/ssh_key_principals.go +++ b/models/asymkey/ssh_key_principals.go @@ -25,15 +25,15 @@ import ( // This file contains functions related to principals // AddPrincipalKey adds new principal to database and authorized_principals file. -func AddPrincipalKey(ownerID int64, content string, authSourceID int64) (*PublicKey, error) { - ctx, committer, err := db.TxContext(db.DefaultContext) +func AddPrincipalKey(ctx context.Context, ownerID int64, content string, authSourceID int64) (*PublicKey, error) { + dbCtx, committer, err := db.TxContext(ctx) if err != nil { return nil, err } defer committer.Close() // Principals cannot be duplicated. - has, err := db.GetEngine(ctx). + has, err := db.GetEngine(dbCtx). Where("content = ? AND type = ?", content, KeyTypePrincipal). Get(new(PublicKey)) if err != nil { @@ -50,7 +50,7 @@ func AddPrincipalKey(ownerID int64, content string, authSourceID int64) (*Public Type: KeyTypePrincipal, LoginSourceID: authSourceID, } - if err = db.Insert(ctx, key); err != nil { + if err = db.Insert(dbCtx, key); err != nil { return nil, fmt.Errorf("addKey: %w", err) } @@ -60,7 +60,7 @@ func AddPrincipalKey(ownerID int64, content string, authSourceID int64) (*Public committer.Close() - return key, RewriteAllPrincipalKeys(db.DefaultContext) + return key, RewriteAllPrincipalKeys(ctx) } // CheckPrincipalKeyString strips spaces and returns an error if the given principal contains newlines @@ -105,8 +105,8 @@ func CheckPrincipalKeyString(ctx context.Context, user *user_model.User, content } // ListPrincipalKeys returns a list of principals belongs to given user. -func ListPrincipalKeys(uid int64, listOptions db.ListOptions) ([]*PublicKey, error) { - sess := db.GetEngine(db.DefaultContext).Where("owner_id = ? AND type = ?", uid, KeyTypePrincipal) +func ListPrincipalKeys(ctx context.Context, uid int64, listOptions db.ListOptions) ([]*PublicKey, error) { + sess := db.GetEngine(ctx).Where("owner_id = ? AND type = ?", uid, KeyTypePrincipal) if listOptions.Page != 0 { sess = db.SetSessionPagination(sess, &listOptions) |