code.gitea.io/gitea@v1.21.7/services/auth/sync.go (about) 1 // Copyright 2021 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package auth 5 6 import ( 7 "context" 8 9 "code.gitea.io/gitea/models/auth" 10 "code.gitea.io/gitea/models/db" 11 "code.gitea.io/gitea/modules/log" 12 ) 13 14 // SyncExternalUsers is used to synchronize users with external authorization source 15 func SyncExternalUsers(ctx context.Context, updateExisting bool) error { 16 log.Trace("Doing: SyncExternalUsers") 17 18 ls, err := auth.Sources() 19 if err != nil { 20 log.Error("SyncExternalUsers: %v", err) 21 return err 22 } 23 24 for _, s := range ls { 25 if !s.IsActive || !s.IsSyncEnabled { 26 continue 27 } 28 select { 29 case <-ctx.Done(): 30 log.Warn("SyncExternalUsers: Cancelled before update of %s", s.Name) 31 return db.ErrCancelledf("Before update of %s", s.Name) 32 default: 33 } 34 35 if syncable, ok := s.Cfg.(SynchronizableSource); ok { 36 err := syncable.Sync(ctx, updateExisting) 37 if err != nil { 38 return err 39 } 40 } 41 } 42 return nil 43 }