Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions cmd/audit_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ func (c AuditLogsCmd) Search(ctx context.Context, in AuditLogsSearchInput) error
return nil
}

table := pterm.TableData{{"Timestamp", "Method", "Status", "Path", "User", "Duration (ms)", "Client IP"}}
table := pterm.TableData{{"Timestamp", "Method", "Status", "Path", "User", "User ID", "Duration (ms)", "Client IP"}}
for _, entry := range entries {
table = append(table, []string{
util.FormatLocal(entry.Timestamp),
entry.Method,
strconv.FormatInt(entry.Status, 10),
entry.Path,
formatAuditLogUser(entry),
entry.UserID,
strconv.FormatInt(entry.DurationMs, 10),
entry.ClientIP,
})
Expand Down Expand Up @@ -156,13 +157,10 @@ func parseAuditLogTime(value string) (time.Time, error) {
}

func formatAuditLogUser(entry kernel.AuditLogEntry) string {
if entry.Email != "" {
return entry.Email
if entry.Email == "" {
return "-"
}
if entry.UserID != "" {
return entry.UserID
}
return "-"
return entry.Email
}

func getAuditLogsHandler(cmd *cobra.Command) AuditLogsCmd {
Expand Down
8 changes: 8 additions & 0 deletions cmd/audit_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,17 @@ func TestAuditLogsSearchBuildsParamsAndPrintsTable(t *testing.T) {
assert.Contains(t, out, "POST")
assert.Contains(t, out, "201")
assert.Contains(t, out, "dev@example.com")
assert.Contains(t, out, "user_123")
assert.Contains(t, out, "203.0.113.7")
}

func TestFormatAuditLogUserDoesNotRepeatUserIDWhenEmailMissing(t *testing.T) {
entry := sampleAuditLogEntry("POST", "/browsers")
entry.Email = ""

assert.Equal(t, "-", formatAuditLogUser(entry))
}

func TestAuditLogsSearchRejectsInvalidStart(t *testing.T) {
c := AuditLogsCmd{auditLogs: &FakeAuditLogsService{}}

Expand Down
Loading