-
Notifications
You must be signed in to change notification settings - Fork 64
/
keys_cmd.go
66 lines (58 loc) · 1.63 KB
/
keys_cmd.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
package main
import (
"fmt"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/charm/ui/common"
"github.com/charmbracelet/charm/ui/keys"
"github.com/spf13/cobra"
)
var (
keysCmd = &cobra.Command{
Use: "keys",
Short: "Browse or print linked keys",
Long: formatLong("Charm accounts are powered by " + common.Keyword("SSH keys") + ". This command prints all of the keys linked to your account. To remove keys use the main " + common.Code("charm") + " interface."),
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
if isTTY() && !simpleOutput && !randomart {
// Log to file, if set
cfg := getCharmConfig()
if cfg.Logfile != "" {
f, err := tea.LogToFile(cfg.Logfile, "charm")
if err != nil {
return err
}
defer f.Close()
}
return keys.NewProgram(cfg).Start()
} else {
cc := initCharmClient(animatedKeygen)
// Print randomart with fingerprints
k, err := cc.AuthorizedKeysWithMetadata()
if err != nil {
return err
}
keys := k.Keys
for i := 0; i < len(keys); i++ {
if !randomart {
fmt.Println(keys[i].Key)
continue
}
fp, err := keys[i].FingerprintSHA256()
if err != nil {
fp.Value = fmt.Sprintf("Could not generate fingerprint for key %s: %v\n\n", keys[i].Key, err)
}
board, err := keys[i].RandomArt()
if err != nil {
board = fmt.Sprintf("Could not generate randomart for key %s: %v\n\n", keys[i].Key, err)
}
cr := "\n\n"
if i == len(keys)-1 {
cr = "\n"
}
fmt.Printf("%s\n%s%s", fp, board, cr)
}
return nil
}
},
}
)