Skip to content

Commit b732a66

Browse files
committed
Fix addkey error messages and improve usability
1 parent a391e0c commit b732a66

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

cmd/envelope/add_key.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"net/url"
66

7-
errors "github.com/hashicorp/errwrap"
7+
"github.com/ansel1/merry"
88
"github.com/mikesimons/envelope"
99
"gopkg.in/urfave/cli.v1"
1010
)
@@ -13,8 +13,10 @@ import (
1313
// e.g $ envelope add-key test kms://arn
1414
func addKeyCommand() cli.Command {
1515
return cli.Command{
16-
Name: "add-key",
17-
Usage: "Add a key to the keyring",
16+
Name: "addkey",
17+
Usage: "Add a key to the keyring.",
18+
Description: `Master key DSN is of the form <provider>://<dsn>. The only supported provider is currently awskms.
19+
Example: envelope add-key mytestkey awskms://arn:aws:kms:us-east-1:111111111111:key/abcdef01-2345-6789-abcd-ef0123456789`,
1820
ArgsUsage: "<alias> <master key dsn>",
1921
Flags: []cli.Flag{
2022
cli.StringFlag{
@@ -24,7 +26,7 @@ func addKeyCommand() cli.Command {
2426
},
2527
Action: func(c *cli.Context) error {
2628
if c.NArg() != 2 {
27-
cli.ShowCommandHelp(c, "add-key")
29+
cli.ShowCommandHelp(c, "addkey")
2830
fmt.Println("")
2931
return cli.NewExitError("Error: Not enough arguments", 1)
3032
}
@@ -61,7 +63,7 @@ func parseEncryptionContext(input string) (map[string]string, error) {
6163

6264
values, err := url.ParseQuery(input)
6365
if err != nil {
64-
return nil, errors.Wrapf("Unable to parse encryption context", err)
66+
return nil, merry.Wrap(err).WithMessage("Unable to parse encryption context")
6567
}
6668

6769
output := make(map[string]string)

cmd/envelope/shared.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
"github.com/ansel1/merry"
11+
cli "gopkg.in/urfave/cli.v1"
1112
)
1213

1314
func asFormat(as string, input string) string {
@@ -66,7 +67,7 @@ func processErrors(err error) error {
6667
}
6768
lines = append(lines, strings.Join(extra, ", "))
6869

69-
return fmt.Errorf(strings.Join(lines, "\n"))
70+
return cli.NewExitError(strings.Join(lines, "\n"), 1)
7071
}
7172

7273
func getInputReader(input string) (io.Reader, error) {

keysvc/keysvc.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package keysvc
33
import (
44
"fmt"
55
"net/url"
6+
"strings"
67

78
"github.com/ansel1/merry"
89
"github.com/mikesimons/envelope/keysvc/awskms"
@@ -26,7 +27,11 @@ func GetKeyService(name string) (KeyServiceProvider, error) {
2627
return fn()
2728
}
2829

29-
return nil, fmt.Errorf("Unknown key service: %s", name)
30+
var known []string
31+
for k := range services {
32+
known = append(known, k)
33+
}
34+
return nil, merry.Errorf("Unknown key service. Must be one of: %s", strings.Join(known, ", ")).WithValue("svc", name)
3035
}
3136

3237
func GenerateDatakey(alias string, masterKey string, context map[string]string) (*Key, error) {

0 commit comments

Comments
 (0)