Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions desktop/internal/core/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,14 @@ type RemoteProbeResult struct {
// challenge with Remote set, answered with RemoteAuthRespond; without a prompt each question is
// cancelled at once. Core bounds a probe, answers included, to five minutes. The probe changes
// nothing, so an observation failure is reported only when the request itself succeeded.
func (c *Client) RemoteProbe(ctx context.Context, connection SSHConnection) (RemoteProbeResult, error) {
// preferences is the remote workspace preference document, or nil; it names the SSH program, and
// a damaged one fails with CodeParseFailed before OpenSSH starts.
func (c *Client) RemoteProbe(ctx context.Context, connection SSHConnection, preferences *string) (RemoteProbeResult, error) {
var result RemoteProbeResult
observationErr, err := c.executeRemoteWithPrompts(ctx, "remote.probe", struct {
Connection SSHConnection `json:"connection"`
}{connection}, &result)
Connection SSHConnection `json:"connection"`
Preferences *string `json:"preferences,omitempty"`
}{connection, preferences}, &result)
if err != nil {
return RemoteProbeResult{}, err
}
Expand Down
18 changes: 11 additions & 7 deletions desktop/internal/core/remote_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ type RemoteEffectiveSettings struct {

// RemoteEffectiveSettings asks OpenSSH what it would use for connection, without connecting.
// Core bounds the run to 10 seconds: CodeRuntimeMissing without ssh, CodeProcessFailed with the
// redacted standard error in Details, CodeTimedOut and CodeParseFailed.
func (c *Client) RemoteEffectiveSettings(ctx context.Context, connection SSHConnection) (RemoteEffectiveSettings, error) {
// redacted standard error in Details, CodeTimedOut and CodeParseFailed. preferences is the
// remote workspace preference document, or nil, naming the SSH program.
func (c *Client) RemoteEffectiveSettings(ctx context.Context, connection SSHConnection, preferences *string) (RemoteEffectiveSettings, error) {
var settings RemoteEffectiveSettings
err := c.Execute(ctx, "remote.effectiveSettings", struct {
Connection SSHConnection `json:"connection"`
}{connection}, &settings)
Connection SSHConnection `json:"connection"`
Preferences *string `json:"preferences,omitempty"`
}{connection, preferences}, &settings)
return settings, err
}

Expand Down Expand Up @@ -135,13 +137,15 @@ type RemoteSSHConfigHosts struct {

// RemoteSSHConfigHosts reads ~/.ssh/config below homeDirectory, an absolute path, and checks each
// host against document, the saved connections or nil. Core runs `ssh -G` for each alias within
// 30 seconds for the whole list; CodeRuntimeMissing without ssh.
func (c *Client) RemoteSSHConfigHosts(ctx context.Context, homeDirectory string, document *string) (RemoteSSHConfigHosts, error) {
// 30 seconds for the whole list; CodeRuntimeMissing without ssh. preferences is the remote
// workspace preference document, or nil, naming the SSH program.
func (c *Client) RemoteSSHConfigHosts(ctx context.Context, homeDirectory string, document, preferences *string) (RemoteSSHConfigHosts, error) {
var hosts RemoteSSHConfigHosts
err := c.Execute(ctx, "remote.sshConfigHosts", struct {
HomeDirectory string `json:"homeDirectory"`
Document *string `json:"document"`
}{homeDirectory, document}, &hosts)
Preferences *string `json:"preferences,omitempty"`
}{homeDirectory, document, preferences}, &hosts)
hosts.Files = nonNil(hosts.Files)
hosts.Hosts = nonNil(hosts.Hosts)
return hosts, err
Expand Down
4 changes: 2 additions & 2 deletions desktop/internal/core/remote_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestRemoteEffectiveSettingsNameTheirSources(t *testing.T) {
"hostname 192.0.2.10\nuser dev\nport 2222\nidentityfile ~/.ssh/build_key\nconnecttimeout 15\nserveraliveinterval 0\nproxyjump jump-box",
"hostname build-box\nuser localdev\nport 22\nidentityfile ~/.ssh/id_ed25519\nconnecttimeout 15\nserveraliveinterval 0\nproxyjump none",
)
settings, err := NewClient().RemoteEffectiveSettings(testContext(t), SSHConnection{Host: "build-box", User: "dev"})
settings, err := NewClient().RemoteEffectiveSettings(testContext(t), SSHConnection{Host: "build-box", User: "dev"}, nil)
if err != nil {
t.Fatalf("effective settings: %v", err)
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestRemoteSSHConfigHostsListTheAliases(t *testing.T) {
if err := os.WriteFile(filepath.Join(home, ".ssh", "config"), []byte("Host build-box\n HostName 192.0.2.10\n\nHost *.lab\n User dev\n"), 0o600); err != nil {
t.Fatal(err)
}
hosts, err := NewClient().RemoteSSHConfigHosts(testContext(t), home, nil)
hosts, err := NewClient().RemoteSSHConfigHosts(testContext(t), home, nil, nil)
if err != nil || len(hosts.Files) != 1 || len(hosts.Hosts) != 2 {
t.Fatalf("hosts = %+v, err = %v", hosts, err)
}
Expand Down
121 changes: 121 additions & 0 deletions desktop/internal/core/remote_preferences.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package core

import "context"

// Remote workspace preferences: the values of the settings page Tools › Remote Workspace. The
// document is machine-local; the desktop reads and publishes it like the saved connections, and
// Core validates it, applies one edit at a time and tells what each automatic value resolves to.

// RemotePreferenceSource says whether a value is the user's setting or the automatic one.
type RemotePreferenceSource string

const (
// RemotePreferenceFromSetting is a value the user chose.
RemotePreferenceFromSetting RemotePreferenceSource = "setting"
// RemotePreferenceAutomatic is the value Core picks when the user chose none.
RemotePreferenceAutomatic RemotePreferenceSource = "automatic"
)

// RemoteProgramStatus is what is at the SSH program path when the page reads it.
type RemoteProgramStatus string

const (
// RemoteProgramFound is an executable file.
RemoteProgramFound RemoteProgramStatus = "found"
// RemoteProgramMissing is nothing at the saved path; for the automatic value, no ssh on
// PATH, so Core starts the bare name ssh for the system to look up.
RemoteProgramMissing RemoteProgramStatus = "missing"
// RemoteProgramNotExecutable is a directory or a file that cannot be run.
RemoteProgramNotExecutable RemoteProgramStatus = "notExecutable"
)

// RemotePreferenceValues are the stored values; nil is automatic.
type RemotePreferenceValues struct {
SSHProgram *string `json:"sshProgram"`
ReconnectLimitSeconds *uint32 `json:"reconnectLimitSeconds"`
}

// RemoteSSHProgram is the OpenSSH client Core starts. Path is nil only when the automatic
// value finds no ssh on PATH.
type RemoteSSHProgram struct {
Source RemotePreferenceSource `json:"source"`
Path *string `json:"path"`
Status RemoteProgramStatus `json:"status"`
}

// RemoteReconnect is how a dropped session is reconnected: one attempt after each pause in
// DelaysMilliseconds, which add up to LimitSeconds. No pauses means no automatic reconnect.
type RemoteReconnect struct {
Source RemotePreferenceSource `json:"source"`
LimitSeconds uint32 `json:"limitSeconds"`
DelaysMilliseconds []uint64 `json:"delaysMilliseconds"`
}

// RemotePreferenceStorage is where the document lives below the application's preference root.
type RemotePreferenceStorage struct {
RelativePath string `json:"relativePath"`
MaximumBytes int64 `json:"maximumBytes"`
}

// RemoteSSHConfigFile is the user's ~/.ssh/config.
type RemoteSSHConfigFile struct {
Path string `json:"path"`
Exists bool `json:"exists"`
}

// RemotePreferences is what remote.preferences reports. SSHConfig is set only when a home
// directory was given.
type RemotePreferences struct {
Preferences RemotePreferenceValues `json:"preferences"`
SSH RemoteSSHProgram `json:"ssh"`
Reconnect RemoteReconnect `json:"reconnect"`
Storage RemotePreferenceStorage `json:"storage"`
SSHConfig *RemoteSSHConfigFile `json:"sshConfig"`
}

// RemotePreferences reads document, the preference document's text or nil when there is none.
// homeDirectory, an absolute path or empty, adds the SSH configuration file. A document that
// cannot be decoded fails with CodeParseFailed; a relative home directory with
// CodeInvalidRequest naming homeDirectory in RemoteConnectionFieldError.
func (c *Client) RemotePreferences(ctx context.Context, document *string, homeDirectory string) (RemotePreferences, error) {
var result RemotePreferences
err := c.Execute(ctx, "remote.preferences", struct {
Document *string `json:"document"`
HomeDirectory string `json:"homeDirectory,omitempty"`
}{document, homeDirectory}, &result)
result.Reconnect.DelaysMilliseconds = nonNil(result.Reconnect.DelaysMilliseconds)
return result, err
}

// RemotePreferenceEdit changes one value: set exactly one field. A nil Path or Seconds makes the
// value automatic again.
type RemotePreferenceEdit struct {
SSHProgram *RemoteSSHProgramEdit `json:"sshProgram,omitempty"`
ReconnectLimit *RemoteReconnectLimitEdit `json:"reconnectLimit,omitempty"`
}

// RemoteSSHProgramEdit sets the SSH program to an absolute path of an executable file.
type RemoteSSHProgramEdit struct {
Path *string `json:"path"`
}

// RemoteReconnectLimitEdit sets how long a dropped session is reconnected, 0 to 3600 seconds.
type RemoteReconnectLimitEdit struct {
Seconds *uint32 `json:"seconds"`
}

// EditRemotePreferences applies edit to document. changed is false, and the document nil, when
// nothing changes. A refused value fails with CodeInvalidRequest and names sshProgram or
// reconnectLimitSeconds with the reason (invalid, tooLong, relative, missing, notExecutable,
// outOfRange) in RemoteConnectionFieldError; a damaged document fails with CodeParseFailed.
func (c *Client) EditRemotePreferences(ctx context.Context, document *string, edit RemotePreferenceEdit) (changed bool, updated *string, err error) {
var result struct {
Changed bool `json:"changed"`
Document *string `json:"document"`
}
err = c.Execute(ctx, "remote.editPreferences", struct {
Document *string `json:"document"`
RemotePreferenceEdit
}{document, edit}, &result)
return result.Changed, result.Document, err
}
3 changes: 3 additions & 0 deletions desktop/internal/core/remote_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type RemoteConnectRequest struct {
ServerVersion string `json:"serverVersion"`
// InstallRoot is where the host keeps installed servers; empty is $HOME/.lithe-server.
InstallRoot string `json:"installRoot,omitempty"`
// Preferences is the remote workspace preference document, or nil. It names the SSH program;
// a WSL connection ignores it.
Preferences *string `json:"preferences,omitempty"`
}

// WSLConnection is a distribution of the Windows Subsystem for Linux on this machine, as
Expand Down
2 changes: 1 addition & 1 deletion desktop/internal/core/remote_session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func TestRemoteConnectAsksThroughTheHostAndSendsNoUnreadableBuild(t *testing.T)
var probe RemoteProbeResult
var probeErr error
finishesWithin(t, "probe", testDeadline, func() {
probe, probeErr = client.RemoteProbe(WithGitAuthentication(testContext(t), prompt), connection)
probe, probeErr = client.RemoteProbe(WithGitAuthentication(testContext(t), prompt), connection, nil)
})
if probeErr != nil || probe.Host == nil {
t.Fatalf("probe = %+v, %v", probe, probeErr)
Expand Down
4 changes: 2 additions & 2 deletions desktop/internal/core/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestRemoteProbeAsksThroughTheHostAndReportsThePlatform(t *testing.T) {
var result RemoteProbeResult
var err error
finishesWithin(t, "probe", testDeadline, func() {
result, err = client.RemoteProbe(WithGitAuthentication(testContext(t), prompt), SSHConnection{Host: "devbox", User: "dev"})
result, err = client.RemoteProbe(WithGitAuthentication(testContext(t), prompt), SSHConnection{Host: "devbox", User: "dev"}, nil)
})
finishesWithin(t, "answers", testDeadline, replies.Wait)
if err != nil {
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestRemoteProbeWithoutAPromptCancelsEachQuestion(t *testing.T) {
var result RemoteProbeResult
var err error
finishesWithin(t, "probe", testDeadline, func() {
result, err = NewClient().RemoteProbe(testContext(t), SSHConnection{Host: "devbox", User: "dev"})
result, err = NewClient().RemoteProbe(testContext(t), SSHConnection{Host: "devbox", User: "dev"}, nil)
})
if err != nil {
t.Fatalf("probe: %v", err)
Expand Down
1 change: 1 addition & 0 deletions desktop/internal/i18n/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ type SettingsMessages struct {
Debuggers string
Console string
TrustedLocations string
RemoteWorkspace string
Languages string
Tools string
SearchPage string
Expand Down
1 change: 1 addition & 0 deletions desktop/internal/i18n/settings_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func settingsMessages(language Language) SettingsMessages {
Debuggers: Shared(language, "desktop.buildSettings.debuggers"),
Console: Shared(language, "desktop.consoleSettings.title"),
TrustedLocations: Shared(language, "desktop.trustedLocations.title"),
RemoteWorkspace: Shared(language, "desktop.remoteSettings.title"),
Languages: Shared(language, "settings.groups.languages"),
Tools: Shared(language, "settings.groups.tools"),
SearchPage: Shared(language, "desktop.search.settings.title"),
Expand Down
Loading
Loading