feat: add blockcontroller outline for single shell

This adds the code that will call the shellexec code. It also disables
the existing connserver/install code for single shell mode.
This commit is contained in:
Sylvia Crowe 2024-12-27 01:50:27 -08:00
parent d9bac1cabd
commit 7880eb8f89
4 changed files with 42 additions and 1 deletions

View File

@ -291,6 +291,7 @@ declare global {
"conn:wshenabled"?: boolean;
"conn:askbeforewshinstall"?: boolean;
"conn:overrideconfig"?: boolean;
"conn:singlesession"?: boolean;
"display:hidden"?: boolean;
"display:order"?: number;
"term:*"?: boolean;

View File

@ -316,6 +316,13 @@ func (bc *BlockController) DoRunShellCommand(rc *RunShellOpts, blockMeta waveobj
} else {
return fmt.Errorf("unknown controller type %q", bc.ControllerType)
}
var singleSession bool
fullConfig := wconfig.ReadFullConfig()
existingConnection, ok := fullConfig.Connections[remoteName]
if ok {
singleSession = existingConnection.ConnSingleSession
}
var shellProc *shellexec.ShellProc
if strings.HasPrefix(remoteName, "wsl://") {
wslName := strings.TrimPrefix(remoteName, "wsl://")
@ -340,6 +347,36 @@ func (bc *BlockController) DoRunShellCommand(rc *RunShellOpts, blockMeta waveobj
if err != nil {
return err
}
} else if remoteName != "" && singleSession {
credentialCtx, cancelFunc := context.WithTimeout(context.Background(), 60*time.Second)
defer cancelFunc()
opts, err := remote.ParseOpts(remoteName)
if err != nil {
return err
}
conn := conncontroller.GetConn(credentialCtx, opts, false, &wshrpc.ConnKeywords{})
connStatus := conn.DeriveConnStatus()
if connStatus.Status != conncontroller.Status_Connected {
return fmt.Errorf("not connected, cannot start shellproc")
}
if !blockMeta.GetBool(waveobj.MetaKey_CmdNoWsh, false) {
jwtStr, err := wshutil.MakeClientJWTToken(wshrpc.RpcContext{TabId: bc.TabId, BlockId: bc.BlockId, Conn: conn.Opts.String()}, conn.GetDomainSocketName())
if err != nil {
return fmt.Errorf("error making jwt token: %w", err)
}
cmdOpts.Env[wshutil.WaveJwtTokenVarName] = jwtStr
}
shellProc, err = shellexec.StartSingleSessionRemoteShellProc(rc.TermSize, conn)
if err != nil {
return err
}
// todo
// i have disabled the conn server for this type of connection
// this means we need to receive a signal from the process once it has
// opened a domain socket. then, once that is done, we can forward the
// unix domain socket here. also, we need to set the wsh boolean true as
// is done in the current connserver implementation
} else if remoteName != "" {
credentialCtx, cancelFunc := context.WithTimeout(context.Background(), 60*time.Second)
defer cancelFunc()

View File

@ -511,6 +511,7 @@ func (conn *SSHConn) connectInternal(ctx context.Context, connFlags *wshrpc.Conn
})
config := wconfig.ReadFullConfig()
enableWsh := config.Settings.ConnWshEnabled
var singleSession bool
askBeforeInstall := config.Settings.ConnAskBeforeWshInstall
connSettings, ok := config.Connections[conn.GetName()]
if ok {
@ -520,8 +521,9 @@ func (conn *SSHConn) connectInternal(ctx context.Context, connFlags *wshrpc.Conn
if connSettings.ConnAskBeforeWshInstall != nil {
askBeforeInstall = *connSettings.ConnAskBeforeWshInstall
}
singleSession = connSettings.ConnSingleSession
}
if enableWsh {
if enableWsh && !singleSession {
installErr := conn.CheckAndInstallWsh(ctx, clientDisplayName, &WshInstallOpts{NoUserPrompt: !askBeforeInstall})
if errors.Is(installErr, &WshInstallSkipError{}) {
// skips are not true errors

View File

@ -462,6 +462,7 @@ type ConnKeywords struct {
ConnWshEnabled *bool `json:"conn:wshenabled,omitempty"`
ConnAskBeforeWshInstall *bool `json:"conn:askbeforewshinstall,omitempty"`
ConnOverrideConfig bool `json:"conn:overrideconfig,omitempty"`
ConnSingleSession bool `json:"conn:singlesession,omitempty"`
DisplayHidden *bool `json:"display:hidden,omitempty"`
DisplayOrder float32 `json:"display:order,omitempty"`