/
user_config.go
86 lines (72 loc) · 1.74 KB
/
user_config.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
// Copyright 2015 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package engine
import (
"fmt"
"strings"
"github.com/keybase/client/go/libkb"
)
type UserConfigEngineArg struct {
Key string
Value string
}
type UserConfigEngine struct {
libkb.Contextified
arg *UserConfigEngineArg
}
func NewUserConfigEngine(g *libkb.GlobalContext, arg *UserConfigEngineArg) *UserConfigEngine {
return &UserConfigEngine{
arg: arg,
Contextified: libkb.NewContextified(g),
}
}
func (e *UserConfigEngine) Name() string {
return "UserConfig"
}
func (e *UserConfigEngine) Prereqs() Prereqs {
return Prereqs{Device: true}
}
func (e *UserConfigEngine) RequiredUIs() []libkb.UIKind {
return []libkb.UIKind{}
}
func (e *UserConfigEngine) SubConsumers() []libkb.UIConsumer {
return nil
}
func (e *UserConfigEngine) Run(m libkb.MetaContext) (err error) {
keys := strings.SplitN(e.arg.Key, ".", 2)
if len(keys) < 2 {
return fmt.Errorf("Invalid key")
}
// Supports picture.source = "twitter" or "github".
// This maps to http endpoint image/set_preference.json?identify_src=100 (or 101).
// TODO We should clean this up.
if keys[0] == "picture" {
var key string
var value string
if keys[1] == "source" {
key = "identity_src"
switch e.arg.Value {
case "twitter":
value = "100"
case "github":
value = "101"
default:
return fmt.Errorf("Invalid picture.source")
}
}
var err error
_, err = m.G().API.Post(m, libkb.APIArg{
Endpoint: "image/set_preference",
SessionType: libkb.APISessionTypeREQUIRED,
Args: libkb.HTTPArgs{
key: libkb.S{Val: value},
},
})
if err != nil {
return err
}
} else {
return fmt.Errorf("Invalid key")
}
return nil
}