Skip to content

Commit

Permalink
redact url (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivanshgaur authored Apr 22, 2020
1 parent 107e5de commit 9a9a169
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
14 changes: 12 additions & 2 deletions v1/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package machinery
import (
"errors"
"fmt"
"net/url"
"os"
"os/signal"
"syscall"
Expand Down Expand Up @@ -52,13 +53,13 @@ func (worker *Worker) LaunchAsync(errorsChan chan<- error) {

// Log some useful information about worker configuration
log.INFO.Printf("Launching a worker with the following settings:")
log.INFO.Printf("- Broker: %s", cnf.Broker)
log.INFO.Printf("- Broker: %s", RedactURL(cnf.Broker))
if worker.Queue == "" {
log.INFO.Printf("- DefaultQueue: %s", cnf.DefaultQueue)
} else {
log.INFO.Printf("- CustomQueue: %s", worker.Queue)
}
log.INFO.Printf("- ResultBackend: %s", cnf.ResultBackend)
log.INFO.Printf("- ResultBackend: %s", RedactURL(cnf.ResultBackend))
if cnf.AMQP != nil {
log.INFO.Printf("- AMQP: %s", cnf.AMQP.Exchange)
log.INFO.Printf(" - Exchange: %s", cnf.AMQP.Exchange)
Expand Down Expand Up @@ -403,3 +404,12 @@ func (worker *Worker) SetPostTaskHandler(handler func(*tasks.Signature)) {
func (worker *Worker) GetServer() *Server {
return worker.server
}


func RedactURL(urlString string) string {
u, err := url.Parse(urlString)
if err != nil {
return urlString
}
return fmt.Sprintf("%s://%s", u.Scheme, u.Host)
}
14 changes: 14 additions & 0 deletions v1/worker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package machinery

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestRedactURL(t *testing.T) {
t.Parallel()

broker := "amqp://guest:guest@localhost:5672"
redactedURL := RedactURL(broker)
assert.Equal(t, "amqp://localhost:5672", redactedURL)
}
5 changes: 3 additions & 2 deletions v2/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/opentracing/opentracing-go"

"github.com/RichardKnop/machinery/v1"
"github.com/RichardKnop/machinery/v1/backends/amqp"
"github.com/RichardKnop/machinery/v1/brokers/errs"
"github.com/RichardKnop/machinery/v1/log"
Expand Down Expand Up @@ -46,13 +47,13 @@ func (worker *Worker) LaunchAsync(errorsChan chan<- error) {

// Log some useful information about worker configuration
log.INFO.Printf("Launching a worker with the following settings:")
log.INFO.Printf("- Broker: %s", cnf.Broker)
log.INFO.Printf("- Broker: %s", machinery.RedactURL(cnf.Broker))
if worker.Queue == "" {
log.INFO.Printf("- DefaultQueue: %s", cnf.DefaultQueue)
} else {
log.INFO.Printf("- CustomQueue: %s", worker.Queue)
}
log.INFO.Printf("- ResultBackend: %s", cnf.ResultBackend)
log.INFO.Printf("- ResultBackend: %s", machinery.RedactURL(cnf.ResultBackend))
if cnf.AMQP != nil {
log.INFO.Printf("- AMQP: %s", cnf.AMQP.Exchange)
log.INFO.Printf(" - Exchange: %s", cnf.AMQP.Exchange)
Expand Down

0 comments on commit 9a9a169

Please sign in to comment.