Skip to content

Commit

Permalink
testutil: fixed promrated.go (#2815)
Browse files Browse the repository at this point in the history
Fixing promrated.go (resolving TODOs).

category: misc
ticket: none
  • Loading branch information
pinebit committed Jan 24, 2024
1 parent 4d66a10 commit 84b9457
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
14 changes: 12 additions & 2 deletions testutil/promrated/promrated.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package promrated

import (
"context"
"net/url"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand All @@ -27,8 +28,7 @@ type Config struct {
// Run blocks running the promrated program until the context is canceled or a fatal error occurs.
func Run(ctx context.Context, config Config) error {
log.Info(ctx, "Promrated started",
z.Str("rated_endpoint", config.RatedEndpoint), // TODO(corver): This may contain a password
z.Str("prom_auth", config.PromAuth), // TODO(corver): This may contain a password
z.Str("rated_endpoint", redactURL(config.RatedEndpoint)),
z.Str("monitoring_addr", config.MonitoringAddr),
)

Expand Down Expand Up @@ -131,3 +131,13 @@ func contains(arr []string, s string) bool {

return result
}

// redactURL returns a redacted version of the given URL.
func redactURL(val string) string {
u, err := url.Parse(val)
if err != nil {
return val
}

return u.Redacted()
}
17 changes: 17 additions & 0 deletions testutil/promrated/promrated_internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright © 2022-2023 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1

package promrated

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestRedactURL(t *testing.T) {
url := "https://user:password@domain.com"

redacted := redactURL(url)

require.Equal(t, "https://user:xxxxx@domain.com", redacted)
}

0 comments on commit 84b9457

Please sign in to comment.