commit
22433a57db
3 changed files with 28 additions and 31 deletions
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
// A PortForwarder forwards TCP traffic over a LiveShare session from a port on a remote
|
||||
// A PortForwarder forwards TCP traffic over a Live Share session from a port on a remote
|
||||
// container to a local destination such as a network port or Go reader/writer.
|
||||
type PortForwarder struct {
|
||||
session *Session
|
||||
|
|
|
|||
27
session.go
27
session.go
|
|
@ -3,6 +3,7 @@ package liveshare
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// A Session represents the session between a connected Live Share client and server.
|
||||
|
|
@ -59,3 +60,29 @@ func (s *Session) UpdateSharedVisibility(ctx context.Context, port int, public b
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// StartsSSHServer starts an SSH server in the container, installing sshd if necessary,
|
||||
// and returns the port on which it listens and the user name clients should provide.
|
||||
func (s *Session) StartSSHServer(ctx context.Context) (int, string, error) {
|
||||
var response struct {
|
||||
Result bool `json:"result"`
|
||||
ServerPort string `json:"serverPort"`
|
||||
User string `json:"user"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
if err := s.rpc.do(ctx, "ISshServerHostService.startRemoteServer", []string{}, &response); err != nil {
|
||||
return 0, "", err
|
||||
}
|
||||
|
||||
if !response.Result {
|
||||
return 0, "", fmt.Errorf("failed to start server: %s", response.Message)
|
||||
}
|
||||
|
||||
port, err := strconv.Atoi(response.ServerPort)
|
||||
if err != nil {
|
||||
return 0, "", fmt.Errorf("failed to parse port: %w", err)
|
||||
}
|
||||
|
||||
return port, response.User, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
package liveshare
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type SSHServer struct {
|
||||
session *Session
|
||||
}
|
||||
|
||||
func (session *Session) SSHServer() *SSHServer {
|
||||
return &SSHServer{session: session}
|
||||
}
|
||||
|
||||
type SSHServerStartResult struct {
|
||||
Result bool `json:"result"`
|
||||
ServerPort string `json:"serverPort"`
|
||||
User string `json:"user"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
func (s *SSHServer) StartRemoteServer(ctx context.Context) (*SSHServerStartResult, error) {
|
||||
var response SSHServerStartResult
|
||||
|
||||
if err := s.session.rpc.do(ctx, "ISshServerHostService.startRemoteServer", []string{}, &response); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue