forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.go
47 lines (39 loc) · 1.18 KB
/
history.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package action
import (
"time"
"github.com/gopasspw/gopass/internal/action/exit"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/gopasspw/gopass/pkg/debug"
"github.com/urfave/cli/v2"
)
// History displays the history of a given secret.
func (s *Action) History(c *cli.Context) error {
ctx := ctxutil.WithGlobalFlags(c)
name := c.Args().Get(0)
showPassword := c.Bool("password")
if name == "" {
return exit.Error(exit.Usage, nil, "Usage: %s history <NAME>", s.Name)
}
if !s.Store.Exists(ctx, name) {
return exit.Error(exit.NotFound, nil, "Secret not found")
}
revs, err := s.Store.ListRevisions(ctx, name)
if err != nil {
return exit.Error(exit.Unknown, err, "Failed to get revisions: %s", err)
}
for _, rev := range revs {
pw := ""
if showPassword {
_, sec, err := s.Store.GetRevision(ctx, name, rev.Hash)
if err != nil {
debug.Log("Failed to get revision %q of %q: %s", rev.Hash, name, err)
}
if err == nil {
pw = " - " + sec.Password()
}
}
out.Printf(ctx, "%s - %s <%s> - %s - %s%s\n", rev.Hash, rev.AuthorName, rev.AuthorEmail, rev.Date.Format(time.RFC3339), rev.Subject, pw)
}
return nil
}