A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/grafana/mcp-grafana/commit/de6926be0073a86f7a45f7ac1892ecef557eed76 below:

always fixup schemes of Grafana client based on final Grafana UR… · grafana/mcp-grafana@de6926b · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+19

-15

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+19

-15

lines changed Original file line number Diff line number Diff line change

@@ -167,20 +167,21 @@ func NewGrafanaClient(ctx context.Context, grafanaURL, apiKey string) *client.Gr

167 167

var parsedURL *url.URL

168 168

var err error

169 169 170 -

if grafanaURL != "" {

171 -

parsedURL, err = url.Parse(grafanaURL)

172 -

if err != nil {

173 -

panic(fmt.Errorf("invalid Grafana URL: %w", err))

174 -

}

175 -

cfg.Host = parsedURL.Host

176 -

cfg.BasePath = makeBasePath(parsedURL.Path)

177 -

// The Grafana client will always prefer HTTPS even if the URL is HTTP,

178 -

// so we need to limit the schemes to HTTP if the URL is HTTP.

179 -

if parsedURL.Scheme == "http" {

180 -

cfg.Schemes = []string{"http"}

181 -

}

182 -

} else {

183 -

parsedURL, _ = url.Parse(defaultGrafanaURL)

170 +

if grafanaURL == "" {

171 +

grafanaURL = defaultGrafanaURL

172 +

}

173 + 174 +

parsedURL, err = url.Parse(grafanaURL)

175 +

if err != nil {

176 +

panic(fmt.Errorf("invalid Grafana URL: %w", err))

177 +

}

178 +

cfg.Host = parsedURL.Host

179 +

cfg.BasePath = makeBasePath(parsedURL.Path)

180 + 181 +

// The Grafana client will always prefer HTTPS even if the URL is HTTP,

182 +

// so we need to limit the schemes to HTTP if the URL is HTTP.

183 +

if parsedURL.Scheme == "http" {

184 +

cfg.Schemes = []string{"http"}

184 185

}

185 186 186 187

if apiKey != "" {

@@ -216,6 +217,9 @@ var ExtractGrafanaClientFromHeaders httpContextFunc = func(ctx context.Context,

216 217

if u == "" {

217 218

u = uEnv

218 219

}

220 +

if u == "" {

221 +

u = defaultGrafanaURL

222 +

}

219 223

if apiKey == "" {

220 224

apiKey = apiKeyEnv

221 225

}

Original file line number Diff line number Diff line change

@@ -173,7 +173,7 @@ func TestExtractGrafanaClientFromHeaders(t *testing.T) {

173 173

ctx := ExtractGrafanaClientFromHeaders(context.Background(), req)

174 174

c := GrafanaClientFromContext(ctx)

175 175

url := minURLFromClient(c)

176 -

assert.Equal(t, "localhost", url.host)

176 +

assert.Equal(t, "localhost:3000", url.host)

177 177

assert.Equal(t, "/api", url.basePath)

178 178

})

179 179

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4