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() {