mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 09:26:43 -06:00
Merge pull request #7466 from hagen1778/prometheus-basicauth-query
allow setting basic auth headers for prometheus datasource
This commit is contained in:
commit
7d205ae2b8
@ -22,6 +22,18 @@ type PrometheusExecutor struct {
|
||||
Transport *http.Transport
|
||||
}
|
||||
|
||||
type basicAuthTransport struct {
|
||||
*http.Transport
|
||||
|
||||
username string
|
||||
password string
|
||||
}
|
||||
|
||||
func (bat basicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
req.SetBasicAuth(bat.username, bat.password)
|
||||
return bat.Transport.RoundTrip(req)
|
||||
}
|
||||
|
||||
func NewPrometheusExecutor(dsInfo *models.DataSource) (tsdb.Executor, error) {
|
||||
transport, err := dsInfo.GetHttpTransport()
|
||||
if err != nil {
|
||||
@ -51,6 +63,14 @@ func (e *PrometheusExecutor) getClient() (prometheus.QueryAPI, error) {
|
||||
Transport: e.Transport,
|
||||
}
|
||||
|
||||
if e.BasicAuth {
|
||||
cfg.Transport = basicAuthTransport{
|
||||
Transport: e.Transport,
|
||||
username: e.BasicAuthUser,
|
||||
password: e.BasicAuthPassword,
|
||||
}
|
||||
}
|
||||
|
||||
client, err := prometheus.New(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user