Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions pkg/client/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c *HttpClient) authenticate() {
logger.Fatal(err, "could not marshal credentials")
}

req := NewRequest("/login", WithBody(b))
req := NewRequest("/login", WithBody(b), WithNoLog(true))

res, err := c.send("POST", req)
if err != nil {
Expand Down Expand Up @@ -113,17 +113,13 @@ func (c *HttpClient) send(method string, request *Request) (*Response, error) {

logger.Info("%s %s", method, u.String())

debugOutput := string(request.Body)

if debugOutput != "" {
// FIXME (privateip) this is a quick hack to prevent the logger from
// showing the username and password used to authenticate to the
// server. A better mechanism should be implemented
if request.Path != "/login" {
if !request.NoLog {
debugOutput := string(request.Body)
if debugOutput != "" {
logger.Debug(string(request.Body))
} else {
logger.Debug("Request body is empty")
}
} else {
logger.Debug("Request body is empty")
}

client := &http.Client{Jar: c.jar}
Expand Down
13 changes: 13 additions & 0 deletions pkg/client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type Request struct {

// The HTTP body to be send to the remote host
Body []byte

// Enable or disable logging this request
NoLog bool
}

// Defines a new HTTP request object.
Expand Down Expand Up @@ -54,3 +57,13 @@ func WithBody(v []byte) RequestOption {
r.Body = v
}
}

// NoLog allows a calling function to disable logging to stdout or file for
// this request. This is useful when making API calls where the calling
// function does not want reveal sensitive information such as calling
// `/login` for example.
func WithNoLog(v bool) RequestOption {
return func(r *Request) {
r.NoLog = v
}
}
Loading