Esempio n. 1
0
func (c *MountCommand) prepareForSSH(sshKey *ssh.SSHKey) error {
	if err := sshKey.PrepareForSSH(c.Options.Name); err != nil {
		if strings.Contains(err.Error(), "user: unknown user") {
			c.printfln(CannotFindSSHUser)
			return fmt.Errorf("Cannot ssh into managed machines. err:%s", err)
		}

		if klientctlerrors.IsMachineNotValidYetErr(err) {
			c.printfln(defaultHealthChecker.CheckAllFailureOrMessagef(MachineNotValidYet))
			return fmt.Errorf("Machine is not valid yet. err:%s", err)
		}

		c.printfln(FailedGetSSHKey)
		return fmt.Errorf("Error getting ssh key. err:%s", err)
	}

	return nil
}
Esempio n. 2
0
func (c *Command) prepareForSSH(machineName string, sshKey *ssh.SSHKey) error {
	if err := sshKey.PrepareForSSH(machineName); err != nil {
		if strings.Contains(err.Error(), "user: unknown user") {
			c.Stdout.Printlnf(errormessages.CannotFindSSHUser)
			return fmt.Errorf("Cannot ssh into managed machines. err:%s", err)
		}

		if klientctlerrors.IsMachineNotValidYetErr(err) {
			c.Stdout.Printlnf(
				c.HealthChecker.CheckAllFailureOrMessagef(errormessages.MachineNotValidYet),
			)
			return fmt.Errorf("Machine is not valid yet. err:%s", err)
		}

		c.Stdout.Printlnf(errormessages.FailedGetSSHKey)
		return fmt.Errorf("Error getting ssh key. err:%s", err)
	}

	return nil
}
Esempio n. 3
0
func TestSSHKey(t *testing.T) {
	Convey("It should discover remote IP for tunneled connection", t, func() {
		srv := discovertest.Server{
			"ssh": {{
				Addr:  "apple.rafal.grape.koding.me:2222",
				Local: false,
			}},
		}

		l, err := srv.Start()
		So(err, ShouldBeNil)
		defer l.Close()

		k := &fakeKlient{
			RemoteUsername: "******",
			Remotes: list.KiteInfos{{
				ListMachineInfo: restypes.ListMachineInfo{
					Hostname: "root",
					VMName:   "remote",
					IP:       l.Addr().String(),
				},
			}},
		}

		s := ssh.SSHKey{
			Klient: k,
		}

		userhost, port, err := s.GetSSHAddr("remote")
		So(err, ShouldBeNil)
		So(userhost, ShouldEqual, "*****@*****.**")
		So(port, ShouldEqual, "2222")
	})

	Convey("It should discover local IP for tunneled connection", t, func() {
		srv := discovertest.Server{
			"ssh": {{
				Addr:  "127.0.0.1:2222",
				Local: true,
			}},
		}

		l, err := srv.Start()
		So(err, ShouldBeNil)
		defer l.Close()

		k := &fakeKlient{
			RemoteUsername: "******",
			Remotes: list.KiteInfos{{
				ListMachineInfo: restypes.ListMachineInfo{
					Hostname: "root",
					VMName:   "local",
					IP:       l.Addr().String(),
				},
			}},
		}

		s := ssh.SSHKey{
			Klient: k,
		}

		userhost, port, err := s.GetSSHAddr("local")
		So(err, ShouldBeNil)
		So(userhost, ShouldEqual, "[email protected]")
		So(port, ShouldEqual, "2222")
	})
}