cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

Run jev-api-key-command only when a sheet first asks JEV

Dami committed 710b5e6
A password manager's CLI can prompt; with a lazy client it runs once,
on the first question, instead of on every start.
commit
710b5e6b52f1f4666a35faf4cc4f4c1e9bf68fcc
parent
c97c9c9d05a0cca615b5584df6c4782c52144b1e
author
Dami <dami.etoile@gmail.com>
4 files changed, +65 -2
Mcmd/012/main.go17+++++++++++++++--
Mcmd/012/main_test.go7+++++++
Minternal/jev/apikey.go26++++++++++++++++++++++++++
Minternal/jev/apikey_test.go17+++++++++++++++++
M cmd/012/main.go +15 -2
@@ -130,14 +130,27 @@ func jevConfig(c *config.Config, key string) jev.Config {
130130 // startJEV finds the API key and connects, returning notes for the131131 // context line: why the key couldn't be read, or that a .env file's key132132 // is no longer read.133+//134+// jev-api-key-command runs only when the environment and the credential135+// store have no key, and then only when a sheet first asks JEV136+// something, so a password manager doesn't prompt on every start.133137 func startJEV(c *config.Config, e env, store keyring.Store) (jev.Client, []string) {134- ctx, cancel := context.WithTimeout(context.Background(), 2*jev.KeyCommandTimeout)138+ ctx, cancel := context.WithTimeout(context.Background(), jev.KeyCommandTimeout)135139 defer cancel()136- key, _, err := jev.ResolveKey(ctx, jev.KeySources{Getenv: e.getenv, Store: store, Command: c.String("jev-api-key-command")})140+ key, _, err := jev.ResolveKey(ctx, jev.KeySources{Getenv: e.getenv, Store: store})137141 var notes []string138142 if err != nil {139143 notes = append(notes, "JEV API key: "+err.Error())140144 }145+ if command := c.String("jev-api-key-command"); key == "" && command != "" {146+ return jev.Lazy(func() (jev.Client, error) {147+ key, _, err := jev.ResolveKey(context.Background(), jev.KeySources{Command: command})148+ if err != nil {149+ return nil, err150+ }151+ return jev.NewClient(jevConfig(c, key))152+ }), notes153+ }141154 if key == "" {142155 if jev.DotEnvHasKey(".") {143156 notes = append(notes, "012 no longer reads TYPESAFE_API_KEY from .env files: run 012 config set-key to store it")
M cmd/012/main_test.go +7 -0
M internal/jev/apikey.go +26 -0
M internal/jev/apikey_test.go +17 -0