-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
cmd_wot_vouch.go
106 lines (98 loc) · 2.75 KB
/
cmd_wot_vouch.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package client
import (
"errors"
"fmt"
"strings"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
"github.com/keybase/go-framed-msgpack-rpc/rpc"
context "golang.org/x/net/context"
)
type CmdWotVouch struct {
Assertion string
Message string
Confidence keybase1.Confidence
libkb.Contextified
}
// Keep in sync with wot.avdl
const verifiedViaChoices = "in_person, proofs, video, audio, other_chat, familiar, other"
func newCmdWotVouch(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
flags := []cli.Flag{
cli.StringFlag{
Name: "m, message",
Usage: "A message about this user",
},
cli.StringFlag{
Name: "verified-via",
Usage: fmt.Sprintf("How you verified their identity: %s", verifiedViaChoices),
},
cli.StringFlag{
Name: "other",
Usage: "Other information about your confidence in knowing this user",
},
}
cmd := &CmdWotVouch{
Contextified: libkb.NewContextified(g),
}
return cli.Command{
Name: "vouch",
Usage: "Make a claim about another user",
Description: "Make a claim about another user",
Action: func(c *cli.Context) {
cl.ChooseCommand(cmd, "vouch", c)
},
Flags: flags,
}
}
func (c *CmdWotVouch) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
return errors.New("vouch requires a user assertion argument")
}
c.Assertion = ctx.Args()[0]
c.Message = ctx.String("message")
if len(c.Message) == 0 {
return errors.New("vouch requires an attestation e.g. `-m \"Alice plays the banjo\"`")
}
via := ctx.String("verified-via")
if via == "" {
return errors.New("verified-via is required")
}
viaType, ok := keybase1.UsernameVerificationTypeMap[strings.ToLower(via)]
if !ok {
return fmt.Errorf("invalid verified-via value '%v'. Expected one of: %v", via, verifiedViaChoices)
}
c.Confidence.UsernameVerifiedVia = viaType
other := ctx.String("other")
if (other != "") != (c.Confidence.UsernameVerifiedVia == keybase1.UsernameVerificationType_OTHER) {
return errors.New("--other must be paired with --verified-via 'other'")
}
if other != "" {
c.Confidence.Other = ctx.String("other")
}
return nil
}
func (c *CmdWotVouch) Run() error {
protocols := []rpc.Protocol{NewIdentifyUIProtocol(c.G())}
if err := RegisterProtocolsWithContext(protocols, c.G()); err != nil {
return err
}
arg := keybase1.WotVouchCLIArg{
Assertion: c.Assertion,
VouchText: c.Message,
Confidence: c.Confidence,
}
cli, err := GetWebOfTrustClient(c.G())
if err != nil {
return err
}
return cli.WotVouchCLI(context.Background(), arg)
}
func (c *CmdWotVouch) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
API: true,
KbKeyring: true,
}
}