Skip to content

Commit

Permalink
trivial. workarround fix that incorrectly recorded in audit
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed Feb 29, 2024
1 parent 34fe3ca commit 82113eb
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions internal/middleware/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,26 @@ func (a *defaultAudit) WithAudit(endpoint internalApi.Endpoint, handler http.Han

message, description := "", ""
if fn, ok := auditMap[endpoint]; ok {
body, err := io.ReadAll(r.Body)
if err != nil {
log.Error(err)
}
message, description = fn(lrw.GetBody(), body, statusCode)
r.Body = io.NopCloser(bytes.NewBuffer(body))
// workarround pingtoken
if endpoint != internalApi.PingToken {
body, err := io.ReadAll(r.Body)
if err != nil {
log.Error(err)
}
message, description = fn(lrw.GetBody(), body, statusCode)
r.Body = io.NopCloser(bytes.NewBuffer(body))

dto := domain.Audit{
OrganizationId: organizationId,
Group: internalApi.ApiMap[endpoint].Group,
Message: message,
Description: description,
ClientIP: GetClientIpAddress(w, r),
UserId: &userId,
}
if _, err := a.repo.Create(dto); err != nil {
log.Error(err)
dto := domain.Audit{
OrganizationId: organizationId,
Group: internalApi.ApiMap[endpoint].Group,
Message: message,
Description: description,
ClientIP: GetClientIpAddress(w, r),
UserId: &userId,
}
if _, err := a.repo.Create(dto); err != nil {
log.Error(err)
}
}
}

Expand Down

0 comments on commit 82113eb

Please sign in to comment.