From ff790adf4209ca01ed6fda468b3db280fc03dcb4 Mon Sep 17 00:00:00 2001 From: Mario Macias Date: Thu, 16 Nov 2023 16:39:04 +0100 Subject: [PATCH] Fix Basic auth key encoding (#446) * Fix Basic auth key encoding * Fix linting --- pkg/internal/export/otel/grafana.go | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/pkg/internal/export/otel/grafana.go b/pkg/internal/export/otel/grafana.go index 5038a4782..9d4e600ad 100644 --- a/pkg/internal/export/otel/grafana.go +++ b/pkg/internal/export/otel/grafana.go @@ -1,17 +1,11 @@ package otel import ( - "bytes" "encoding/base64" "fmt" - "log/slog" "strings" ) -func gclog() *slog.Logger { - return slog.With("component", "otel.GrafanaConfig") -} - const ( submitMetrics = "metrics" submitTraces = "traces" @@ -80,16 +74,7 @@ func (cfg *GrafanaOTLP) Endpoint() string { } func (cfg *GrafanaOTLP) AuthHeader() string { - encodedKey := bytes.Buffer{} - encodedKey.WriteString("Basic ") - encoder := base64.NewEncoder(base64.StdEncoding, &encodedKey) - _, err := encoder.Write([]byte(cfg.InstanceID + ":" + cfg.APIKey)) - if err != nil { - // This should never happen, as the bytes.Buffer reader will never return error on Write - gclog().Error("can't encode Grafana OTLP Authorization header. Leaving empty", "error", err) - return "" - } - return encodedKey.String() + return "Basic " + base64.StdEncoding.EncodeToString([]byte(cfg.InstanceID+":"+cfg.APIKey)) } func (cfg *GrafanaOTLP) setupOptions(opt *otlpOptions) {