No behaviour change. - Deleted, unused or one-line wrappers: panes.RuneIndexes, Detail.Refresh (SetDescribed does it), SecretValue.Len, Query.Empty, Clipboard.Native, config.Load, get's value, Model.done, providerOf (cachefile.ProviderOf), contextWithTimeout, searchCoverage, startCrawl, showKeybindings, the expiry aliases and daysLeft. - cmp.Or instead of the two cmpOr copies; slices.Sorted(maps.Keys(…)), maps.Copy, wg.Go, utf8.RuneCountInString and new(true) instead of loops and helpers that do the same. - A container's pane title is set once, not twice; a redundant length check in share links and a no-op assignment in linkhandler.Launch are gone. - Tests call ansi.Strip and lastLines directly; gofmt -s on links.go. Reviewed-on: #76 Co-authored-by: Karl-Einar Bergstrøm <karl-einarb@outlook.com>
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"golang.org/x/term"
|
|
|
|
"git.kebcloud.no/keb/lazysecrets/internal/provider"
|
|
"git.kebcloud.no/keb/lazysecrets/internal/ref"
|
|
"git.kebcloud.no/keb/lazysecrets/internal/store"
|
|
)
|
|
|
|
// get prints the value a link points at, for scripts:
|
|
//
|
|
// export DB_PASSWORD=$(lazysecrets get lazysecrets://azure/kv.vault.azure.net/secrets/db-password)
|
|
//
|
|
// It ends with a newline only when printing to a terminal, so command
|
|
// substitution and pipes get the value exactly.
|
|
func get(ctx context.Context, providers []provider.Provider, st *store.Store, r ref.Ref) error {
|
|
v, _, err := readKey(ctx, providers, st, r)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
out := v.Reveal()
|
|
if term.IsTerminal(int(os.Stdout.Fd())) {
|
|
out += "\n"
|
|
}
|
|
_, err = os.Stdout.WriteString(out)
|
|
return err
|
|
}
|
|
|
|
// readKey reads what r points at (ref.Read), and the version read. The
|
|
// account asked for (--account) goes first, else the one that last read
|
|
// it.
|
|
func readKey(ctx context.Context, providers []provider.Provider, st *store.Store, r ref.Ref) (provider.SecretValue, string, error) {
|
|
key := r
|
|
key.Version = ""
|
|
node := st.Node(key.String())
|
|
account, source := node.Account, node.Source
|
|
if r.Account != "" && r.Account != account {
|
|
account, source = r.Account, ""
|
|
}
|
|
return ref.Read(ctx, providers, r, account, source)
|
|
}
|