From 575c96cb0802273493b1ceafa49b3b225b5a7724 Mon Sep 17 00:00:00 2001 From: Dane Strandboge Date: Wed, 8 Jan 2025 10:55:11 -0600 Subject: [PATCH] fix(outputs.influxdb_v2): Fix http auth/agent header --- plugins/outputs/influxdb_v2/http.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/plugins/outputs/influxdb_v2/http.go b/plugins/outputs/influxdb_v2/http.go index 8a622a5f4b522..23562be9e81d8 100644 --- a/plugins/outputs/influxdb_v2/http.go +++ b/plugins/outputs/influxdb_v2/http.go @@ -70,17 +70,21 @@ type httpClient struct { } func (c *httpClient) Init() error { - token, err := c.token.Get() - if err != nil { - return fmt.Errorf("getting token failed: %w", err) - } - if c.headers == nil { c.headers = make(map[string]string, 2) } - c.headers["Authorization"] = "Token " + token.String() - token.Destroy() - c.headers["User-Agent"] = c.userAgent + + if _, ok := c.headers["Authorization"]; !ok { + token, err := c.token.Get() + if err != nil { + return fmt.Errorf("getting token failed: %w", err) + } + c.headers["Authorization"] = "Token " + token.String() + token.Destroy() + } + if _, ok := c.headers["User-Agent"]; !ok { + c.headers["User-Agent"] = c.userAgent + } var proxy func(*http.Request) (*url.URL, error) if c.proxy != nil {