MCPcopy Create free account
hub / github.com/devspace-sh/devspace / NewServer

Function NewServer

helper/ssh/server.go:19–75  ·  view source on GitHub ↗
(addr string, hostKey []byte, keys []ssh.PublicKey)

Source from the content-addressed store, hash-verified

17var DefaultPort = 8022
18
19func NewServer(addr string, hostKey []byte, keys []ssh.PublicKey) (*Server, error) {
20 shell, err := getShell()
21 if err != nil {
22 return nil, err
23 }
24
25 forwardHandler := &ssh.ForwardedTCPHandler{}
26 server := &Server{
27 shell: shell,
28 sshServer: ssh.Server{
29 Addr: addr,
30 PublicKeyHandler: func(ctx ssh.Context, key ssh.PublicKey) bool {
31 if len(keys) == 0 {
32 return true
33 }
34
35 for _, k := range keys {
36 if ssh.KeysEqual(k, key) {
37 return true
38 }
39 }
40
41 stderrlog.Debugf("Declined public key")
42 return false
43 },
44 LocalPortForwardingCallback: func(ctx ssh.Context, dhost string, dport uint32) bool {
45 stderrlog.Debugf("Accepted forward", dhost, dport)
46 return true
47 },
48 ReversePortForwardingCallback: func(ctx ssh.Context, host string, port uint32) bool {
49 stderrlog.Debugf("attempt to bind", host, port, "granted")
50 return true
51 },
52 ChannelHandlers: map[string]ssh.ChannelHandler{
53 "direct-tcpip": ssh.DirectTCPIPHandler,
54 "session": ssh.DefaultSessionHandler,
55 },
56 RequestHandlers: map[string]ssh.RequestHandler{
57 "tcpip-forward": forwardHandler.HandleSSHRequest,
58 "cancel-tcpip-forward": forwardHandler.HandleSSHRequest,
59 },
60 SubsystemHandlers: map[string]ssh.SubsystemHandler{
61 "sftp": SftpHandler,
62 },
63 },
64 }
65
66 if len(hostKey) > 0 {
67 err = server.sshServer.SetOption(ssh.HostKeyPEM(hostKey))
68 if err != nil {
69 return nil, err
70 }
71 }
72
73 server.sshServer.Handler = server.handler
74 return server, nil
75}
76

Callers

nothing calls this directly

Calls 2

DebugfFunction · 0.92
getShellFunction · 0.85

Tested by

no test coverage detected