forked from keybase/client
/
cmd_pgp_list.go
96 lines (81 loc) · 2.13 KB
/
cmd_pgp_list.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
// 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"
)
func NewCmdPGPList(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "list",
Usage: "List the active PGP keys in your account.",
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdPGPList{Contextified: libkb.NewContextified(g)}, "list", c)
},
}
}
type CmdPGPList struct {
libkb.Contextified
}
func (s *CmdPGPList) ParseArgv(ctx *cli.Context) error {
if len(ctx.Args()) > 0 {
return UnexpectedArgsError("pgp list")
}
return nil
}
func (s *CmdPGPList) Run() error {
configCli, err := GetConfigClient(s.G())
if err != nil {
return err
}
currentStatus, err := configCli.GetCurrentStatus(context.TODO(), 0)
if err != nil {
return err
}
if !currentStatus.LoggedIn {
return libkb.LoginRequiredError{}
}
userCli, err := GetUserClient(s.G())
if err != nil {
return err
}
publicKeys, err := userCli.LoadPublicKeys(context.TODO(), keybase1.LoadPublicKeysArg{Uid: currentStatus.User.Uid})
if err != nil {
return err
}
dui := s.G().UI.GetDumbOutputUI()
for _, key := range publicKeys {
if len(key.PGPFingerprint) == 0 {
continue
}
dui.Printf("Keybase Key ID: %s\n", key.KID)
dui.Printf("PGP Fingerprint: %s\n", libkb.PGPFingerprintFromHexNoError(key.PGPFingerprint).ToQuads())
if len(key.PGPIdentities) > 0 {
dui.Printf("PGP Identities:\n")
for _, id := range key.PGPIdentities {
var comment string
if len(id.Comment) > 0 {
comment = fmt.Sprintf(" (%s)", id.Comment)
}
var email string
if len(id.Email) > 0 {
email = fmt.Sprintf(" <%s>", id.Email)
}
dui.Printf(" %s%s%s\n", id.Username, comment, email)
}
}
dui.Printf("\n")
}
return nil
}
func (s *CmdPGPList) GetUsage() libkb.Usage {
return libkb.Usage{
Config: true,
KbKeyring: true,
API: true,
}
}