New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow using {{ .URL }} inside "routes" section in plugin.json #80858
Conversation
@wbrowne @andresmgot @oshirohugo could you sugget how to pass |
…afana#80858 Signed-off-by: Eugene Klimov <eklimov@altinity.com>
It seems there is a specific test that prevents the request from being modified at all: https://github.com/grafana/grafana/blob/main/pkg/api/pluginproxy/ds_proxy_test.go#L151-L159 This was introduced here: #27653 which seemed to be only interested in keeping the Host and Schema but also protected the Path. Seems unnecessary but do you know if this may break anything @marefr ? |
@andresmgot i can't figure out |
It did fail, you need to expand the logs:
|
@andresmgot thanks for logs |
path
from url when using routes
section without url
@andresmgot @marefr I implemented allowing to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, do you mind adding a test to cover this use case? You can add the following:
--- a/pkg/api/pluginproxy/ds_proxy_test.go
+++ b/pkg/api/pluginproxy/ds_proxy_test.go
@@ -158,6 +158,36 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
assert.Equal(t, "http://localhost/asd", req.URL.String())
})
+ t.Run("When matching route path and has setting url", func(t *testing.T) {
+ ctx, req := setUp()
+ proxy, err := setupDSProxyTest(t, ctx, ds, routes, "api/common/some/method")
+ require.NoError(t, err)
+ proxy.matchedRoute = &plugins.Route{
+ Path: "api/common",
+ URL: "{{.URL}}",
+ Headers: []plugins.Header{
+ {Name: "x-header", Content: "my secret {{.SecureJsonData.key}}"},
+ },
+ URLParams: []plugins.URLParam{
+ {Name: "{{.JsonData.queryParam}}", Content: "{{.SecureJsonData.key}}"},
+ },
+ }
+
+ dsInfo := DSInfo{
+ ID: ds.ID,
+ Updated: ds.Updated,
+ JSONData: jd,
+ DecryptedSecureJSONData: map[string]string{
+ "key": "123",
+ },
+ URL: "https://dynamic.grafana.com",
+ }
+ ApplyRoute(proxy.ctx.Req.Context(), req, proxy.proxyPath, proxy.matchedRoute, dsInfo, proxy.cfg)
+
+ assert.Equal(t, "https://dynamic.grafana.com/some/method?apiKey=123", req.URL.String())
+ assert.Equal(t, "my secret 123", req.Header.Get("x-header"))
+ })
+
@andresmgot test added, thanks for suggestion |
@andresmgot hot to approve |
hi @Slach, can you merge the latest |
Signed-off-by: Slach <bloodjazman@gmail.com>
Co-authored-by: Andres Martinez Gotor <andres.mgotor@gmail.com>
…, fix after comment
43eea5a
to
c0b639e
Compare
merge and rebase, done |
Thank you for the contribution. |
…in.json (#80858) Signed-off-by: Slach <bloodjazman@gmail.com> Co-authored-by: Andres Martinez Gotor <andres.mgotor@gmail.com>
What is this feature?
Detail description is #80856
Why do we need this feature?
Looks like current implementation contains bug
Who is this feature for?
For plugin developers which can't store all settings into
jsonData
and try to use standard
@grafana/ui
DataSourceHttpSettings
componentFor plugin developers when data source destination server doesn't allow additional
path
in proxyfied request URL.Which issue(s) does this PR fix?:
Fixes #80856
Special notes for your reviewer:
Please check that: