-
Notifications
You must be signed in to change notification settings - Fork 20
/
ssh_key_show.go
67 lines (51 loc) · 1.7 KB
/
ssh_key_show.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
package cmd
import (
"fmt"
"strings"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
type computeSSHKeyShowOutput struct {
Name string `json:"name"`
Fingerprint string `json:"fingerprint"`
}
func (o *computeSSHKeyShowOutput) Type() string { return "SSH key" }
func (o *computeSSHKeyShowOutput) toJSON() { outputJSON(o) }
func (o *computeSSHKeyShowOutput) toText() { outputText(o) }
func (o *computeSSHKeyShowOutput) toTable() { outputTable(o) }
type computeSSHKeyShowCmd struct {
cliCommandSettings `cli-cmd:"-"`
_ bool `cli-cmd:"show"`
Key string `cli-arg:"#"`
}
func (c *computeSSHKeyShowCmd) cmdAliases() []string { return gShowAlias }
func (c *computeSSHKeyShowCmd) cmdShort() string {
return "Show an SSH key details"
}
func (c *computeSSHKeyShowCmd) cmdLong() string {
return fmt.Sprintf(`This command shows an SSH key details.
Supported output template annotations: %s`,
strings.Join(outputterTemplateAnnotations(&computeSSHKeyShowOutput{}), ", "))
}
func (c *computeSSHKeyShowCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *computeSSHKeyShowCmd) cmdRun(_ *cobra.Command, _ []string) error {
ctx := exoapi.WithEndpoint(
gContext,
exoapi.NewReqEndpoint(gCurrentAccount.Environment, gCurrentAccount.DefaultZone),
)
sshKey, err := cs.Client.GetSSHKey(ctx, gCurrentAccount.DefaultZone, c.Key)
if err != nil {
return err
}
return c.outputFunc(&computeSSHKeyShowOutput{
Name: *sshKey.Name,
Fingerprint: *sshKey.Fingerprint,
}, nil)
}
func init() {
cobra.CheckErr(registerCLICommand(computeSSHKeyCmd, &computeSSHKeyShowCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}