package main
import (
"fmt"
"git.neuromancer.ovh/bastien-mrq/gitfed/internal/store"
)
type userItem struct{ u store.User }
func (i userItem) Title() string { return i.u.Username }
func (i userItem) Description() string {
return fmt.Sprintf("%d key(s)", len(i.u.PubKeys))
}
func (i userItem) FilterValue() string { return i.u.Username }
type repoItem struct{ r store.Repo }
func (i repoItem) Title() string { return i.r.Name }
func (i repoItem) Description() string { return "owner: " + i.r.Owner }
func (i repoItem) FilterValue() string { return i.r.Name }
type collaboratorItem struct {
c store.Collaborator
isOwner bool
}
func (i collaboratorItem) Title() string {
if i.isOwner {
return i.c.Principal + " (owner)"
}
return i.c.Principal
}
func (i collaboratorItem) Description() string { return string(i.c.Role) }
func (i collaboratorItem) FilterValue() string { return i.c.Principal }
type trustItem struct{ t store.TrustedCA }
func (i trustItem) Title() string { return i.t.Domain }
func (i trustItem) Description() string { return string(i.t.Status) }
func (i trustItem) FilterValue() string { return i.t.Domain }
type auditItem struct{ e store.AuditEvent }
func (i auditItem) Title() string {
mark := "✓"
if !i.e.Allowed {
mark = "✗"
}
return fmt.Sprintf("%s %s %s", mark, i.e.Time.Local().Format("15:04:05"), i.e.Action)
}
func (i auditItem) Description() string {
who := i.e.Principal
if who == "" {
who = "?"
}
target := i.e.Repo
if target == "" {
target = i.e.Domain
}
s := who
if target != "" {
s += " · " + target
}
if i.e.Detail != "" {
s += " · " + i.e.Detail
}
return s
}
func (i auditItem) FilterValue() string { return i.e.Action + " " + i.e.Principal }
type menuItem struct{ title, desc string }
func (i menuItem) Title() string { return i.title }
func (i menuItem) Description() string { return i.desc }
func (i menuItem) FilterValue() string { return i.title }