MCPcopy Index your code
hub / github.com/devspace-sh/devspace / runProxyCommand

Function runProxyCommand

helper/cmd/proxycommands/run.go:35–134  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

33}
34
35func runProxyCommand(args []string) error {
36 key, err := os.ReadFile(sshPrivateKeyPath)
37 if err != nil {
38 return errors.Wrap(err, "read private key")
39 }
40
41 signer, err := ssh.ParsePrivateKey(key)
42 if err != nil {
43 return errors.Wrap(err, "parse private key")
44 }
45
46 clientConfig := &ssh.ClientConfig{
47 Auth: []ssh.AuthMethod{
48 ssh.PublicKeys(signer),
49 },
50 HostKeyCallback: ssh.InsecureIgnoreHostKey(),
51 }
52
53 // get port
54 port, err := os.ReadFile(portPath)
55 if err != nil {
56 return errors.Wrap(err, "read port")
57 }
58
59 // dial ssh
60 client, err := ssh.Dial("tcp", "localhost:"+string(port), clientConfig)
61 if err != nil {
62 return errors.Wrap(err, "dial ssh")
63 }
64 defer client.Close()
65
66 // create new session
67 session, err := client.NewSession()
68 if err != nil {
69 return errors.Wrap(err, "new session")
70 }
71 defer session.Close()
72
73 // check if we should use a pty
74 var (
75 width = 0
76 height = 0
77 )
78
79 tty, t := terminal.SetupTTY(os.Stdin, os.Stdout)
80 if tty {
81 info, ok := term.GetFdInfo(t.In)
82 if ok {
83 winSize, err := term.GetWinsize(info)
84 if err == nil {
85 width = int(winSize.Width)
86 height = int(winSize.Height)
87 }
88 }
89 }
90
91 // get current working directory
92 currentWorkingDir, err := os.Getwd()

Callers 2

RunMethod · 0.85
RunMethod · 0.85

Calls 5

CloseMethod · 0.95
SetupTTYFunction · 0.92
CloseMethod · 0.65
EnvironMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected