You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sync.go 1023B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package auth
  5. import (
  6. "context"
  7. "code.gitea.io/gitea/models/auth"
  8. "code.gitea.io/gitea/models/db"
  9. "code.gitea.io/gitea/modules/log"
  10. )
  11. // SyncExternalUsers is used to synchronize users with external authorization source
  12. func SyncExternalUsers(ctx context.Context, updateExisting bool) error {
  13. log.Trace("Doing: SyncExternalUsers")
  14. ls, err := auth.Sources()
  15. if err != nil {
  16. log.Error("SyncExternalUsers: %v", err)
  17. return err
  18. }
  19. for _, s := range ls {
  20. if !s.IsActive || !s.IsSyncEnabled {
  21. continue
  22. }
  23. select {
  24. case <-ctx.Done():
  25. log.Warn("SyncExternalUsers: Cancelled before update of %s", s.Name)
  26. return db.ErrCancelledf("Before update of %s", s.Name)
  27. default:
  28. }
  29. if syncable, ok := s.Cfg.(SynchronizableSource); ok {
  30. err := syncable.Sync(ctx, updateExisting)
  31. if err != nil {
  32. return err
  33. }
  34. }
  35. }
  36. return nil
  37. }