Ejemplo n.º 1
0
func (*AppDialer) Dial(appName string, instanceIndex int, config *config_package.Config) (Client, error) {
	diegoSSHUser := fmt.Sprintf("diego:%s/%d", appName, instanceIndex)
	address := fmt.Sprintf("%s:2222", config.Target())

	client, err := sshapi.New(diegoSSHUser, config.Username(), config.Password(), address)
	if err != nil {
		return nil, err
	}

	return client, nil
}
Ejemplo n.º 2
0
		sshapi.DialFunc = func(network, addr string, config *ssh.ClientConfig) (*ssh.Client, error) {
			Expect(network).To(Equal("tcp"))
			Expect(addr).To(Equal("some-host"))
			Expect(config.User).To(Equal("some-ssh-user"))

			Expect(config.Auth).To(HaveLen(1))

			actualSecret := reflect.ValueOf(config.Auth[0]).Call([]reflect.Value{})[0].Interface()
			Expect(actualSecret).To(Equal("some-user:some-password"))

			dialCalled = true

			return sshClient, nil
		}

		client, err := sshapi.New("some-ssh-user", "some-user", "some-password", "some-host")
		Expect(err).NotTo(HaveOccurred())
		Expect(client.Dialer == sshClient).To(BeTrue())
		Expect(client.SSHSessionFactory.(*sshapi.CryptoSSHSessionFactory).Client == sshClient).To(BeTrue())
		Expect(client.Stdin).To(Equal(os.Stdin))
		Expect(client.Stdout).To(Equal(os.Stdout))
		Expect(client.Stderr).To(Equal(os.Stderr))

		Expect(dialCalled).To(BeTrue())
	})

	Context("when dialing fails", func() {
		It("should return an error", func() {
			origDial := sshapi.DialFunc
			defer func() { sshapi.DialFunc = origDial }()