Plugins Proxy: Allow using {{ .URL }} inside "routes" section in plugin.json (#80858)
Signed-off-by: Slach <bloodjazman@gmail.com> Co-authored-by: Andres Martinez Gotor <andres.mgotor@gmail.com>
This commit is contained in:
co-authored by
Andres Martinez Gotor
parent
ea243b536c
commit
702e22806c
@@ -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"))
|
||||
})
|
||||
|
||||
t.Run("When matching route path and has dynamic body", func(t *testing.T) {
|
||||
ctx, req := setUp()
|
||||
proxy, err := setupDSProxyTest(t, ctx, ds, routes, "api/body")
|
||||
|
||||
Reference in New Issue
Block a user