2024-01-09 14:26:24 -06:00
|
|
|
package datasource
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"k8s.io/apiserver/pkg/registry/rest"
|
2024-01-19 08:56:52 -06:00
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
2024-01-09 14:26:24 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
type subProxyREST struct {
|
2024-01-19 08:56:52 -06:00
|
|
|
pluginJSON plugins.JSONData
|
2024-01-09 14:26:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ = rest.Connecter(&subProxyREST{})
|
|
|
|
|
|
|
|
func (r *subProxyREST) New() runtime.Object {
|
|
|
|
return &metav1.Status{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *subProxyREST) Destroy() {}
|
|
|
|
|
|
|
|
func (r *subProxyREST) ConnectMethods() []string {
|
|
|
|
unique := map[string]bool{}
|
|
|
|
methods := []string{}
|
2024-01-19 08:56:52 -06:00
|
|
|
for _, r := range r.pluginJSON.Routes {
|
2024-01-09 14:26:24 -06:00
|
|
|
if unique[r.Method] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
unique[r.Method] = true
|
|
|
|
methods = append(methods, r.Method)
|
|
|
|
}
|
|
|
|
return methods
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *subProxyREST) NewConnectOptions() (runtime.Object, bool, string) {
|
|
|
|
return nil, true, ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *subProxyREST) Connect(ctx context.Context, name string, opts runtime.Object, responder rest.Responder) (http.Handler, error) {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
2024-01-19 08:56:52 -06:00
|
|
|
responder.Error(fmt.Errorf("TODO, proxy: " + r.pluginJSON.ID))
|
2024-01-09 14:26:24 -06:00
|
|
|
}), nil
|
|
|
|
}
|