forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read.go
36 lines (29 loc) · 761 Bytes
/
read.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
package sub
import (
"context"
"strings"
"github.com/justwatchcom/gopass/store"
"github.com/justwatchcom/gopass/store/secret"
"github.com/justwatchcom/gopass/utils/fsutil"
"github.com/justwatchcom/gopass/utils/out"
)
// Get returns the plaintext of a single key
func (s *Store) Get(ctx context.Context, name string) (*secret.Secret, error) {
p := s.passfile(name)
if !strings.HasPrefix(p, s.path) {
return nil, store.ErrSneaky
}
if !fsutil.IsFile(p) {
out.Debug(ctx, "File %s not found", p)
return nil, store.ErrNotFound
}
content, err := s.gpg.Decrypt(ctx, p)
if err != nil {
return nil, store.ErrDecrypt
}
sec, err := secret.Parse(content)
if err != nil {
out.Debug(ctx, "Failed to parse YAML: %s", err)
}
return sec, nil
}