loki backend mode forward-oauth (#48401)

* loki: backend: add forward oauth credentials functionality

* removed obsolete comment
This commit is contained in:
Gábor Farkas
2022-05-05 12:42:50 +02:00
committed by GitHub
parent 9b8cdab123
commit 02aa1cd1c5
6 changed files with 293 additions and 62 deletions
+41
View File
@@ -0,0 +1,41 @@
package loki
import (
"bytes"
"io"
"net/http"
"github.com/grafana/grafana/pkg/infra/log"
)
type mockRequestCallback func(req *http.Request)
type mockedRoundTripper struct {
statusCode int
responseBytes []byte
contentType string
requestCallback mockRequestCallback
}
func (mockedRT *mockedRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
requestCallback := mockedRT.requestCallback
if requestCallback != nil {
requestCallback(req)
}
header := http.Header{}
header.Add("Content-Type", mockedRT.contentType)
return &http.Response{
StatusCode: mockedRT.statusCode,
Header: header,
Body: io.NopCloser(bytes.NewReader(mockedRT.responseBytes)),
}, nil
}
func makeMockedAPI(statusCode int, contentType string, responseBytes []byte, requestCallback mockRequestCallback) *LokiAPI {
client := http.Client{
Transport: &mockedRoundTripper{statusCode: statusCode, contentType: contentType, responseBytes: responseBytes, requestCallback: requestCallback},
}
return newLokiAPI(&client, "http://localhost:9999", log.New("test"), "")
}