mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-09-30 03:51:43 +02:00
Add more options to /exec (#435)
* Add SSH exec session options * Remove unused exec session helper
This commit is contained in:
+24
-4
@@ -49,7 +49,12 @@ type EventsPageOptions struct {
|
||||
|
||||
type ExecSessionOptions struct {
|
||||
Command string
|
||||
Stdin bool
|
||||
Interactive bool
|
||||
TTY bool
|
||||
Rows uint32
|
||||
Cols uint32
|
||||
Env map[string]string
|
||||
Workdir string
|
||||
WaitSeconds uint16
|
||||
Session string
|
||||
}
|
||||
@@ -173,7 +178,7 @@ func (service *VMsService) Exec(
|
||||
) (*websocket.Conn, error) {
|
||||
return service.ExecSession(ctx, name, ExecSessionOptions{
|
||||
Command: command,
|
||||
Stdin: stdin,
|
||||
Interactive: stdin,
|
||||
WaitSeconds: waitSeconds,
|
||||
})
|
||||
}
|
||||
@@ -189,8 +194,23 @@ func (service *VMsService) ExecSession(
|
||||
if options.Command != "" {
|
||||
params["command"] = options.Command
|
||||
}
|
||||
if options.Stdin {
|
||||
params["stdin"] = strconv.FormatBool(true)
|
||||
if options.Interactive {
|
||||
params["interactive"] = strconv.FormatBool(true)
|
||||
}
|
||||
if options.TTY {
|
||||
params["tty"] = strconv.FormatBool(true)
|
||||
}
|
||||
if options.Rows > 0 {
|
||||
params["rows"] = strconv.FormatUint(uint64(options.Rows), 10)
|
||||
}
|
||||
if options.Cols > 0 {
|
||||
params["cols"] = strconv.FormatUint(uint64(options.Cols), 10)
|
||||
}
|
||||
for key, value := range options.Env {
|
||||
params[fmt.Sprintf("env[%s]", key)] = value
|
||||
}
|
||||
if options.Workdir != "" {
|
||||
params["workdir"] = options.Workdir
|
||||
}
|
||||
if options.Session != "" {
|
||||
params["session"] = options.Session
|
||||
|
||||
+12
-2
@@ -26,7 +26,12 @@ func TestExecSessionBuildsReconnectableQuery(t *testing.T) {
|
||||
|
||||
conn, err := devClient.VMs().ExecSession(t.Context(), "vm", ExecSessionOptions{
|
||||
Command: "echo hello",
|
||||
Stdin: true,
|
||||
Interactive: true,
|
||||
TTY: true,
|
||||
Rows: 24,
|
||||
Cols: 80,
|
||||
Env: map[string]string{"GREETING": "hello"},
|
||||
Workdir: "/tmp",
|
||||
WaitSeconds: 7,
|
||||
Session: "resume-me",
|
||||
})
|
||||
@@ -34,7 +39,12 @@ func TestExecSessionBuildsReconnectableQuery(t *testing.T) {
|
||||
defer conn.CloseNow()
|
||||
|
||||
require.Equal(t, []string{"echo hello"}, query["command"])
|
||||
require.Equal(t, []string{"true"}, query["stdin"])
|
||||
require.Equal(t, []string{"true"}, query["interactive"])
|
||||
require.Equal(t, []string{"true"}, query["tty"])
|
||||
require.Equal(t, []string{"24"}, query["rows"])
|
||||
require.Equal(t, []string{"80"}, query["cols"])
|
||||
require.Equal(t, []string{"hello"}, query["env[GREETING]"])
|
||||
require.Equal(t, []string{"/tmp"}, query["workdir"])
|
||||
require.Equal(t, []string{"7"}, query["wait"])
|
||||
require.Equal(t, []string{"resume-me"}, query["session"])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user