From fdde9e16975c19286803a997731ce2334178bd5e Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sat, 7 May 2016 19:19:19 -0400 Subject: [PATCH] Audit wrap info --- audit/format_json.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/audit/format_json.go b/audit/format_json.go index 87d9057571..f3544c823f 100644 --- a/audit/format_json.go +++ b/audit/format_json.go @@ -46,6 +46,7 @@ func (f *FormatJSON) FormatRequest( Path: req.Path, Data: req.Data, RemoteAddr: getRemoteAddr(req), + WrapTTL: int64(req.WrapTTL / time.Second), }, }) } @@ -86,6 +87,14 @@ func (f *FormatJSON) FormatResponse( } } + var respWrapInfo *JSONWrapInfo + if resp.WrapInfo != nil { + respWrapInfo = &JSONWrapInfo{ + TTL: int64(resp.WrapInfo.TTL / time.Second), + Token: resp.WrapInfo.Token, + } + } + // Encode! enc := json.NewEncoder(w) return enc.Encode(&JSONResponseEntry{ @@ -104,6 +113,7 @@ func (f *FormatJSON) FormatResponse( Path: req.Path, Data: req.Data, RemoteAddr: getRemoteAddr(req), + WrapTTL: int64(req.WrapTTL / time.Second), }, Response: JSONResponse{ @@ -111,6 +121,7 @@ func (f *FormatJSON) FormatResponse( Secret: respSecret, Data: resp.Data, Redirect: resp.Redirect, + WrapInfo: respWrapInfo, }, }) } @@ -140,6 +151,7 @@ type JSONRequest struct { Path string `json:"path"` Data map[string]interface{} `json:"data"` RemoteAddr string `json:"remote_address"` + WrapTTL int64 `json:"wrap_ttl"` } type JSONResponse struct { @@ -147,6 +159,7 @@ type JSONResponse struct { Secret *JSONSecret `json:"secret,emitempty"` Data map[string]interface{} `json:"data"` Redirect string `json:"redirect"` + WrapInfo *JSONWrapInfo `json:"wrap_info,omitempty"` } type JSONAuth struct { @@ -161,6 +174,11 @@ type JSONSecret struct { LeaseID string `json:"lease_id"` } +type JSONWrapInfo struct { + TTL int64 `json:"ttl"` + Token string `json:"token"` +} + // getRemoteAddr safely gets the remote address avoiding a nil pointer func getRemoteAddr(req *logical.Request) string { if req != nil && req.Connection != nil {