Provisioning: Configurable Repository Types in monolith and operators (#110822)

* Configurable repository types in monolith and operator

* Default to Github in operators

* Regenerate wire

* Fix and implement unit tests

* Same types for enterprise tests

* Remove unnecessary conversion

* Remove the issue with import cycles
This commit is contained in:
Roberto Jiménez Sánchez
2025-09-09 19:13:22 +02:00
committed by GitHub
parent 3f4c523ef5
commit acbc2cf01a
8 changed files with 361 additions and 45 deletions
+17 -6
View File
@@ -3,8 +3,6 @@ package repository
import (
"context"
"fmt"
"maps"
"slices"
"sort"
provisioning "github.com/grafana/grafana/apps/provisioning/pkg/apis/provisioning/v0alpha1"
@@ -28,12 +26,14 @@ type Factory interface {
}
type factory struct {
extras map[provisioning.RepositoryType]Extra
extras map[provisioning.RepositoryType]Extra
enabled map[provisioning.RepositoryType]struct{}
}
func ProvideFactory(extras []Extra) (Factory, error) {
func ProvideFactory(enabled map[provisioning.RepositoryType]struct{}, extras []Extra) (Factory, error) {
f := &factory{
extras: make(map[provisioning.RepositoryType]Extra, len(extras)),
enabled: enabled,
extras: make(map[provisioning.RepositoryType]Extra, len(extras)),
}
for _, e := range extras {
@@ -47,16 +47,27 @@ func ProvideFactory(extras []Extra) (Factory, error) {
}
func (f *factory) Types() []provisioning.RepositoryType {
types := slices.Collect(maps.Keys(f.extras))
var types []provisioning.RepositoryType
for t := range f.enabled {
if _, exists := f.extras[t]; exists {
types = append(types, t)
}
}
sort.Slice(types, func(i, j int) bool {
return string(types[i]) < string(types[j])
})
return types
}
func (f *factory) Build(ctx context.Context, r *provisioning.Repository) (Repository, error) {
for _, e := range f.extras {
if e.Type() == r.Spec.Type {
if _, enabled := f.enabled[e.Type()]; !enabled {
return nil, fmt.Errorf("repository type %q is not enabled", e.Type())
}
return e.Build(ctx, r)
}
}