Auth: Remove oAuthProviders from Social service (#78732)

* Remove oauthProviders from social svc

* Add EnabledFn to supportbundles.Collector
This commit is contained in:
Misi
2023-11-30 09:30:35 +01:00
committed by GitHub
parent 86311e3a33
commit 79577e4929
5 changed files with 47 additions and 30 deletions
+2
View File
@@ -46,6 +46,8 @@ type Collector struct {
Default bool `json:"default"`
// Fn is the function that collects the support item.
Fn CollectorFunc `json:"-"`
// EnabledFn is a function that determines if the collector is enabled. If nil, the collector is always enabled.
EnabledFn func() bool `json:"-"`
}
type Service interface {
@@ -74,9 +74,15 @@ func (s *Service) bundle(ctx context.Context, collectors []string, uid string) (
files := map[string][]byte{}
for _, collector := range s.bundleRegistry.Collectors() {
if !lookup[collector.UID] && !collector.IncludedByDefault {
collectorEnabled := true
if collector.EnabledFn != nil {
collectorEnabled = collector.EnabledFn()
}
if !(lookup[collector.UID] || collector.IncludedByDefault) || !collectorEnabled {
continue
}
item, err := collector.Fn(ctx)
if err != nil {
s.log.Warn("Failed to collect support bundle item", "error", err, "collector", collector.UID)
@@ -38,12 +38,16 @@ func TestService_bundleCreate(t *testing.T) {
cfg := setting.NewCfg()
collector := basicCollector(cfg)
disabledCollector := settingsCollector(setting.ProvideProvider(cfg))
disabledCollector.EnabledFn = func() bool { return false }
s.bundleRegistry.RegisterSupportItemCollector(collector)
s.bundleRegistry.RegisterSupportItemCollector(disabledCollector)
createdBundle, err := s.store.Create(context.Background(), &user.SignedInUser{UserID: 1, Login: "bob"})
require.NoError(t, err)
s.startBundleWork(context.Background(), []string{collector.UID}, createdBundle.UID)
s.startBundleWork(context.Background(), []string{collector.UID, disabledCollector.UID}, createdBundle.UID)
bundle, err := s.get(context.Background(), createdBundle.UID)
require.NoError(t, err)