Skip to content

Commit

Permalink
Fix Basic auth key encoding (grafana#446)
Browse files Browse the repository at this point in the history
* Fix Basic auth key encoding

* Fix linting
  • Loading branch information
mariomac authored Nov 16, 2023
1 parent 90bcc62 commit ff790ad
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions pkg/internal/export/otel/grafana.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ff790ad

Please sign in to comment.