solve

package
v0.54.1 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package solve asks the service whether there is work for this machine.

The agent asks; the service never calls the agent. That is the decision the whole channel rests on: nothing new listens on the customer's server, so nothing new on it can be attacked. It travels on the same outgoing HTTPS and the same token the agent already uses for scans.

This package only carries messages. Running an action is #182's job, and deliberately not here — the road first, then what travels on it.

Index

Constants

View Source
const (
	// ModeDryRun means: find out what would change, and report it. Change nothing.
	ModeDryRun = "dry_run"
	// ModeRun means: a human approved this. Do it.
	ModeRun = "run"
)

Mode is what the service is asking this agent to do.

Variables

This section is empty.

Functions

func ReportDryRun

func ReportDryRun(ctx context.Context, apiBaseURL, token string, report DryRunReport) error

ReportDryRun sends back what would change. The job then waits for a human.

func ReportResult

func ReportResult(ctx context.Context, apiBaseURL, token string, report ResultReport) error

ReportResult sends back how the run ended, whether or not it worked.

Types

type Action

type Action struct {
	Type   string            `json:"type"`
	Params map[string]string `json:"params,omitempty"`
}

Action is one thing the service is asking for: a type from the agent's own catalog, and the values to fill in. Never a command.

type DryRunReport

type DryRunReport struct {
	MachineUUID string `json:"machine_uuid"`
	JobID       string `json:"-"`
	PreviewID   string `json:"preview_id"`

	// OK is false when this machine cannot carry the actions out at all. That is
	// still a preview: the answer to "what would happen here" is "nothing, and
	// this is why". The service refuses to let such a preview be approved, so a
	// person is not sent to a server to be told a second time.
	OK bool `json:"ok"`

	Detail any `json:"detail"`
}

DryRunReport is what would have changed, had the agent acted.

Detail is whatever the runtime produced, passed through untouched: the real commands, their real output and the honest ledger. Summarising it here would be choosing for the customer what they get to see.

type ResultReport

type ResultReport struct {
	MachineUUID string `json:"machine_uuid"`
	JobID       string `json:"-"`
	OK          bool   `json:"ok"`
	Detail      any    `json:"detail"`
}

ResultReport is how a run ended.

type Work

type Work struct {
	Mode    string   `json:"mode"`
	JobID   string   `json:"job_id"`
	Actions []Action `json:"actions"`

	// Backup is whether the person asked for a copy to be taken first. It is a
	// request, not an instruction: whether one is possible is measured on this
	// machine, at the moment of running.
	Backup bool `json:"backup"`
}

Work is the service's answer to "is there anything for me?".

func NextWork

func NextWork(ctx context.Context, apiBaseURL, token, machineUUID string) (Work, error)

NextWork asks whether there is anything to do on this machine.

func (Work) HasWork

func (w Work) HasWork() bool

HasWork reports whether the service gave us something to do.

An empty answer is the normal case, not a failure: most machines are idle most of the time, and a loop that treated silence as an error would log a warning every minute on every quiet server.

Jump to

Keyboard shortcuts

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