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 /services/auth | |
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 'services/auth')
-rw-r--r-- | services/auth/source.go | 10 | ||||
-rw-r--r-- | services/auth/source/oauth2/init.go | 13 | ||||
-rw-r--r-- | services/auth/source/oauth2/providers.go | 5 |
3 files changed, 16 insertions, 12 deletions
diff --git a/services/auth/source.go b/services/auth/source.go index aae3a78102..69b71a6dea 100644 --- a/services/auth/source.go +++ b/services/auth/source.go @@ -4,14 +4,16 @@ package auth import ( + "context" + "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/db" user_model "code.gitea.io/gitea/models/user" ) // DeleteSource deletes a AuthSource record in DB. -func DeleteSource(source *auth.Source) error { - count, err := db.GetEngine(db.DefaultContext).Count(&user_model.User{LoginSource: source.ID}) +func DeleteSource(ctx context.Context, source *auth.Source) error { + count, err := db.GetEngine(ctx).Count(&user_model.User{LoginSource: source.ID}) if err != nil { return err } else if count > 0 { @@ -20,7 +22,7 @@ func DeleteSource(source *auth.Source) error { } } - count, err = db.GetEngine(db.DefaultContext).Count(&user_model.ExternalLoginUser{LoginSourceID: source.ID}) + count, err = db.GetEngine(ctx).Count(&user_model.ExternalLoginUser{LoginSourceID: source.ID}) if err != nil { return err } else if count > 0 { @@ -35,6 +37,6 @@ func DeleteSource(source *auth.Source) error { } } - _, err = db.GetEngine(db.DefaultContext).ID(source.ID).Delete(new(auth.Source)) + _, err = db.GetEngine(ctx).ID(source.ID).Delete(new(auth.Source)) return err } diff --git a/services/auth/source/oauth2/init.go b/services/auth/source/oauth2/init.go index 32fe545c90..cfaddaa35d 100644 --- a/services/auth/source/oauth2/init.go +++ b/services/auth/source/oauth2/init.go @@ -4,6 +4,7 @@ package oauth2 import ( + "context" "encoding/gob" "net/http" "sync" @@ -26,7 +27,7 @@ const UsersStoreKey = "gitea-oauth2-sessions" const ProviderHeaderKey = "gitea-oauth2-provider" // Init initializes the oauth source -func Init() error { +func Init(ctx context.Context) error { if err := InitSigningKey(); err != nil { return err } @@ -51,18 +52,18 @@ func Init() error { // Unlock our mutex gothRWMutex.Unlock() - return initOAuth2Sources() + return initOAuth2Sources(ctx) } // ResetOAuth2 clears existing OAuth2 providers and loads them from DB -func ResetOAuth2() error { +func ResetOAuth2(ctx context.Context) error { ClearProviders() - return initOAuth2Sources() + return initOAuth2Sources(ctx) } // initOAuth2Sources is used to load and register all active OAuth2 providers -func initOAuth2Sources() error { - authSources, _ := auth.GetActiveOAuth2ProviderSources() +func initOAuth2Sources(ctx context.Context) error { + authSources, _ := auth.GetActiveOAuth2ProviderSources(ctx) for _, source := range authSources { oauth2Source, ok := source.Cfg.(*Source) if !ok { diff --git a/services/auth/source/oauth2/providers.go b/services/auth/source/oauth2/providers.go index e3a0cb0335..cd158614a2 100644 --- a/services/auth/source/oauth2/providers.go +++ b/services/auth/source/oauth2/providers.go @@ -4,6 +4,7 @@ package oauth2 import ( + "context" "errors" "fmt" "html" @@ -97,10 +98,10 @@ func GetOAuth2Providers() []Provider { // GetActiveOAuth2Providers returns the map of configured active OAuth2 providers // key is used as technical name (like in the callbackURL) // values to display -func GetActiveOAuth2Providers() ([]string, map[string]Provider, error) { +func GetActiveOAuth2Providers(ctx context.Context) ([]string, map[string]Provider, error) { // Maybe also separate used and unused providers so we can force the registration of only 1 active provider for each type - authSources, err := auth.GetActiveOAuth2ProviderSources() + authSources, err := auth.GetActiveOAuth2ProviderSources(ctx) if err != nil { return nil, nil, err } |