Skip to content

Commit

Permalink
gopass recipients add/remove selection wizard (#359)
Browse files Browse the repository at this point in the history
Fixes #351
  • Loading branch information
dominikschulz authored Oct 5, 2017
1 parent 775bb9b commit 2c065a4
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions action/recipients.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/fatih/color"
"github.com/justwatchcom/gopass/utils/ctxutil"
"github.com/justwatchcom/gopass/utils/termwiz"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -66,7 +67,25 @@ func (s *Action) RecipientsComplete(ctx context.Context, c *cli.Context) {
func (s *Action) RecipientsAdd(ctx context.Context, c *cli.Context) error {
store := c.String("store")
added := 0
for _, r := range c.Args() {

recipients := []string(c.Args())
if len(recipients) < 1 {
choices := []string{}
kl, _ := s.gpg.FindPublicKeys(ctx)
for _, key := range kl.UseableKeys() {
choices = append(choices, key.OneLine())
}
if len(choices) > 0 {
act, sel := termwiz.GetSelection(choices)
switch act {
case "show":
recipients = []string{choices[sel]}
default:
return s.exitError(ctx, ExitAborted, nil, "user aborted")
}
}
}
for _, r := range recipients {
keys, err := s.gpg.FindPublicKeys(ctx, r)
if err != nil {
fmt.Println(color.CyanString("Failed to list public key '%s': %s", r, err))
Expand Down Expand Up @@ -100,8 +119,34 @@ func (s *Action) RecipientsAdd(ctx context.Context, c *cli.Context) error {
// RecipientsRemove removes recipients
func (s *Action) RecipientsRemove(ctx context.Context, c *cli.Context) error {
store := c.String("store")

recipients := []string(c.Args())
if len(recipients) < 1 {
ids := s.Store.ListRecipients(ctx, store)
choices := make([]string, 0, len(ids))
kl, err := s.gpg.FindPublicKeys(ctx, ids...)
if err == nil && kl != nil {
for _, id := range ids {
if key, err := kl.FindKey(id); err == nil {
choices = append(choices, key.OneLine())
continue
}
choices = append(choices, id)
}
}
if len(choices) > 0 {
act, sel := termwiz.GetSelection(choices)
switch act {
case "show":
recipients = []string{choices[sel]}
default:
return s.exitError(ctx, ExitAborted, nil, "user aborted")
}
}
}

removed := 0
for _, r := range c.Args() {
for _, r := range recipients {
kl, err := s.gpg.FindPrivateKeys(ctx, r)
if err == nil {
if len(kl) > 0 {
Expand Down

0 comments on commit 2c065a4

Please sign in to comment.