forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.go
61 lines (51 loc) · 1.36 KB
/
action.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package action
import (
"context"
"os"
"path/filepath"
"github.com/blang/semver"
"github.com/justwatchcom/gopass/backend/gpg"
gpgcli "github.com/justwatchcom/gopass/backend/gpg/cli"
"github.com/justwatchcom/gopass/config"
"github.com/justwatchcom/gopass/store/root"
)
type gpger interface {
FindPublicKeys(context.Context, ...string) (gpg.KeyList, error)
FindPrivateKeys(context.Context, ...string) (gpg.KeyList, error)
ListPublicKeys(context.Context) (gpg.KeyList, error)
ListPrivateKeys(context.Context) (gpg.KeyList, error)
CreatePrivateKeyBatch(context.Context, string, string, string) error
CreatePrivateKey(context.Context) error
ExportPublicKey(context.Context, string, string) error
}
// Action knows everything to run gopass CLI actions
type Action struct {
Name string
Store *root.Store
cfg *config.Config
gpg gpger
version semver.Version
}
// New returns a new Action wrapper
func New(ctx context.Context, cfg *config.Config, sv semver.Version) *Action {
name := "gopass"
if len(os.Args) > 0 {
name = filepath.Base(os.Args[0])
}
act := &Action{
Name: name,
cfg: cfg,
version: sv,
}
store, err := root.New(ctx, cfg)
if err != nil {
panic(err)
}
act.Store = store
act.gpg = gpgcli.New(gpgcli.Config{})
return act
}
// String implement fmt.Stringer
func (s *Action) String() string {
return s.Store.String()
}