DS apiserver: Minor fixes (#84691)

This commit is contained in:
Marcus Efraimsson 2024-03-19 09:02:52 +01:00 committed by GitHub
parent 58170d4141
commit e978d0810e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -69,6 +69,7 @@ func (r *subQueryREST) Connect(ctx context.Context, name string, opts runtime.Ob
} }
if dsRef != nil && dsRef.UID != name { if dsRef != nil && dsRef.UID != name {
responder.Error(fmt.Errorf("expected query body datasource and request to match")) responder.Error(fmt.Errorf("expected query body datasource and request to match"))
return
} }
ctx = backend.WithGrafanaConfig(ctx, pluginCtx.GrafanaConfig) ctx = backend.WithGrafanaConfig(ctx, pluginCtx.GrafanaConfig)

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"net/url"
"strings" "strings"
"github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend"
@ -66,12 +67,21 @@ func (r *subResourceREST) Connect(ctx context.Context, name string, opts runtime
return return
} }
path := req.URL.Path[idx+len("/resource"):] clonedReq := req.Clone(req.Context())
rawURL := req.URL.Path[idx+len("/resource"):]
clonedReq.URL = &url.URL{
Path: rawURL,
RawQuery: clonedReq.URL.RawQuery,
}
err = r.builder.client.CallResource(ctx, &backend.CallResourceRequest{ err = r.builder.client.CallResource(ctx, &backend.CallResourceRequest{
PluginContext: pluginCtx, PluginContext: pluginCtx,
Path: path, Path: clonedReq.URL.Path,
Method: req.Method, Method: req.Method,
URL: req.URL.String(),
Body: body, Body: body,
Headers: req.Header,
}, httpresponsesender.New(w)) }, httpresponsesender.New(w))
if err != nil { if err != nil {