2021-07-24 15:46:34 +05:30
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2021-07-24 15:46:34 +05:30
|
|
|
|
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-01-02 18:42:35 +05:30
|
|
|
"code.gitea.io/gitea/models/auth"
|
2021-11-10 10:43:16 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2021-07-24 15:46:34 +05:30
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SyncExternalUsers is used to synchronize users with external authorization source
|
|
|
|
func SyncExternalUsers(ctx context.Context, updateExisting bool) error {
|
|
|
|
log.Trace("Doing: SyncExternalUsers")
|
|
|
|
|
2023-11-03 07:11:00 +05:30
|
|
|
ls, err := auth.FindSources(ctx, auth.FindSourcesOptions{})
|
2021-07-24 15:46:34 +05:30
|
|
|
if err != nil {
|
|
|
|
log.Error("SyncExternalUsers: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range ls {
|
|
|
|
if !s.IsActive || !s.IsSyncEnabled {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
log.Warn("SyncExternalUsers: Cancelled before update of %s", s.Name)
|
2021-11-10 10:43:16 +05:30
|
|
|
return db.ErrCancelledf("Before update of %s", s.Name)
|
2021-07-24 15:46:34 +05:30
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
if syncable, ok := s.Cfg.(SynchronizableSource); ok {
|
|
|
|
err := syncable.Sync(ctx, updateExisting)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|