From 0465745981fc1a6adc7dc8f6a9fbc3b851af5cc6 Mon Sep 17 00:00:00 2001 From: Andreas Bergmeier Date: Fri, 24 Sep 2021 16:53:04 +0200 Subject: [PATCH] Add support for Proxy-Authorization. This way scenarios like this can be used: https://cloud.google.com/iap/docs/authentication-howto#authenticating_from_proxy-authorization_header --- client.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client.go b/client.go index c31c2b56..aac3955e 100644 --- a/client.go +++ b/client.go @@ -33,6 +33,10 @@ type Config struct { Client *http.Client // OrgID provides an optional organization ID, ignored when using APIKey, BasicAuth defaults to last used org OrgID int64 + + Proxy struct { + APIKey string + } } // New creates a new Grafana client. @@ -110,6 +114,10 @@ func (c *Client) newRequest(method, requestPath string, query url.Values, body i req.Header.Add("X-Grafana-Org-Id", strconv.FormatInt(c.config.OrgID, 10)) } + if c.config.Proxy.APIKey != "" { + req.Header.Add("Proxy-Authorization", fmt.Sprintf("Bearer %s", c.config.Proxy.APIKey)) + } + if os.Getenv("GF_LOG") != "" { if body == nil { log.Printf("request (%s) to %s with no body data", method, url.String())