generated from brevdev/seed
-
Notifications
You must be signed in to change notification settings - Fork 14
/
sshkeys.go
54 lines (47 loc) · 1.64 KB
/
sshkeys.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
// Package sshkeys gets your public ssh key to add to github/gitlab
package sshkeys
import (
"github.com/brevdev/brev-cli/pkg/cmdcontext"
"github.com/brevdev/brev-cli/pkg/entity"
breverrors "github.com/brevdev/brev-cli/pkg/errors"
"github.com/brevdev/brev-cli/pkg/terminal"
"github.com/spf13/cobra"
)
type SSHKeyStore interface {
GetCurrentUser() (*entity.User, error)
}
func NewCmdSSHKeys(t *terminal.Terminal, sshKeyStore SSHKeyStore) *cobra.Command {
cmd := &cobra.Command{
Annotations: map[string]string{"housekeeping": ""},
Use: "ssh-key",
Short: "Get your pulic SSH-Key",
Long: "Get your pulic SSH-Key to add to pull and push from your git repository.",
Example: `brev ssh-key`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
err := cmdcontext.InvokeParentPersistentPreRun(cmd, args)
if err != nil {
return breverrors.WrapAndTrace(err)
}
return nil
},
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
user, err := sshKeyStore.GetCurrentUser()
if err != nil {
return breverrors.WrapAndTrace(err)
}
DisplaySSHKeys(t, user.PublicKey)
return nil
},
}
return cmd
}
func DisplaySSHKeys(t *terminal.Terminal, publicKey string) {
t.Vprintf(publicKey)
t.Print("\n")
t.Eprintf(t.Yellow("Copy 👆 and add it to your git provider:\n"))
t.Eprintf(t.Yellow("\tGithub: https://github.com/settings/keys\n"))
t.Eprintf(t.Yellow("\tGitlab: https://gitlab.com/-/profile/keys\n"))
t.Eprintf(t.Yellow("Check authentication by starting a new dev environment\n"))
t.Eprintf(t.Yellow("\tbrev start --empty --name test-ssh && brev delete test-ssh\n"))
}