Skip to content

Commit

Permalink
Refactor action package (gopasspw#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikschulz authored Mar 27, 2018
1 parent 501f88e commit 09299f8
Show file tree
Hide file tree
Showing 33 changed files with 738 additions and 436 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The slightly more awesome Standard Unix Password Manager for Teams. Written in G

## Demo

[![asciicast](https://asciinema.org/a/101688.png)](https://asciinema.org/a/101688)
[![asciicast](https://asciinema.org/a/172749.png)](https://asciinema.org/a/172749)

## Features

Expand Down
44 changes: 11 additions & 33 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"

ap "github.com/justwatchcom/gopass/pkg/action"
"github.com/justwatchcom/gopass/pkg/action/binary"
"github.com/justwatchcom/gopass/pkg/action/create"
"github.com/justwatchcom/gopass/pkg/action/xc"
"github.com/justwatchcom/gopass/pkg/agent"
"github.com/justwatchcom/gopass/pkg/agent/client"
Expand Down Expand Up @@ -73,10 +75,10 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com
Description: "" +
"This command will decrypt all secrets and check the passwords against the public " +
"havibeenpwned.com v2 API or Dumps. " +
"To use the dumps you need to download the dumps from https://haveibeenpwned.com/passwords first. This is a very expensive operation for advanced users." +
"Most users should probably use the API." +
"If you want to use the dumps you need to use 7z to extract the dump: 7z x pwned-passwords-2.0.txt.7z." +
"To speed up processing you should sort them and use the --sorted flag: cat pwned-passwords-2.0.txt | LANG=C sort -S 10G --parallel=4 | gzip --fast > pwned-passwords-2.0.txt.gz",
"To use the dumps you need to download the dumps from https://haveibeenpwned.com/passwords first. Be sure to grap the one that says '(ordered by hash)'. " +
"This is a very expensive operation for advanced users. " +
"Most users should probably use the API. " +
"If you want to use the dumps you need to use 7z to extract the dump: 7z x pwned-passwords-ordered-2.0.txt.7z.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.HIBP(withGlobalFlags(ctx, c), c)
Expand Down Expand Up @@ -115,7 +117,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com
"to a secret.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.BinaryCat(withGlobalFlags(ctx, c), c)
return binary.Cat(withGlobalFlags(ctx, c), c, action.Store)
},
BashComplete: func(c *cli.Context) { action.Complete(ctx, c) },
},
Expand All @@ -129,7 +131,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com
Aliases: []string{"sha", "sha256"},
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.BinarySum(withGlobalFlags(ctx, c), c)
return binary.Sum(withGlobalFlags(ctx, c), c, action.Store)
},
BashComplete: func(c *cli.Context) { action.Complete(ctx, c) },
},
Expand All @@ -145,7 +147,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Aliases: []string{"cp"},
Action: func(c *cli.Context) error {
return action.BinaryCopy(withGlobalFlags(ctx, c), c)
return binary.Copy(withGlobalFlags(ctx, c), c, action.Store)
},
BashComplete: func(c *cli.Context) { action.Complete(ctx, c) },
Flags: []cli.Flag{
Expand All @@ -169,7 +171,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Aliases: []string{"mv"},
Action: func(c *cli.Context) error {
return action.BinaryMove(withGlobalFlags(ctx, c), c)
return binary.Move(withGlobalFlags(ctx, c), c, action.Store)
},
BashComplete: func(c *cli.Context) { action.Complete(ctx, c) },
Flags: []cli.Flag{
Expand Down Expand Up @@ -283,7 +285,7 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com
"This command starts a wizard to aid in creation of new secrets.",
Before: func(c *cli.Context) error { return action.Initialized(withGlobalFlags(ctx, c), c) },
Action: func(c *cli.Context) error {
return action.Create(withGlobalFlags(ctx, c), c)
return create.Create(withGlobalFlags(ctx, c), c, action.Store)
},
},
{
Expand Down Expand Up @@ -539,14 +541,6 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com
Name: "store",
Usage: "Store to operate on",
},
cli.StringFlag{
Name: "remote",
Usage: "Git remote to add",
},
cli.StringFlag{
Name: "url",
Usage: "Git URL",
},
},
},
},
Expand All @@ -564,14 +558,6 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com
Name: "store",
Usage: "Store to operate on",
},
cli.StringFlag{
Name: "origin",
Usage: "Git Origin to push to",
},
cli.StringFlag{
Name: "branch",
Usage: "Git branch to push",
},
},
},
{
Expand All @@ -587,14 +573,6 @@ func getCommands(ctx context.Context, action *ap.Action, app *cli.App) []cli.Com
Name: "store",
Usage: "Store to operate on",
},
cli.StringFlag{
Name: "origin",
Usage: "Git Origin to push to",
},
cli.StringFlag{
Name: "branch",
Usage: "Git branch to push",
},
},
},
},
Expand Down
5 changes: 5 additions & 0 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/urfave/cli"
)

// commandsWithError is a list of commands that return an error when
// invoked without arguments
var commandsWithError = map[string]struct{}{
".audit": {},
".audit.hibp": {},
Expand All @@ -35,6 +37,9 @@ var commandsWithError = map[string]struct{}{
".find": {},
".generate": {},
".grep": {},
".git.remote.add": {},
".git.push": {},
".git.pull": {},
".history": {},
".init": {},
".insert": {},
Expand Down
4 changes: 3 additions & 1 deletion pkg/action/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import (
func (s *Action) Audit(ctx context.Context, c *cli.Context) error {
filter := c.Args().First()

out.Print(ctx, "Auditing passwords for common flaws ...")

t, err := s.Store.Tree(ctx)
if err != nil {
return ExitError(ctx, ExitList, err, "failed to get store tree: %s", err)
}
if filter != "" {
subtree, err := t.FindFolder(filter)
if err != nil {
return err
return ExitError(ctx, ExitUnknown, err, "failed to find subtree: %s", err)
}
t = subtree
}
Expand Down
238 changes: 0 additions & 238 deletions pkg/action/binary.go

This file was deleted.

Loading

0 comments on commit 09299f8

Please sign in to comment.