mirror of
https://github.com/coder/coder.git
synced 2025-07-21 01:28:49 +00:00
feat: add WorkspaceUpdates tailnet RPC (#14847)
Closes #14716 Closes #14717 Adds a new user-scoped tailnet API endpoint (`api/v2/tailnet`) with a new RPC stream for receiving updates on workspaces owned by a specific user, as defined in #14716. When a stream is started, the `WorkspaceUpdatesProvider` will begin listening on the user-scoped pubsub events implemented in #14964. When a relevant event type is seen (such as a workspace state transition), the provider will query the DB for all the workspaces (and agents) owned by the user. This gets compared against the result of the previous query to produce a set of workspace updates. Workspace updates can be requested for any user ID, however only workspaces the authorised user is permitted to `ActionRead` will have their updates streamed. Opening a tunnel to an agent requires that the user can perform `ActionSSH` against the workspace containing it.
This commit is contained in:
@ -402,3 +402,37 @@ func (c *Client) DeleteProvisionerKey(ctx context.Context, organizationID uuid.U
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ConvertWorkspaceStatus(jobStatus ProvisionerJobStatus, transition WorkspaceTransition) WorkspaceStatus {
|
||||
switch jobStatus {
|
||||
case ProvisionerJobPending:
|
||||
return WorkspaceStatusPending
|
||||
case ProvisionerJobRunning:
|
||||
switch transition {
|
||||
case WorkspaceTransitionStart:
|
||||
return WorkspaceStatusStarting
|
||||
case WorkspaceTransitionStop:
|
||||
return WorkspaceStatusStopping
|
||||
case WorkspaceTransitionDelete:
|
||||
return WorkspaceStatusDeleting
|
||||
}
|
||||
case ProvisionerJobSucceeded:
|
||||
switch transition {
|
||||
case WorkspaceTransitionStart:
|
||||
return WorkspaceStatusRunning
|
||||
case WorkspaceTransitionStop:
|
||||
return WorkspaceStatusStopped
|
||||
case WorkspaceTransitionDelete:
|
||||
return WorkspaceStatusDeleted
|
||||
}
|
||||
case ProvisionerJobCanceling:
|
||||
return WorkspaceStatusCanceling
|
||||
case ProvisionerJobCanceled:
|
||||
return WorkspaceStatusCanceled
|
||||
case ProvisionerJobFailed:
|
||||
return WorkspaceStatusFailed
|
||||
}
|
||||
|
||||
// return error status since we should never get here
|
||||
return WorkspaceStatusFailed
|
||||
}
|
||||
|
@ -580,6 +580,11 @@ func (f *fakeDRPCClient) RefreshResumeToken(_ context.Context, _ *proto.RefreshR
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WorkspaceUpdates implements proto.DRPCTailnetClient.
|
||||
func (*fakeDRPCClient) WorkspaceUpdates(context.Context, *proto.WorkspaceUpdatesRequest) (proto.DRPCTailnet_WorkspaceUpdatesClient, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
type fakeDRPCConn struct{}
|
||||
|
||||
var _ drpc.Conn = &fakeDRPCConn{}
|
||||
|
Reference in New Issue
Block a user