Audit wrap info

This commit is contained in:
Jeff Mitchell 2016-05-07 19:19:19 -04:00
parent e36f66000e
commit fdde9e1697

View File

@ -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 {