Files
grafana/pkg/services/ngalert/remote/client/mimir_auth_round_tripper.go
Santiago b19e546254 Remote Alertmanager: Remove X-Remote-Alertmanager header (#114917)
Remote Alertmanager: Remove X-Remote-Alertmanager haeder
2025-12-05 15:04:42 +00:00

31 lines
722 B
Go

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)
}