本文整理汇总了Golang中golang.org/x/crypto/ssh.Client.SendRequest方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.SendRequest方法的具体用法?Golang Client.SendRequest怎么用?Golang Client.SendRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/crypto/ssh.Client
的用法示例。
在下文中一共展示了Client.SendRequest方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sendSshKeepAlive
// sendSshKeepAlive is a helper which sends a [email protected] request
// on the specified SSH connections and returns true of the request succeeds
// within a specified timeout.
func sendSshKeepAlive(
sshClient *ssh.Client, conn net.Conn, timeout time.Duration) error {
errChannel := make(chan error, 2)
if timeout > 0 {
time.AfterFunc(timeout, func() {
errChannel <- TimeoutError{}
})
}
go func() {
// Random padding to frustrate fingerprinting
_, _, err := sshClient.SendRequest(
"[email protected]", true,
MakeSecureRandomPadding(0, TUNNEL_SSH_KEEP_ALIVE_PAYLOAD_MAX_BYTES))
errChannel <- err
}()
err := <-errChannel
if err != nil {
sshClient.Close()
conn.Close()
}
return ContextError(err)
}
示例2: sendSshKeepAlive
// sendSshKeepAlive is a helper which sends a [email protected] request
// on the specified SSH connections and returns true of the request succeeds
// within a specified timeout.
func sendSshKeepAlive(sshClient *ssh.Client) error {
errChannel := make(chan error, 2)
time.AfterFunc(TUNNEL_SSH_KEEP_ALIVE_TIMEOUT, func() {
errChannel <- TimeoutError{}
})
go func() {
// Random padding to frustrate fingerprinting
_, _, err := sshClient.SendRequest(
"[email protected]", true,
MakeSecureRandomPadding(0, TUNNEL_SSH_KEEP_ALIVE_PAYLOAD_MAX_BYTES))
errChannel <- err
}()
return ContextError(<-errChannel)
}
示例3: SSHls
func SSHls(client *ssh.Client) ([]string, error) {
defer trace.End(trace.Begin(""))
ok, reply, err := client.SendRequest(msgs.ContainersReq, true, nil)
if !ok || err != nil {
return nil, fmt.Errorf("failed to get container IDs from remote: %s", err)
}
ids := msgs.ContainersMsg{}
if err = ids.Unmarshal(reply); err != nil {
log.Debugf("raw IDs response: %+v", reply)
return nil, fmt.Errorf("failed to unmarshal ids from remote: %s", err)
}
return ids.IDs, nil
}
示例4:
client.Close()
})
Context("when the client sends a global request", func() {
var globalRequestHandler *fake_handlers.FakeGlobalRequestHandler
BeforeEach(func() {
globalRequestHandler = &fake_handlers.FakeGlobalRequestHandler{}
globalRequestHandler.HandleRequestStub = func(logger lager.Logger, request *ssh.Request) {
request.Reply(true, []byte("response-payload"))
}
daemonGlobalRequestHandlers["test-global-request"] = globalRequestHandler
})
It("gets forwarded to the daemon and the response comes back", func() {
accepted, response, err := client.SendRequest("test-global-request", true, []byte("request-payload"))
Expect(err).NotTo(HaveOccurred())
Expect(accepted).To(BeTrue())
Expect(response).To(Equal([]byte("response-payload")))
Expect(globalRequestHandler.HandleRequestCallCount()).To(Equal(1))
_, request := globalRequestHandler.HandleRequestArgsForCall(0)
Expect(request.Type).To(Equal("test-global-request"))
Expect(request.WantReply).To(BeTrue())
Expect(request.Payload).To(Equal([]byte("request-payload")))
})
})
Context("when the client requests a new channel", func() {
var newChannelHandler *fake_handlers.FakeNewChannelHandler
示例5:
AfterEach(func() {
client.Close()
})
Context("when a global request is recevied", func() {
var (
accepted bool
requestErr error
name string
wantReply bool
)
JustBeforeEach(func() {
accepted, _, requestErr = client.SendRequest(name, wantReply, []byte("payload"))
})
Context("and there is an associated handler", func() {
BeforeEach(func() {
name = "known-handler"
wantReply = true
fakeHandler.HandleRequestStub = func(logger lager.Logger, request *ssh.Request) {
request.Reply(true, []byte("response"))
}
})
It("calls the handler to handle the request", func() {
Eventually(fakeHandler.HandleRequestCallCount).Should(Equal(1))
})