This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 604
Expand file tree
/
Copy pathssh.go
More file actions
70 lines (59 loc) · 1.64 KB
/
ssh.go
File metadata and controls
70 lines (59 loc) · 1.64 KB
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 main
import (
"fmt"
"github.com/koding/logging"
"koding/klientctl/config"
"koding/klientctl/shortcut"
"koding/klientctl/ssh"
"github.com/codegangsta/cli"
)
// SSHCommandFactory is the factory method for SSHCommand.
func SSHCommandFactory(c *cli.Context, log logging.Logger, _ string) int {
if len(c.Args()) != 1 {
cli.ShowCommandHelp(c, "ssh")
return 1
}
if c.Bool("debug") {
log.SetLevel(logging.DEBUG)
}
opts := ssh.SSHCommandOpts{
Debug: c.Bool("debug") || config.Konfig.Debug,
RemoteUsername: c.String("username"),
Ask: true,
}
cmd, err := ssh.NewSSHCommand(log, opts)
mountName := c.Args()[0]
// TODO: Refactor SSHCommand instance to require no initialization,
// and thus avoid needing to log an error in a weird place.
if err != nil {
log.Error("Error initializing ssh: %s", err)
switch err {
case ssh.ErrLocalDialingFailed:
fmt.Println(
defaultHealthChecker.CheckAllFailureOrMessagef(KlientIsntRunning),
)
default:
fmt.Println(GenericInternalError)
}
return 1
}
err = cmd.Run(mountName)
switch err {
case nil:
return 0
case ssh.ErrMachineNotFound:
fmt.Println(MachineNotFound)
case ssh.ErrCannotFindUser:
fmt.Println(CannotFindSSHUser)
case ssh.ErrFailedToGetSSHKey:
fmt.Println(FailedGetSSHKey)
case ssh.ErrMachineNotValidYet:
fmt.Println(defaultHealthChecker.CheckAllFailureOrMessagef(MachineNotValidYet))
case ssh.ErrRemoteDialingFailed:
fmt.Println(defaultHealthChecker.CheckAllFailureOrMessagef(FailedDialingRemote))
case shortcut.ErrMachineNotFound:
fmt.Println(MachineNotFound)
}
log.Error("SSHCommand.Run returned err:%s", err)
return 1
}