The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/services/ngalert/remote/client/mimir_auth_round_tripper.go

28 lines
717 B

package client
import (
"net/http"
)
const mimirTenantHeader = "X-Scope-OrgID"
type MimirAuthRoundTripper struct {
TenantID string
Password string
Next http.RoundTripper
}
// RoundTrip implements the http.RoundTripper interface
// It adds an `X-Scope-OrgID` header with the TenantID if only provided with a tenantID or sets HTTP Basic Authentication if both
// a tenantID and a password are provided.
func (r *MimirAuthRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
if r.TenantID != "" && r.Password == "" {
req.Header.Set(mimirTenantHeader, r.TenantID)
}
if r.TenantID != "" && r.Password != "" {
req.SetBasicAuth(r.TenantID, r.Password)
}
return r.Next.RoundTrip(req)
}