consolerun

package
v0.216.3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package consolerun implements `wb console` (spec/features/console-connect): the browser-approved connection of this machine to Sneat Dev Console, its status, disconnection, and the hand-over of the person's task key.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportFromDaemon

func ExportFromDaemon(ctx context.Context, projectsRoot string) cockpitrun.ExportResult

ExportFromDaemon is the production Export.

func Sleep

func Sleep(ctx context.Context, d time.Duration) error

Sleep waits for d or until ctx ends.

func TaskKeyPath

func TaskKeyPath(configPath string) string

TaskKeyPath is where the person's task key lives.

Types

type Client

Client is the part of the Console client these commands use.

func NewConsoleClient

func NewConsoleClient(url, credentialFile string) (Client, error)

NewConsoleClient is the production NewClient.

type ConnectRequest

type ConnectRequest struct {
	ProjectsRoot  string
	ConsoleURL    string
	Machine       string
	Detail        console.Level
	DetailChanged bool
	SpaceHint     string
	NoBrowser     bool
	CanOpen       bool
	NoRestart     bool
	TaskKeyStdin  bool
	Input         io.Reader
	Notice        io.Writer
}

ConnectRequest is `wb console connect`.

type ConnectResult

type ConnectResult struct {
	Machine         string          `json:"machine"`
	MachineID       string          `json:"machine_id"`
	ConsoleURL      string          `json:"console_url"`
	PersonalSpaceID string          `json:"personal_space_id"`
	Shares          []console.Share `json:"shares,omitempty"`
	Detail          console.Level   `json:"detail"`
	CredentialFile  string          `json:"credential_file"`
	TaskKeyID       string          `json:"task_key_id"`
	TaskKeyCreated  bool            `json:"task_key_created"`
	ConfigPath      string          `json:"config_path"`
	DetailOnly      bool            `json:"detail_only,omitempty"`
	DaemonRestarted bool            `json:"daemon_restarted"`
}

ConnectResult is what connect reports. It never carries the credential or the task key, only the key's public fingerprint.

type Dependencies

type Dependencies struct {
	ConfigPath  func() string
	NewClient   func(url, credentialFile string) (Client, error)
	MachineName func(configPath string) string
	MachineID   func(projectsRoot string) (string, error)
	OpenBrowser func(string) error
	Restart     func(ctx context.Context, projectsRoot string) error
	Sleep       func(context.Context, time.Duration) error
	Now         func() time.Time
	Random      io.Reader
	// Export reads this machine's export from its running daemon, with the
	// throughput block (cockpitrun.Export with WithThroughput).
	Export    func(ctx context.Context, projectsRoot string) cockpitrun.ExportResult
	WBVersion string
	OS, Arch  string
}

Dependencies are the effects the commands have, replaced in tests.

func DefaultPlatform

func DefaultPlatform(deps Dependencies) Dependencies

DefaultPlatform fills OS and Arch from the running binary.

type DisconnectResult

type DisconnectResult struct {
	Revoked         bool   `json:"revoked"`
	CredentialFile  string `json:"credential_file"`
	ConfigPath      string `json:"config_path"`
	DaemonRestarted bool   `json:"daemon_restarted"`
}

DisconnectResult is what disconnect reports.

type PushResult

type PushResult struct {
	ConsoleURL string        `json:"console_url"`
	Detail     console.Level `json:"detail"`
	Hash       string        `json:"hash"`
	AcceptedAt time.Time     `json:"accepted_at"`
	Heartbeat  bool          `json:"heartbeat"`
	// Warnings are problems that did not stop the push, such as a `full`
	// push sent without its repositories copy because the task key is unusable.
	Warnings []string `json:"warnings,omitempty"`
}

PushResult is `wb console push --json`.

type Service

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

Service runs the commands.

func New

func New(deps Dependencies, exit func(int, string) error) *Service

New returns a Service; exit builds WB's coded exit errors.

func (*Service) Connect

func (s *Service) Connect(ctx context.Context, request ConnectRequest) (ConnectResult, error)

Connect enrolls this machine (console-connect#req:device-code-enrollment), or, on a connected machine given only --detail, changes its detail level.

func (*Service) Disconnect

func (s *Service) Disconnect(ctx context.Context, projectsRoot string, noRestart bool) (DisconnectResult, error)

Disconnect revokes at Console, then removes the credential and the console: fields (console-connect#req:disconnect-revokes). When Console cannot be reached it still removes them locally and reports revoked=false.

func (*Service) ExportTaskKey

func (s *Service) ExportTaskKey(out io.Writer, stdoutIsTerminal bool) error

ExportTaskKey writes the task key for the person's next machine, only to a non-terminal stdout.

func (*Service) Push

func (s *Service) Push(ctx context.Context, projectsRoot string) (PushResult, error)

Push publishes this machine's state now, read from its running daemon and reduced exactly as the daemon's own publisher reduces it, then sends a heartbeat. Without a running daemon there is nothing to read: exit 1.

func (*Service) Status

func (s *Service) Status(ctx context.Context) (StatusResult, error)

Status reads the configuration and Console's record of this machine. Not being connected, or a Console error, is reported in the result; the command turns either into exit 1.

type StatusResult

type StatusResult struct {
	Connected       bool              `json:"connected"`
	Paused          bool              `json:"paused,omitempty"`
	Problem         string            `json:"problem,omitempty"`
	ConsoleURL      string            `json:"console_url,omitempty"`
	Machine         string            `json:"machine,omitempty"`
	MachineID       string            `json:"machine_id,omitempty"`
	PersonalSpaceID string            `json:"personal_space_id,omitempty"`
	Shares          []console.Share   `json:"shares,omitempty"`
	Detail          console.Level     `json:"detail,omitempty"`
	LastSnapshotAt  *time.Time        `json:"last_snapshot_at,omitempty"`
	LastHeartbeatAt *time.Time        `json:"last_heartbeat_at,omitempty"`
	ConsoleError    console.ErrorCode `json:"console_error,omitempty"`
	Fix             string            `json:"fix,omitempty"`
}

StatusResult is `wb console status --json`.

Jump to

Keyboard shortcuts

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