Skip to content

Commit afa917d

Browse files
committed
fix: set session env via command
1 parent f075216 commit afa917d

3 files changed

Lines changed: 5 additions & 17 deletions

File tree

helper/cmd/proxy_commands/run.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"golang.org/x/crypto/ssh"
1111
"io/ioutil"
1212
"os"
13-
"strings"
1413
)
1514

1615
// RunCmd holds the ssh cmd flags
@@ -59,19 +58,6 @@ func (cmd *RunCmd) Run(_ *cobra.Command, args []string) error {
5958
}
6059
defer session.Close()
6160

62-
// set environment variables
63-
for _, v := range os.Environ() {
64-
splitted := strings.Split(v, "=")
65-
if len(splitted) < 2 {
66-
continue
67-
}
68-
69-
err = session.Setenv(splitted[0], strings.Join(splitted[1:], "="))
70-
if err != nil {
71-
return errors.Wrap(err, "set session env")
72-
}
73-
}
74-
7561
// check if we should use a pty
7662
tty, t := terminal.SetupTTY(os.Stdin, os.Stdout)
7763
if tty {
@@ -81,8 +67,8 @@ func (cmd *RunCmd) Run(_ *cobra.Command, args []string) error {
8167
if err == nil {
8268
err = session.RequestPty("xterm", int(winSize.Height), int(winSize.Width), ssh.TerminalModes{
8369
ssh.ECHO: 0,
84-
ssh.TTY_OP_ISPEED: 14400,
85-
ssh.TTY_OP_OSPEED: 14400,
70+
ssh.TTY_OP_ISPEED: 28800,
71+
ssh.TTY_OP_OSPEED: 28800,
8672
})
8773
if err != nil {
8874
return errors.Wrap(err, "request pty")
@@ -101,6 +87,7 @@ func (cmd *RunCmd) Run(_ *cobra.Command, args []string) error {
10187

10288
// marshal command and execute command
10389
proxyCommand := &types.ProxyCommand{
90+
Env: os.Environ(),
10491
Args: args,
10592
WorkingDir: currentWorkingDir,
10693
}

helper/types/proxy_command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package types
22

33
type ProxyCommand struct {
4+
Env []string `json:"env,omitempty"`
45
Args []string `json:"args,omitempty"`
56
WorkingDir string `json:"workingDir,omitempty"`
67
}

pkg/devspace/services/proxycommands/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (s *Server) getCommand(sess ssh.Session) (*exec.Cmd, error) {
166166
}
167167

168168
s.log.Debugf("run command '%s %s' locally", c, strings.Join(args, " "))
169-
cmd.Env = append(cmd.Env, sess.Environ()...)
169+
cmd.Env = append(cmd.Env, command.Env...)
170170
cmd.Env = append(cmd.Env, os.Environ()...)
171171
return cmd, nil
172172
}

0 commit comments

Comments
 (0)