diff --git a/checker/mysql/mysql.go b/checker/mysql/mysql.go index 2150aa0..e247007 100644 --- a/checker/mysql/mysql.go +++ b/checker/mysql/mysql.go @@ -22,8 +22,11 @@ import ( "wait4x.dev/v2/checker" // Needed for the MySQL driver _ "github.com/go-sql-driver/mysql" + "regexp" ) +var hidePasswordRegexp = regexp.MustCompile(`^([^:]+):[^:@]+@`) + // MySQL represents MySQL checker type MySQL struct { dsn string @@ -66,7 +69,7 @@ func (m *MySQL) Check(ctx context.Context) (err error) { if checker.IsConnectionRefused(err) { return checker.NewExpectedError( "failed to establish a connection to the mysql server", err, - "dsn", m.dsn, + "dsn", hidePasswordRegexp.ReplaceAllString(m.dsn, `$1:***@`), ) } diff --git a/checker/postgresql/postgresql.go b/checker/postgresql/postgresql.go index c8d200d..f1d0e8f 100644 --- a/checker/postgresql/postgresql.go +++ b/checker/postgresql/postgresql.go @@ -22,8 +22,11 @@ import ( "wait4x.dev/v2/checker" // Needed for the PostgreSQL driver _ "github.com/lib/pq" + "regexp" ) +var hidePasswordRegexp = regexp.MustCompile(`^(postgres://[^/:]+):[^:@]+@`) + // PostgreSQL represents PostgreSQL checker type PostgreSQL struct { dsn string @@ -66,7 +69,7 @@ func (p *PostgreSQL) Check(ctx context.Context) (err error) { if checker.IsConnectionRefused(err) { return checker.NewExpectedError( "failed to establish a connection to the postgresql server", err, - "dsn", p.dsn, + "dsn", hidePasswordRegexp.ReplaceAllString(p.dsn, `$1:***@`), ) } diff --git a/checker/rabbitmq/rabbitmq.go b/checker/rabbitmq/rabbitmq.go index 2e0a8b1..859dfa7 100644 --- a/checker/rabbitmq/rabbitmq.go +++ b/checker/rabbitmq/rabbitmq.go @@ -20,10 +20,13 @@ import ( "fmt" "github.com/streadway/amqp" "net" + "regexp" "time" "wait4x.dev/v2/checker" ) +var hidePasswordRegexp = regexp.MustCompile(`(amqp://[^/:]+):[^:@]+@`) + // Option configures a RabbitMQ. type Option func(r *RabbitMQ) @@ -118,7 +121,7 @@ func (r *RabbitMQ) Check(ctx context.Context) (err error) { if checker.IsConnectionRefused(err) { return checker.NewExpectedError( "failed to establish a connection to the rabbitmq server", err, - "dsn", r.dsn, + "dsn", hidePasswordRegexp.ReplaceAllString(r.dsn, `$1:***@`), ) } diff --git a/checker/redis/redis.go b/checker/redis/redis.go index 3840867..d33a359 100644 --- a/checker/redis/redis.go +++ b/checker/redis/redis.go @@ -24,6 +24,8 @@ import ( "wait4x.dev/v2/checker" ) +var hidePasswordRegexp = regexp.MustCompile(`([^/]+//[^/:]+):[^:@]+@`) + // Option configures a Redis. type Option func(r *Redis) @@ -94,7 +96,7 @@ func (r *Redis) Check(ctx context.Context) error { if checker.IsConnectionRefused(err) { return checker.NewExpectedError( "failed to establish a connection to the redis server", err, - "dsn", r.address, + "dsn", hidePasswordRegexp.ReplaceAllString(r.address, `$1:***@`), ) }