@@ -25,14 +25,10 @@ type AuditFormatter struct {
25
25
AuditFormatWriter
26
26
}
27
27
28
- func (f * AuditFormatter ) FormatRequest (
29
- w io.Writer ,
30
- config FormatterConfig ,
31
- auth * logical.Auth ,
32
- req * logical.Request ,
33
- inErr error ) error {
34
-
35
- if req == nil {
28
+ var _ Formatter = (* AuditFormatter )(nil )
29
+
30
+ func (f * AuditFormatter ) FormatRequest (w io.Writer , config FormatterConfig , in * LogInput ) error {
31
+ if in == nil || in .Request == nil {
36
32
return fmt .Errorf ("request to request-audit a nil request" )
37
33
}
38
34
@@ -49,28 +45,31 @@ func (f *AuditFormatter) FormatRequest(
49
45
return errwrap .Wrapf ("error fetching salt: {{err}}" , err )
50
46
}
51
47
48
+ // Set these to the input values at first
49
+ auth := in .Auth
50
+ req := in .Request
51
+
52
52
if ! config .Raw {
53
53
// Before we copy the structure we must nil out some data
54
54
// otherwise we will cause reflection to panic and die
55
- if req .Connection != nil && req .Connection .ConnState != nil {
56
- origReq := req
57
- origState := req .Connection .ConnState
58
- req .Connection .ConnState = nil
55
+ if in .Request .Connection != nil && in .Request .Connection .ConnState != nil {
56
+ origState := in .Request .Connection .ConnState
57
+ in .Request .Connection .ConnState = nil
59
58
defer func () {
60
- origReq .Connection .ConnState = origState
59
+ in . Request .Connection .ConnState = origState
61
60
}()
62
61
}
63
62
64
63
// Copy the auth structure
65
- if auth != nil {
66
- cp , err := copystructure .Copy (auth )
64
+ if in . Auth != nil {
65
+ cp , err := copystructure .Copy (in . Auth )
67
66
if err != nil {
68
67
return err
69
68
}
70
69
auth = cp .(* logical.Auth )
71
70
}
72
71
73
- cp , err := copystructure .Copy (req )
72
+ cp , err := copystructure .Copy (in . Request )
74
73
if err != nil {
75
74
return err
76
75
}
@@ -83,7 +82,7 @@ func (f *AuditFormatter) FormatRequest(
83
82
if ! config .HMACAccessor && auth .Accessor != "" {
84
83
authAccessor = auth .Accessor
85
84
}
86
- if err := Hash (salt , auth ); err != nil {
85
+ if err := Hash (salt , auth , nil ); err != nil {
87
86
return err
88
87
}
89
88
if authAccessor != "" {
@@ -96,7 +95,7 @@ func (f *AuditFormatter) FormatRequest(
96
95
if ! config .HMACAccessor && req != nil && req .ClientTokenAccessor != "" {
97
96
clientTokenAccessor = req .ClientTokenAccessor
98
97
}
99
- if err := Hash (salt , req ); err != nil {
98
+ if err := Hash (salt , req , in . NonHMACReqDataKeys ); err != nil {
100
99
return err
101
100
}
102
101
if clientTokenAccessor != "" {
@@ -109,8 +108,8 @@ func (f *AuditFormatter) FormatRequest(
109
108
auth = new (logical.Auth )
110
109
}
111
110
var errString string
112
- if inErr != nil {
113
- errString = inErr .Error ()
111
+ if in . OuterErr != nil {
112
+ errString = in . OuterErr .Error ()
114
113
}
115
114
116
115
reqEntry := & AuditRequestEntry {
@@ -152,15 +151,8 @@ func (f *AuditFormatter) FormatRequest(
152
151
return f .AuditFormatWriter .WriteRequest (w , reqEntry )
153
152
}
154
153
155
- func (f * AuditFormatter ) FormatResponse (
156
- w io.Writer ,
157
- config FormatterConfig ,
158
- auth * logical.Auth ,
159
- req * logical.Request ,
160
- resp * logical.Response ,
161
- inErr error ) error {
162
-
163
- if req == nil {
154
+ func (f * AuditFormatter ) FormatResponse (w io.Writer , config FormatterConfig , in * LogInput ) error {
155
+ if in == nil || in .Request == nil {
164
156
return fmt .Errorf ("request to response-audit a nil request" )
165
157
}
166
158
@@ -177,35 +169,39 @@ func (f *AuditFormatter) FormatResponse(
177
169
return errwrap .Wrapf ("error fetching salt: {{err}}" , err )
178
170
}
179
171
172
+ // Set these to the input values at first
173
+ auth := in .Auth
174
+ req := in .Request
175
+ resp := in .Response
176
+
180
177
if ! config .Raw {
181
178
// Before we copy the structure we must nil out some data
182
179
// otherwise we will cause reflection to panic and die
183
- if req .Connection != nil && req .Connection .ConnState != nil {
184
- origReq := req
185
- origState := req .Connection .ConnState
186
- req .Connection .ConnState = nil
180
+ if in .Request .Connection != nil && in .Request .Connection .ConnState != nil {
181
+ origState := in .Request .Connection .ConnState
182
+ in .Request .Connection .ConnState = nil
187
183
defer func () {
188
- origReq .Connection .ConnState = origState
184
+ in . Request .Connection .ConnState = origState
189
185
}()
190
186
}
191
187
192
188
// Copy the auth structure
193
- if auth != nil {
194
- cp , err := copystructure .Copy (auth )
189
+ if in . Auth != nil {
190
+ cp , err := copystructure .Copy (in . Auth )
195
191
if err != nil {
196
192
return err
197
193
}
198
194
auth = cp .(* logical.Auth )
199
195
}
200
196
201
- cp , err := copystructure .Copy (req )
197
+ cp , err := copystructure .Copy (in . Request )
202
198
if err != nil {
203
199
return err
204
200
}
205
201
req = cp .(* logical.Request )
206
202
207
- if resp != nil {
208
- cp , err := copystructure .Copy (resp )
203
+ if in . Response != nil {
204
+ cp , err := copystructure .Copy (in . Response )
209
205
if err != nil {
210
206
return err
211
207
}
@@ -220,7 +216,7 @@ func (f *AuditFormatter) FormatResponse(
220
216
if ! config .HMACAccessor && auth .Accessor != "" {
221
217
accessor = auth .Accessor
222
218
}
223
- if err := Hash (salt , auth ); err != nil {
219
+ if err := Hash (salt , auth , nil ); err != nil {
224
220
return err
225
221
}
226
222
if accessor != "" {
@@ -233,7 +229,7 @@ func (f *AuditFormatter) FormatResponse(
233
229
if ! config .HMACAccessor && req != nil && req .ClientTokenAccessor != "" {
234
230
clientTokenAccessor = req .ClientTokenAccessor
235
231
}
236
- if err := Hash (salt , req ); err != nil {
232
+ if err := Hash (salt , req , in . NonHMACReqDataKeys ); err != nil {
237
233
return err
238
234
}
239
235
if clientTokenAccessor != "" {
@@ -250,7 +246,7 @@ func (f *AuditFormatter) FormatResponse(
250
246
wrappedAccessor = resp .WrapInfo .WrappedAccessor
251
247
wrappingAccessor = resp .WrapInfo .Accessor
252
248
}
253
- if err := Hash (salt , resp ); err != nil {
249
+ if err := Hash (salt , resp , in . NonHMACRespDataKeys ); err != nil {
254
250
return err
255
251
}
256
252
if accessor != "" {
@@ -273,8 +269,8 @@ func (f *AuditFormatter) FormatResponse(
273
269
resp = new (logical.Response )
274
270
}
275
271
var errString string
276
- if inErr != nil {
277
- errString = inErr .Error ()
272
+ if in . OuterErr != nil {
273
+ errString = in . OuterErr .Error ()
278
274
}
279
275
280
276
var respAuth * AuditAuth
@@ -358,7 +354,7 @@ func (f *AuditFormatter) FormatResponse(
358
354
return f .AuditFormatWriter .WriteResponse (w , respEntry )
359
355
}
360
356
361
- // AuditRequest is the structure of a request audit log entry in Audit.
357
+ // AuditRequestEntry is the structure of a request audit log entry in Audit.
362
358
type AuditRequestEntry struct {
363
359
Time string `json:"time,omitempty"`
364
360
Type string `json:"type"`
0 commit comments