Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
satellitedb/metabase: do not log password when connected
Passwords should never be printed out, even if debug level is used. Change-Id: Ib6af301f442374a2bb3561c84fc8d7c1f66fba25
- Loading branch information
Showing
4 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (C) 2024 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package logging | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
// Redacted removes the password from a URL string. | ||
func Redacted(source string) string { | ||
parsed, err := url.Parse(source) | ||
if err != nil { | ||
return fmt.Sprintf("redacting password from URL was not possible: %s", err.Error()) | ||
} | ||
return parsed.Redacted() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (C) 2024 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package logging | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRedacted(t *testing.T) { | ||
require.Equal(t, "cockroach://root@localhost:26257/env1?sslmode=disable", Redacted("cockroach://root@localhost:26257/env1?sslmode=disable")) | ||
require.Equal(t, "cockroach://root:xxxxx@localhost:26257/env1?sslmode=disable", Redacted("cockroach://root:mypassword@localhost:26257/env1?sslmode=disable")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters