workbench

package
v1.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package workbench implements service.WorkbenchService: it manages the per-vault Docker container backing a vault's cloud workbench. See docs/workbench/01_data_model_and_lifecycle.md for the full state machine and docs/workbench/02_docker_topology.md for the Docker client this composes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(
	workbenches repository.Workbenches,
	vaults repository.Vaults,
	dockerHosts repository.DockerHosts,
	externalConnections externalConnectionService,
	newDockerClient func(host string, tlsCfg workbenchdocker.TLSConfig) (dockerClient, error),
) *Service

func (*Service) CreateWorkbench

func (s *Service) CreateWorkbench(ctx context.Context, vaultID uuid.UUID) (domain.Workbench, error)

CreateWorkbench records a 'configuring' workbenches row for vaultID, then provisions the Docker volume and (unstarted) container backing it, and finally records the container id with status='created'. Safely re-invocable: if a workbenches row for vaultID already exists (e.g. a retry after a partial failure), it's returned as-is rather than duplicated — see docs/workbench/01_data_model_and_lifecycle.md, "Hook points".

The row is inserted before the Docker calls (rather than after, as previously) so that a vaultID that never gets a workbench created for it is still driven by a caller explicitly invoking this method (see CreateWorkbench RPC), and so a caller/UI can observe a 'configuring' state while Docker provisioning is in flight. If CreateVolume or CreateContainer fails after the row is inserted, the row is intentionally left in 'configuring' rather than rolled back or cleaned up here — DeleteWorkbench already tolerates partial Docker state (missing container/volume) when tearing down, so a stuck 'configuring' row is recoverable by deleting and retrying rather than needing bespoke rollback logic here.

The docker host backing the new workbench is picked once, up front, by DockerHosts.PickLeastLoaded — spreading new workbenches across the registered pool. Returns user_errors.NoDockerHostsAvailable if the pool is empty.

func (*Service) DeleteWorkbench

func (s *Service) DeleteWorkbench(ctx context.Context, vaultID uuid.UUID) error

DeleteWorkbench tears down vaultID's workbench: stops (if a container was created) and removes the container, removes the volume, then deletes the DB row — in that order, so a failure partway through never leaves the DB pointing at nothing while Docker still holds a live container (see docs/workbench/01_data_model_and_lifecycle.md, "Vault deletion"). A missing workbench row is treated as already-deleted, not an error. "Not found" from Docker (container/volume already gone, e.g. a retry picking up after a prior partial failure) is likewise tolerated at each step rather than failing the whole call.

func (*Service) GetLoginPrompt

func (s *Service) GetLoginPrompt(ctx context.Context, vaultID uuid.UUID) (domain.WorkbenchLoginPrompt, error)

GetLoginPrompt returns a snapshot of vaultID's subscription_login TUI flow, derived by capturing the workbench's tmux pane and parsing it — see docs/workbench/03_auth_and_login_flow.md, "Mechanism (confirmed)", steps 2-3 and 5-6.

func (*Service) GetWorkbench

func (s *Service) GetWorkbench(ctx context.Context, vaultID uuid.UUID) (domain.Workbench, error)

GetWorkbench returns the workbench for vaultID.

func (*Service) StartWorkbench

func (s *Service) StartWorkbench(
	ctx context.Context, vaultID uuid.UUID, authMode domain.WorkbenchAuthMode,
) (domain.Workbench, error)

StartWorkbench starts vaultID's workbench container under authMode — see docs/workbench/03_auth_and_login_flow.md for both modes' designs. Any mode besides the two domain.WorkbenchAuthMode constants fails with user_errors.WorkbenchAuthModeNotImplemented rather than silently falling back.

func (*Service) StopWorkbench

func (s *Service) StopWorkbench(ctx context.Context, vaultID uuid.UUID) error

StopWorkbench stops vaultID's running workbench container, retaining it (and its volume) for a later restart, and records status='stopped'/stopped_at.

func (*Service) SubmitLoginCode

func (s *Service) SubmitLoginCode(ctx context.Context, vaultID uuid.UUID, code string) error

SubmitLoginCode relays the user's pasted OAuth code (or, on a brand-new container, their first theme/menu keystroke) back into vaultID's workbench tmux session — see docs/workbench/03_auth_and_login_flow.md, "Mechanism (confirmed)", step 4.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL