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
26 changes: 19 additions & 7 deletions desktop/internal/core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type requestEnvelope struct {
GitExecution *gitExecution `json:"gitExecution,omitempty"`
// Origin is the user action the request belongs to, nil for none (see Origin).
Origin *requestOrigin `json:"origin,omitempty"`
// RemoteWorkspace is the host folder the request's workspace paths stand for, nil for a
// local request (WithRemoteWorkspace).
RemoteWorkspace *remoteWorkspace `json:"remoteWorkspace,omitempty"`
}

// gitExecution is the part of a request's Git policy the client sets (GitExecutionOptions in
Expand Down Expand Up @@ -113,14 +116,19 @@ func (c *Client) execute(ctx context.Context, command string, payload, result an
if payload == nil {
payload = struct{}{}
}
remote, binding, session, err := remoteWorkspaceRequest(ctx, command)
if err != nil {
return nil, err
}
operationID := fmt.Sprintf("desktop-%d", nextCoreOperation.Add(1))
execution := gitExecutionOf(ctx, command)
request, err := json.Marshal(requestEnvelope{
OperationID: operationID,
Command: command,
Payload: payload,
GitExecution: execution,
Origin: requestOriginOf(ctx),
OperationID: operationID,
Command: command,
Payload: payload,
GitExecution: execution,
Origin: requestOriginOf(ctx),
RemoteWorkspace: remote,
})
if err != nil {
return nil, &Error{
Expand All @@ -146,12 +154,16 @@ func (c *Client) execute(ctx context.Context, command string, payload, result an
observer = gitAuthenticationObserver(gitAuthenticationOf(ctx, command), returned, observer)
}
if observer == nil {
return nil, decodeResponse(ctx, command, call(ctx, operationID, request), result)
err = decodeResponse(ctx, command, call(ctx, operationID, request), result)
remoteWorkspaceAnswered(binding, session, err)
return nil, err
}
stop := watchCancellation(ctx, operationID)
defer stop()
response, observationErr := executeJSONWithEvents(request, observer)
return observationErr, decodeResponse(ctx, command, response, result)
err = decodeResponse(ctx, command, response, result)
remoteWorkspaceAnswered(binding, session, err)
return observationErr, err
}

// call sends one encoded request while a watcher forwards cancellation of ctx to the kernel.
Expand Down
4 changes: 4 additions & 0 deletions desktop/internal/core/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const (
CodeTimedOut ErrorCode = "timed_out"
// CodeConnectionClosed means a long-lived connection named by the request is closed.
CodeConnectionClosed ErrorCode = "connection_closed"
// CodeRemoteServerInvalid means the remote server build for the host's platform could not be
// read, or its SHA-256 is not the one the application's manifest names; nothing was sent to
// the host.
CodeRemoteServerInvalid ErrorCode = "remote_server_invalid"
// CodeUnknown means the failure fits no more specific category.
CodeUnknown ErrorCode = "unknown"
)
Expand Down
17 changes: 2 additions & 15 deletions desktop/internal/core/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,10 @@ type RemoteProbeResult struct {
// 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) {
prompt, _ := ctx.Value(gitAuthenticationKey{}).(func(GitAuthChallenge))
if prompt == nil {
prompt = func(challenge GitAuthChallenge) {
// The answer must not wait on the request's goroutine, which delivers the event.
go func() { _, _ = c.RemoteAuthRespond(context.Background(), challenge.RequestID, nil) }()
}
}
returned := make(chan struct{})
defer close(returned)
observer := gitAuthenticationObserver(func(challenge GitAuthChallenge) {
challenge.Remote = true
prompt(challenge)
}, returned, nil)
var result RemoteProbeResult
observationErr, err := c.ExecuteWithEvents(ctx, "remote.probe", struct {
observationErr, err := c.executeRemoteWithPrompts(ctx, "remote.probe", struct {
Connection SSHConnection `json:"connection"`
}{connection}, &result, observer)
}{connection}, &result)
if err != nil {
return RemoteProbeResult{}, err
}
Expand Down
Loading
Loading