feat: lazysecrets list prints everything lazysecrets can find, for fzf and editor pickers (#70)
`lazysecrets list` prints every source, vault and secret lazysecrets can find, one per line, for fzf, editor pickers and scripts: what Go to searches, without the TUI. What's cached prints at once; what's missing or older than `--max-age` loads in the background and streams in. It stops when the reader goes (a pick in fzf), saving what it loaded. - Text: kind, mark (✗/⚠, ★, ◷ and the provider icon), name, status (why it couldn't be read, or expired / expires in 12d), note, account and link, tab-separated; kind first and account and link last, so new fields go between. Coloured from the theme; `--color never`, `--icons=false`, `--stars=false`, `--recent`, `--notes=false`, `--expiry=false`. - `--format json`: an object per line, with starred, recent, lastUsed and uses, expires, enabled, note, reference and url too. - `--kind` lists only some kinds, and doesn't load lists only other kinds need; `--cached` loads nothing. - `lazysecrets open --action go|copy|show` skips the "what to do" menu and ends in the list, like Go to; `open` and `get` take `--account`, the account list printed, rather than asking which. - The cache file moved to `internal/cachefile`: saves merge with the file under a lock, so list and the TUI don't undo each other. - `ui.recentIcon` marks items used lately with ◷ in the TUI's lists too; Recent now means the last 90 days. - --demo has stars, notes, recent use, and expired, expiring and disabled secrets. - docs/integration.md documents get, list and an fzf picker; docs/links.md is docs/sharing.md. Reviewed-on: #70 Co-authored-by: Karl-Einar Bergstrøm <karl-einarb@outlook.com>
This commit was merged in pull request #70.
This commit is contained in:
1 parent
dbb0eb2bbd
commit
39454d47a8
45 files changed
+2107
-222
No files matched your search
@@ -0,0 +1,65 @@
|
||||
package fake
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.kebcloud.no/keb/lazysecrets/internal/store"
|
||||
)
|
||||
|
||||
// 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
|
||||
ago time.Duration
|
||||
}
|
||||
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,
|
||||
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, 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: azure + "kv-app-prod.vault.azure.net/secrets/smtp-password", account: alice, source: "sub-prod",
|
||||
path: []string{"platform-prod", "kv-app-prod"}, note: "migrated to Microsoft Graph sendMail; delete after Q4"},
|
||||
{link: dbx + "app/storage-key", account: "Databricks", source: "dbx-prod",
|
||||
path: []string{"prod", "app"}, star: true, uses: 3, ago: 5 * time.Hour},
|
||||
// A subscription, for both accounts, and a repo's file.
|
||||
{link: azure + "subscriptions/sub-prod", account: alice, source: "sub-prod",
|
||||
name: "platform-prod", star: true},
|
||||
{link: azure + "subscriptions/sub-prod", account: admin, source: "sub-prod",
|
||||
name: "platform-prod", star: true},
|
||||
{link: "lazysecrets://repo/github.com%2Facme%2Flazysecrets-demo/deploy%2Fprod%2Fsecrets.yaml", account: "Repos",
|
||||
source: "/home/dev/git/lazysecrets-demo", name: "deploy/prod/secrets.yaml",
|
||||
path: []string{"lazysecrets-demo"}, star: true},
|
||||
} {
|
||||
context := func(n *store.Node) {
|
||||
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 || it.note != "" {
|
||||
_ = st.Update(it.link, func(n *store.Node) {
|
||||
context(n)
|
||||
if it.star {
|
||||
n.ToggleStar(it.account)
|
||||
}
|
||||
n.Note = it.note
|
||||
})
|
||||
}
|
||||
for range it.uses {
|
||||
_ = st.Use(it.link, time.Now().Add(-it.ago), context)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user