mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
Set Basic Auth on proxied requests if user:pass is set in the Alertmanager URI
This commit is contained in:
7
proxy.go
7
proxy.go
@@ -31,6 +31,13 @@ func NewAlertmanagerProxy(alertmanager *alertmanager.Alertmanager) (*httputil.Re
|
||||
Director: func(req *http.Request) {
|
||||
req.URL.Scheme = upstreamURL.Scheme
|
||||
req.URL.Host = upstreamURL.Host
|
||||
|
||||
if upstreamURL.User.Username() != "" {
|
||||
username := upstreamURL.User.Username()
|
||||
password, _ := upstreamURL.User.Password()
|
||||
req.SetBasicAuth(username, password)
|
||||
}
|
||||
|
||||
// drop Accept-Encoding header so we always get uncompressed reponses from
|
||||
// upstream, there's a gzip middleware that's global so we don't want it
|
||||
// to gzip twice
|
||||
|
||||
@@ -162,6 +162,16 @@ var proxyHeaderTests = []proxyHeaderTest{
|
||||
authUser: "foo",
|
||||
authPass: "bar",
|
||||
},
|
||||
{
|
||||
method: "POST",
|
||||
localPath: "/proxy/alertmanager/dummy/api/v1/silences",
|
||||
upstreamURI: "http://alertmanager.example.com/api/v1/silences",
|
||||
code: 200,
|
||||
alertmanagerURI: "http://foo@alertmanager.example.com",
|
||||
alertmanagerHost: "alertmanager.example.com",
|
||||
authUser: "foo",
|
||||
authPass: "",
|
||||
},
|
||||
}
|
||||
|
||||
func TestProxyHeaders(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user