forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
track.go
66 lines (59 loc) · 1.94 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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package service
import (
"github.com/keybase/client/go/engine"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol"
rpc "github.com/keybase/go-framed-msgpack-rpc"
"golang.org/x/net/context"
)
// TrackHandler is the RPC handler for the track interface.
type TrackHandler struct {
*BaseHandler
libkb.Contextified
}
// NewTrackHandler creates a TrackHandler for the xp transport.
func NewTrackHandler(xp rpc.Transporter, g *libkb.GlobalContext) *TrackHandler {
return &TrackHandler{
BaseHandler: NewBaseHandler(xp),
Contextified: libkb.NewContextified(g),
}
}
// Track creates a TrackEngine and runs it.
func (h *TrackHandler) Track(_ context.Context, arg keybase1.TrackArg) error {
earg := engine.TrackEngineArg{
UserAssertion: arg.UserAssertion,
Options: arg.Options,
ForceRemoteCheck: arg.ForceRemoteCheck,
}
ctx := engine.Context{
IdentifyUI: h.NewRemoteIdentifyUI(arg.SessionID, h.G()),
SecretUI: h.getSecretUI(arg.SessionID),
}
eng := engine.NewTrackEngine(&earg, h.G())
return engine.RunEngine(eng, &ctx)
}
func (h *TrackHandler) TrackWithToken(_ context.Context, arg keybase1.TrackWithTokenArg) error {
earg := engine.TrackTokenArg{
Token: libkb.ImportIdentifyCacheToken(arg.TrackToken),
Options: arg.Options,
}
ctx := engine.Context{
IdentifyUI: h.NewRemoteIdentifyUI(arg.SessionID, h.G()),
SecretUI: h.getSecretUI(arg.SessionID),
}
eng := engine.NewTrackToken(&earg, h.G())
return engine.RunEngine(eng, &ctx)
}
// Untrack creates an UntrackEngine and runs it.
func (h *TrackHandler) Untrack(_ context.Context, arg keybase1.UntrackArg) error {
earg := engine.UntrackEngineArg{
Username: arg.Username,
}
ctx := engine.Context{
SecretUI: h.getSecretUI(arg.SessionID),
}
eng := engine.NewUntrackEngine(&earg, h.G())
return engine.RunEngine(eng, &ctx)
}