feat: lazysecrets list prints notes, and --demo has a couple

This commit is contained in:
keb committed 2026-10-14 21:24:01 +02:00
1 parent 2c9c37f809
commit 824f7249c3
4 files changed
+31 -18

No files matched your search

+6 -4
View File
@@ -49,6 +49,8 @@ type Entry struct {
// Enabled whether it's enabled, where the provider says (Azure).
Expires time.Time `json:"expires,omitzero"`
Enabled *bool `json:"enabled,omitempty"`
// Note is the user's note on it, if any.
Note string `json:"note,omitempty"`
// Error says why a source's vaults or a vault's secrets couldn't be
// listed. The entry is then that source or vault, again, or with an
// account's sources unreadable, the account without a link.
@@ -68,9 +70,9 @@ type Options struct {
// alone don't load any secrets. Lists that fail are always listed.
Kinds []string
// Mark tells whether the entry with link is starred for account,
// and when it was last used and how often (zero: not lately); nil
// marks nothing.
Mark func(link, account string) (starred bool, lastUsed time.Time, uses int)
// when it was last used and how often (zero: not lately), and its
// note; nil marks nothing.
Mark func(link, account string) (starred bool, lastUsed time.Time, uses int, note string)
Timeout func(provider.Kind) time.Duration
Now func() time.Time
}
@@ -233,7 +235,7 @@ func (l *lister) put(p provider.Provider, e Entry) {
}
e.Account = p.ID()
if l.o.Mark != nil && e.Link != "" {
e.Starred, e.LastUsed, e.Uses = l.o.Mark(e.Link, e.Account)
e.Starred, e.LastUsed, e.Uses, e.Note = l.o.Mark(e.Link, e.Account)
e.Recent = !e.LastUsed.IsZero()
}
id := p.ID() + "\x00" + e.Link + "\x00" + e.Error
+6 -3
View File
@@ -229,14 +229,14 @@ func TestListMarks(t *testing.T) {
az := fake.Azure(0)
var starredLink string
got, _, _ := run(t, Options{Providers: []provider.Provider{az}, MaxAge: time.Minute, Kinds: []string{"secret"},
Mark: func(link, account string) (bool, time.Time, int) {
Mark: func(link, account string) (bool, time.Time, int, string) {
if starredLink == "" && strings.HasSuffix(link, "/db-password") {
starredLink = link
}
if strings.HasSuffix(link, "/api-key") {
return false, time.Now(), 3
return false, time.Now(), 3, "rotate in May"
}
return link == starredLink && account == az.ID(), time.Time{}, 0
return link == starredLink && account == az.ID(), time.Time{}, 0, ""
}})
var starred, recent int
for _, e := range got {
@@ -246,6 +246,9 @@ func TestListMarks(t *testing.T) {
t.Errorf("%s starred", e.Link)
}
}
if (e.Note != "") != strings.HasSuffix(e.Link, "/api-key") {
t.Errorf("%s: note %q", e.Link, e.Note)
}
if e.Recent {
recent++
if e.Uses != 3 || e.LastUsed.IsZero() {
+11 -6
View File
@@ -8,13 +8,14 @@ import (
"git.kebcloud.no/keb/lazysecrets/internal/store"
)
// Seed stars and uses a few of the demo's secrets, so --demo shows
// Favourites (F), Recent (R) and stars in lazysecrets list. alice and
// Seed stars, notes and uses a few of the demo's secrets, so --demo
// shows Favourites (F), Recent (R), notes, and stars in lazysecrets list. alice and
// admin are the two Azure accounts' provider IDs.
func Seed(st *store.Store, alice, admin string) {
type item struct {
link, account, source string
name string // else the link's last part
note string
path []string
star bool
uses int
@@ -23,11 +24,12 @@ func Seed(st *store.Store, alice, admin string) {
const azure, dbx = "lazysecrets://azure/", "lazysecrets://databricks/adb-1111111111111111.11.azuredatabricks.net/"
for _, it := range []item{
{link: azure + "kv-app-prod.vault.azure.net/secrets/db-password", account: alice, source: "sub-prod",
path: []string{"platform-prod", "kv-app-prod"}, star: true, uses: 12, ago: 20 * time.Minute},
path: []string{"platform-prod", "kv-app-prod"}, star: true, uses: 12, ago: 20 * time.Minute,
note: "rotated by the data team each quarter"},
{link: azure + "kv-app-prod.vault.azure.net/secrets/api-key", account: alice, source: "sub-prod",
path: []string{"platform-prod", "kv-app-prod"}, uses: 4, ago: 2 * time.Hour},
{link: azure + "kv-breakglass.vault.azure.net/secrets/emergency-admin", account: admin, source: "sub-prod",
path: []string{"platform-prod", "kv-breakglass"}, star: true},
path: []string{"platform-prod", "kv-breakglass"}, star: true, note: "incidents only: tell #ops when used"},
{link: azure + "kv-shared-prod.vault.azure.net/secrets/smtp-password", account: alice, source: "sub-prod",
path: []string{"platform-prod", "kv-shared-prod"}, uses: 2, ago: 26 * time.Hour},
{link: dbx + "app/storage-key", account: "Databricks", source: "dbx-prod",
@@ -43,10 +45,13 @@ func Seed(st *store.Store, alice, admin string) {
n.Name = cmp.Or(it.name, it.link[strings.LastIndex(it.link, "/")+1:])
n.Path, n.Source, n.Account = it.path, it.source, it.account
}
if it.star {
if it.star || it.note != "" {
_ = st.Update(it.link, func(n *store.Node) {
context(n)
n.ToggleStar(it.account)
if it.star {
n.ToggleStar(it.account)
}
n.Note = it.note
})
}
for range it.uses {