当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.OpenChannel方法代码示例

本文整理汇总了Golang中golang.org/x/crypto/ssh.Client.OpenChannel方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.OpenChannel方法的具体用法?Golang Client.OpenChannel怎么用?Golang Client.OpenChannel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在golang.org/x/crypto/ssh.Client的用法示例。


在下文中一共展示了Client.OpenChannel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: handleChannel

func handleChannel(newChannel ssh.NewChannel, rClient *ssh.Client) {
	if newChannel.ChannelType() != "session" {
		newChannel.Reject(ssh.UnknownChannelType, "unknown channel type: "+newChannel.ChannelType())
		return
	}
	psChannel, psRequests, err := newChannel.Accept()
	if err != nil {
		panic("could not accept channel.")
	}

	sChannel, sRequests, err := rClient.OpenChannel(newChannel.ChannelType(), nil)
	if err != nil {
		panic("Failed to create session: " + err.Error())
	}

	go pipeRequests(psChannel, sChannel, psRequests, sRequests)
	time.Sleep(50 * time.Millisecond)
	go pipe(sChannel, psChannel)
	go pipe(psChannel, sChannel)
}
开发者ID:Freeaqingme,项目名称:SshReverseProxy,代码行数:20,代码来源:daemon.go

示例2: SSHAttach

// SSHAttach returns a stream connection to the requested session
// The ssh client is assumed to be connected to the Executor hosting the session
func SSHAttach(client *ssh.Client, id string) (SessionInteraction, error) {
	defer trace.End(trace.Begin(""))

	sessionSSH := &attachSSH{
		client: client,
	}

	var err error
	sessionSSH.channel, sessionSSH.requests, err = client.OpenChannel(attachChannelType, []byte(id))
	if err != nil {
		return nil, err
	}

	// we have to handle incoming requests to the client on this channel but we don't support any currently
	go func() {
		for req := range sessionSSH.requests {
			// default, preserving OpenSSH behaviour
			req.Reply(false, nil)
		}
	}()

	return sessionSSH, nil
}
开发者ID:vmware,项目名称:vic,代码行数:25,代码来源:client.go

示例3:

			It("does not terminate the session", func() {
				response, err := session.Output("/bin/echo -n Hello")
				Expect(err).NotTo(HaveOccurred())
				Expect(response).To(Equal([]byte("Hello")))
			})
		})
	})

	Context("when a session channel is opened", func() {
		var channel ssh.Channel
		var requests <-chan *ssh.Request

		BeforeEach(func() {
			var err error
			channel, requests, err = client.OpenChannel("session", nil)
			Expect(err).NotTo(HaveOccurred())

			go ssh.DiscardRequests(requests)
		})

		AfterEach(func() {
			if channel != nil {
				channel.Close()
			}
		})

		Context("and an exec request fails to unmarshal", func() {
			It("rejects the request", func() {
				accepted, err := channel.SendRequest("exec", true, ssh.Marshal(struct{ Bogus uint32 }{Bogus: 1138}))
				Expect(err).NotTo(HaveOccurred())
开发者ID:sykesm,项目名称:diego-ssh,代码行数:30,代码来源:session_channel_handler_test.go

示例4:

				It("the handler returns", func() {
					Consistently(completed).ShouldNot(Receive())

					Expect(echoHandler.HandleConnectionCallCount()).To(Equal(1))
					echoConn := echoHandler.HandleConnectionArgsForCall(0)
					echoConn.Close()

					Eventually(completed).Should(Receive())
				})
			})
		})
	})

	Context("when the direct-tcpip extra data fails to unmarshal", func() {
		It("rejects the open channel request", func() {
			_, _, err := client.OpenChannel("direct-tcpip", ssh.Marshal(struct{ Bogus int }{Bogus: 1234}))
			Expect(err).To(Equal(&ssh.OpenChannelError{
				Reason:  ssh.ConnectionFailed,
				Message: "Failed to parse open channel message",
			}))

		})
	})

	Context("when dialing the target fails", func() {
		BeforeEach(func() {
			testDialer.DialStub = func(net, addr string) (net.Conn, error) {
				return nil, errors.New("woops")
			}
		})
开发者ID:benjaminharnett,项目名称:diego-ssh,代码行数:30,代码来源:direct_tcpip_channel_handler_test.go

示例5:

					})
				})

				Context("when the client requests a new channel", func() {
					var newChannelHandler *fake_handlers.FakeNewChannelHandler

					BeforeEach(func() {
						newChannelHandler = &fake_handlers.FakeNewChannelHandler{}
						newChannelHandler.HandleNewChannelStub = func(logger lager.Logger, newChannel ssh.NewChannel) {
							newChannel.Reject(ssh.Prohibited, "not now")
						}
						daemonNewChannelHandlers["test"] = newChannelHandler
					})

					It("gets forwarded to the daemon", func() {
						_, _, err := client.OpenChannel("test", nil)
						Expect(err).To(Equal(&ssh.OpenChannelError{Reason: ssh.Prohibited, Message: "not now"}))
					})
				})
			})

			Describe("target requests to client", func() {
				var (
					connectionHandler *server_fakes.FakeConnectionHandler

					target        *server.Server
					listener      net.Listener
					targetAddress string

					clientConn     ssh.Conn
					clientChannels <-chan ssh.NewChannel
开发者ID:sykesm,项目名称:diego-ssh,代码行数:31,代码来源:proxy_test.go

示例6:

		AfterEach(func() {
			client.Close()
		})

		Context("when a new channel request is received", func() {
			var (
				channelType string

				sshChannel  ssh.Channel
				requestChan <-chan *ssh.Request
				openError   error
			)

			JustBeforeEach(func() {
				sshChannel, requestChan, openError = client.OpenChannel(channelType, []byte("extra-data"))
			})

			Context("and there is an associated handler", func() {
				BeforeEach(func() {
					channelType = "known-channel-type"

					fakeHandler.HandleNewChannelStub = func(logger lager.Logger, newChannel ssh.NewChannel) {
						ch, _, err := newChannel.Accept()
						Expect(err).NotTo(HaveOccurred())
						ch.Close()
					}
				})

				It("calls the handler to process the new channel request", func() {
					Expect(fakeHandler.HandleNewChannelCallCount()).To(Equal(1))
开发者ID:benjaminharnett,项目名称:diego-ssh,代码行数:30,代码来源:daemon_test.go


注:本文中的golang.org/x/crypto/ssh.Client.OpenChannel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。