lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 982acbc0a68f99ffc4bc02e3b1d2c38c1f86f29b
parent 6132373a8f326a12041d28718959d9ea9d9de920
Author: Sean Enck <sean@ttypty.com>
Date:   Wed, 13 Jul 2022 21:01:34 -0400

hook should pass some info about when it is executing

Diffstat:
Mcmd/lb/main.go | 12++++++++----
Mtests/expected.log | 14+++++++-------
Mtests/run.sh | 2+-
3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/cmd/lb/main.go b/cmd/lb/main.go @@ -13,6 +13,10 @@ import ( "github.com/enckse/lockbox/internal" ) +const ( + postStep = "post" +) + var ( version = "development" libExec = "" @@ -33,7 +37,7 @@ func getEntry(store string, args []string, idx int) string { return filepath.Join(store, args[idx]) + internal.Extension } -func hooks() { +func hooks(store, action, step string) { hookDir := os.Getenv("LOCKBOX_HOOKDIR") if !internal.PathExists(hookDir) { return @@ -45,7 +49,7 @@ func hooks() { for _, d := range dirs { if !d.IsDir() { name := d.Name() - cmd := exec.Command(filepath.Join(hookDir, name)) + cmd := exec.Command(filepath.Join(hookDir, name), action, step) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { @@ -145,7 +149,7 @@ func main() { internal.Die("failed to save password", err) } fmt.Println("") - hooks() + hooks(store, command, postStep) case "rm": entry := getEntry(store, args, 2) if !internal.PathExists(entry) { @@ -153,7 +157,7 @@ func main() { } if confirm("remove entry") { os.Remove(entry) - hooks() + hooks(store, command, postStep) } case "show", "-c", "clip", "dump": isDump := command == "dump" diff --git a/tests/expected.log b/tests/expected.log @@ -1,9 +1,9 @@ [ ] -HOOK RAN +HOOK RAN insert post -HOOK RAN +HOOK RAN insert post keys/one: test keys/one2: @@ -20,14 +20,14 @@ test2 } ] -HOOK RAN +HOOK RAN insert post keys/one keys/one2 keys2/three rekeying: /keys/one.lb rekeying: /keys/one2.lb rekeying: /keys2/three.lb -remove entry? (y/N) HOOK RAN +remove entry? (y/N) HOOK RAN rm post keys/one2 keys2/three @@ -42,13 +42,13 @@ dump data to stdout as plaintext? (y/N) [ } ] -HOOK RAN +HOOK RAN insert post test XXXXXX test2 -remove entry? (y/N) HOOK RAN +remove entry? (y/N) HOOK RAN rm post -remove entry? (y/N) HOOK RAN +remove entry? (y/N) HOOK RAN rm post unable to decrypt (decrypt not ok) rekeying: /keys/one2.lb diff --git a/tests/run.sh b/tests/run.sh @@ -27,7 +27,7 @@ mkdir -p $LOCKBOX_HOOKDIR _hook() { echo "#!/bin/sh" - echo "echo HOOK RAN" + echo "echo HOOK RAN \$@" } _run() {