-
Notifications
You must be signed in to change notification settings - Fork 20
/
ssh_key_show.go
70 lines (54 loc) · 1.87 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
68
69
70
package cmd
import (
"fmt"
"strings"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
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() { output.JSON(o) }
func (o *computeSSHKeyShowOutput) ToText() { output.Text(o) }
func (o *computeSSHKeyShowOutput) ToTable() { output.Table(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(output.TemplateAnnotations(&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(account.CurrentAccount.Environment, account.CurrentAccount.DefaultZone),
)
sshKey, err := globalstate.EgoscaleClient.Client.GetSSHKey(ctx, account.CurrentAccount.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(),
}))
}