Skip to content

Commit db6228e

Browse files
committed
feat: add AuditLogEntry type and integrate recent logs into dashboard model instead of calling from core
1 parent 369fa96 commit db6228e

2 files changed

Lines changed: 35 additions & 34 deletions

File tree

client/client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ type Link struct {
126126
// ...
127127
}
128128

129+
// AuditLogEntry represents a single audit event returned by client backends.
130+
type AuditLogEntry struct {
131+
ID int
132+
Timestamp string
133+
Username string
134+
Action string
135+
Details string
136+
}
137+
129138
type DeployProgressAccount struct {
130139
Progress float64
131140
Status string

ui/tui/views/dashboard/model.go

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ import (
1515
tea "github.com/charmbracelet/bubbletea"
1616
"github.com/charmbracelet/lipgloss"
1717
"github.com/toeirei/keymaster/client"
18-
"github.com/toeirei/keymaster/core"
19-
"github.com/toeirei/keymaster/core/model"
2018
"github.com/toeirei/keymaster/i18n"
2119
"github.com/toeirei/keymaster/ui/tui/helpers/tablecontroll"
2220
"github.com/toeirei/keymaster/ui/tui/util"
23-
"github.com/toeirei/keymaster/uiadapters"
2421
"github.com/toeirei/keymaster/util/slicest"
2522
)
2623

@@ -37,8 +34,7 @@ type Data = struct {
3734
RecentLogs []AuditLogEntry
3835
}
3936

40-
// copied from keymaster core for now
41-
type AuditLogEntry = model.AuditLogEntry
37+
type AuditLogEntry = client.AuditLogEntry
4238

4339
type recentActivityRow struct {
4440
Timestamp string
@@ -275,45 +271,41 @@ func (m *Model) reload() tea.Cmd {
275271
// TODO add empty skeleton loading state
276272

277273
return func() tea.Msg {
278-
// Prefer canonical dashboard aggregation from core to avoid placeholder data
279-
// and keep dashboard behavior aligned across UIs.
280-
coreData, err := core.BuildDashboardData(uiadapters.NewStoreAdapter())
281-
if err == nil {
282-
return msgReloadResult{data: Data{
283-
AccountCount: coreData.AccountCount,
284-
ActiveAccountCount: coreData.ActiveAccountCount,
285-
HostsUpToDate: coreData.HostsUpToDate,
286-
HostsOutdated: coreData.HostsOutdated,
287-
SystemKeySerial: coreData.SystemKeySerial,
288-
RecentLogs: coreData.RecentLogs,
289-
}}
290-
}
274+
ctx := context.Background()
291275

292-
// Fallback to the client-based approximation for environments that do not
293-
// have core DB services initialized (for example, isolated TUI test clients).
294-
accounts, err := m.client.ListAccounts(context.Background())
276+
accounts, err := m.client.ListAccounts(ctx)
295277
if err != nil {
296278
return msgReloadResult{err: err}
297279
}
298280

299-
publicKeys, err := m.client.ListPublicKeys(context.Background(), "")
281+
publicKeys, err := m.client.ListPublicKeys(ctx, "")
300282
if err != nil {
301283
return msgReloadResult{err: err}
302284
}
303285

304-
dirtyAccounts, err := slicest.FilterX(accounts, func(account client.Account) (bool, error) {
305-
return m.client.IsAccountDirty(context.Background(), account)
306-
})
286+
dirtyAccounts, err := m.client.ListAccountsDirty(ctx)
307287
if err != nil {
308288
return msgReloadResult{err: err}
309289
}
310290

291+
recentLogs := []AuditLogEntry{}
292+
type recentAuditLogLister interface {
293+
ListRecentAuditLogEntries(ctx context.Context, limit int) ([]client.AuditLogEntry, error)
294+
}
295+
if lister, ok := m.client.(recentAuditLogLister); ok {
296+
logs, lerr := lister.ListRecentAuditLogEntries(ctx, 25)
297+
if lerr != nil {
298+
return msgReloadResult{err: lerr}
299+
}
300+
recentLogs = logs
301+
}
302+
311303
return msgReloadResult{data: Data{
312-
len(accounts),
313-
len(slicest.Filter(accounts, func(account client.Account) bool { return true /* cant't deactivate accounts */ })),
314-
len(publicKeys),
315-
0, // TODO does not exist in client
316-
slicest.ToMap(
304+
AccountCount: len(accounts),
305+
ActiveAccountCount: len(accounts), // TODO client API currently has no account activation state
306+
PublicKeyCount: len(publicKeys),
307+
GlobalKeyCount: 0, // TODO client API currently has no global-key flag on PublicKey
308+
AlgoCounts: slicest.ToMap(
317309
slicest.Reduce(
318310
slicest.Map(
319311
publicKeys,
@@ -330,10 +322,10 @@ func (m *Model) reload() tea.Cmd {
330322
return algo, len(slicest.Filter(publicKeys, func(publicKey client.PublicKey) bool { return publicKey.Algorithm == algo }))
331323
},
332324
),
333-
len(accounts) - len(dirtyAccounts),
334-
len(dirtyAccounts),
335-
0, // TODO does not exist in client
336-
nil, // TODO does not exist in client yet (needs to be added)
325+
HostsUpToDate: len(accounts) - len(dirtyAccounts),
326+
HostsOutdated: len(dirtyAccounts),
327+
SystemKeySerial: 0,
328+
RecentLogs: recentLogs,
337329
}}
338330
}
339331
}

0 commit comments

Comments
 (0)