Commit d9cbb994 by Ricky Niemi

Clean up audit log formatting and code

parent d03977ac
...@@ -2,7 +2,6 @@ package api ...@@ -2,7 +2,6 @@ package api
import ( import (
"bytes" "bytes"
"fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
...@@ -133,17 +132,14 @@ func ProxyDataSourceRequest(c *middleware.Context) { ...@@ -133,17 +132,14 @@ func ProxyDataSourceRequest(c *middleware.Context) {
} }
func outputToAuditLog(dataSourceType string, c *middleware.Context) { func outputToAuditLog(dataSourceType string, c *middleware.Context) {
auditLogger := log.New("data-proxy-audit", "userId", c.UserId, "orgId", c.OrgId, "uname", c.Login) auditLogger := log.New("data-proxy-audit", "userid", c.UserId, "orgid", c.OrgId, "username", c.Login)
bodyString := "" var body string
if c.Req.Request.Body != nil { if c.Req.Request.Body != nil {
reqBody := c.Req.Request.Body buffer, _ := ioutil.ReadAll(c.Req.Request.Body)
buffer, _ := ioutil.ReadAll(reqBody)
c.Req.Request.Body = ioutil.NopCloser(bytes.NewBuffer(buffer)) c.Req.Request.Body = ioutil.NopCloser(bytes.NewBuffer(buffer))
bodyString = string(buffer) body = string(buffer)
} }
logFormat := "Datasource: %s, URI: %s, Method: %s, Body: %s" auditLogger.Info("Proxying incoming request", "datasource", dataSourceType, "uri", c.Req.RequestURI, "method", c.Req.Request.Method, "body", body)
auditLogger.Info(fmt.Sprintf(logFormat, dataSourceType, c.Req.RequestURI, c.Req.Request.Method, bodyString))
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment