forked from keybase/client
/
cmd_id.go
130 lines (114 loc) · 3.24 KB
/
cmd_id.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"fmt"
"golang.org/x/net/context"
"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"
)
type CmdID struct {
libkb.Contextified
user string
useDelegateUI bool
skipProofCache bool
forceDisplay bool
}
func (v *CmdID) ParseArgv(ctx *cli.Context) error {
nargs := len(ctx.Args())
if nargs > 1 {
return fmt.Errorf("Identify only takes one argument, the user to lookup.")
}
if nargs == 1 {
v.user = ctx.Args()[0]
}
v.useDelegateUI = ctx.Bool("ui")
v.skipProofCache = ctx.Bool("skip-proof-cache")
v.forceDisplay = ctx.Bool("force-display")
return nil
}
func (v *CmdID) makeArg() keybase1.Identify2Arg {
return keybase1.Identify2Arg{
UserAssertion: v.user,
UseDelegateUI: v.useDelegateUI || v.forceDisplay,
ForceDisplay: v.forceDisplay,
Reason: keybase1.IdentifyReason{Reason: "CLI id command"},
ForceRemoteCheck: v.skipProofCache,
AlwaysBlock: true,
NeedProofSet: true,
AllowEmptySelfID: true,
NoSkipSelf: true,
}
}
func (v *CmdID) Run() error {
var cli keybase1.IdentifyClient
protocols := []rpc.Protocol{}
// always register this, even if ui is delegated, so that
// fallback to terminal UI works.
protocols = append(protocols, NewIdentifyUIProtocol(v.G()))
cli, err := GetIdentifyClient(v.G())
if err != nil {
return err
}
if err := RegisterProtocolsWithContext(protocols, v.G()); err != nil {
return err
}
arg := v.makeArg()
_, err = cli.Identify2(context.TODO(), arg)
if _, ok := err.(libkb.SelfNotFoundError); ok {
msg := `Could not find UID or username for you on this device.
You can either specify a user to id: keybase id <username>
Or log in once on this device and run "keybase id" again.
`
v.G().UI.GetDumbOutputUI().Printf(msg)
return nil
}
return err
}
func NewCmdID(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
ret := cli.Command{
Name: "id",
ArgumentHelp: "[username]",
Usage: "Identify a user and check their signature chain",
Description: "Identify a user and check their signature chain. Don't specify a username to identify yourself. You can also specify proof assertions like user@twitter.",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "ui",
Usage: "Use identify UI.",
HideUsage: !develUsage,
},
cli.BoolFlag{
Name: "force-display",
Usage: "Force identify UI to draw (even if still fresh)",
HideUsage: !develUsage,
},
cli.BoolFlag{
Name: "s, skip-proof-cache",
Usage: "Skip cached proofs, force re-check",
},
},
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdIDRunner(g), "id", c)
},
}
return ret
}
func NewCmdIDRunner(g *libkb.GlobalContext) *CmdID {
return &CmdID{Contextified: libkb.NewContextified(g)}
}
func (v *CmdID) SetUser(s string) {
v.user = s
}
func (v *CmdID) UseDelegateUI() {
v.useDelegateUI = true
}
func (v *CmdID) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
KbKeyring: true,
API: true,
}
}