/
cmd_selfprovision.go
88 lines (72 loc) · 1.86 KB
/
cmd_selfprovision.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
package client
import (
"errors"
"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"
)
func NewCmdSelfProvision(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
cmd := cli.Command{
Name: "selfprovision",
ArgumentHelp: "[newdevicename]",
Usage: "Provision a new device if the current device is a clone.",
Action: func(c *cli.Context) {
cl.ChooseCommand(NewCmdSelfProvisionRunner(g), "selfprovision", c)
},
}
return cmd
}
type CmdSelfProvision struct {
libkb.Contextified
deviceName string
SessionID int
}
func NewCmdSelfProvisionRunner(g *libkb.GlobalContext) *CmdSelfProvision {
return &CmdSelfProvision{
Contextified: libkb.NewContextified(g),
}
}
func (c *CmdSelfProvision) Run() (err error) {
client, err := GetSelfProvisionClient(c.G())
if err != nil {
return err
}
protocols := []rpc.Protocol{
NewLoginUIProtocol(c.G()),
NewSecretUIProtocol(c.G()),
}
if err = RegisterProtocolsWithContext(protocols, c.G()); err != nil {
return err
}
if err := client.SelfProvision(context.TODO(),
keybase1.SelfProvisionArg{
DeviceName: c.deviceName,
SessionID: c.SessionID,
}); err != nil {
return err
}
dui := c.G().UI.GetDumbOutputUI()
dui.Printf("Self-provisioning successful.\n")
return nil
}
func (c *CmdSelfProvision) ParseArgv(ctx *cli.Context) error {
nargs := len(ctx.Args())
if nargs != 1 {
return errors.New("devicename argument is required")
}
c.deviceName = ctx.Args()[0]
if c.deviceName == "" {
return errors.New("Devicename argument is required")
}
return nil
}
func (c *CmdSelfProvision) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
KbKeyring: true,
API: true,
}
}