Files
Roberto Jiménez Sánchez 047499a363 Provisioning: introduce concept of provisioning extras (#104981)
* Spike: Extras

* Attempt to wire it up

* Hack

* Fix issue with jobs

* Wire more things up

* Fix more wiring stuff

* Remove webhook secret key from main registration

* Move secret encryption also outside register

* Add TODOs in code

* Add more explanations

* Move connectors to different package

* Move pull request job into webhooks

* Separate registration

* Remove duplicate files

* Fix missing function

* Extract webhook repository logic out of the core github repository

* Use status patcher in webhook connector

* Fix change in go mod

* Change hooks signature

* Remove TODOs

* Remove Webhook methos from go-git

* Remove leftover

* Fix mistake in OpenAPI spec

* Fix some tests

* Fix some issues

* Fix linting
2025-05-13 09:50:43 +02:00

67 lines
1.7 KiB
Go

package provisioning
import (
"context"
"fmt"
"net/http"
"time"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/registry/rest"
provisioning "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1"
"github.com/grafana/grafana/pkg/registry/apis/provisioning/resources"
)
// TODO: Rename to resources as it's not clear that we are returning here is repository resources
type listConnector struct {
getter RepoGetter
lister resources.ResourceLister
}
func (*listConnector) New() runtime.Object {
return &provisioning.ResourceList{}
}
func (*listConnector) Destroy() {}
func (*listConnector) ProducesMIMETypes(verb string) []string {
return []string{"application/json"}
}
func (*listConnector) ProducesObject(verb string) any {
return &provisioning.ResourceList{}
}
func (*listConnector) ConnectMethods() []string {
return []string{http.MethodGet}
}
func (*listConnector) NewConnectOptions() (runtime.Object, bool, string) {
return nil, false, ""
}
func (s *listConnector) Connect(ctx context.Context, name string, opts runtime.Object, responder rest.Responder) (http.Handler, error) {
ns, ok := request.NamespaceFrom(ctx)
if !ok {
return nil, fmt.Errorf("missing namespace")
}
return WithTimeout(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// TODO: Add pagination to resource lister
rsp, err := s.lister.List(ctx, ns, name)
if err != nil {
responder.Error(err)
} else {
responder.Object(200, rsp)
}
}), 30*time.Second), nil
}
var (
_ rest.Storage = (*listConnector)(nil)
_ rest.Connecter = (*listConnector)(nil)
_ rest.StorageMetadata = (*listConnector)(nil)
)