forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
track.go
95 lines (79 loc) · 2.11 KB
/
track.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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package engine
import (
"errors"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol"
)
type TrackEngineArg struct {
UserAssertion string
Me *libkb.User
Options keybase1.TrackOptions
ForceRemoteCheck bool
}
type TrackEngine struct {
arg *TrackEngineArg
them *libkb.User
libkb.Contextified
}
// NewTrackEngine creates a default TrackEngine for tracking theirName.
func NewTrackEngine(arg *TrackEngineArg, g *libkb.GlobalContext) *TrackEngine {
return &TrackEngine{
arg: arg,
Contextified: libkb.NewContextified(g),
}
}
func (e *TrackEngine) Name() string {
return "Track"
}
func (e *TrackEngine) Prereqs() Prereqs {
return Prereqs{
Device: true,
}
}
func (e *TrackEngine) RequiredUIs() []libkb.UIKind {
return []libkb.UIKind{
libkb.SecretUIKind,
libkb.IdentifyUIKind,
}
}
func (e *TrackEngine) SubConsumers() []libkb.UIConsumer {
return []libkb.UIConsumer{
&Identify{},
}
}
func (e *TrackEngine) Run(ctx *Context) error {
iarg := NewIdentifyTrackArg(e.arg.UserAssertion, true, e.arg.ForceRemoteCheck, e.arg.Options)
ieng := NewIdentify(iarg, e.G())
if err := RunEngine(ieng, ctx); err != nil {
e.G().Log.Info("identify run err: %s", err)
return err
}
token := ieng.TrackToken()
e.them = ieng.User()
// prompt if the identify is correct
outcome := ieng.Outcome().Export()
result, err := ctx.IdentifyUI.Confirm(outcome)
if err != nil {
return err
}
if !result.IdentityConfirmed {
return errors.New("Track not confirmed")
}
// if they didn't specify local only on the command line, then if they answer no to posting
// the tracking statement publicly to keybase, change LocalOnly to true here:
if !e.arg.Options.LocalOnly && !result.RemoteConfirmed {
e.arg.Options.LocalOnly = true
}
targ := &TrackTokenArg{
Token: token,
Me: e.arg.Me,
Options: e.arg.Options,
}
teng := NewTrackToken(targ, e.G())
return RunEngine(teng, ctx)
}
func (e *TrackEngine) User() *libkb.User {
return e.them
}