client

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 17 Imported by: ? 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 client is the Go SDK of the OSAPI REST API.

Create a client with New(), then call the typed services, one for each group of the API. internal/sdk/gen writes the services and their types from the API's spec:

c := client.New("http://localhost:8080", "your-jwt-token")

// The hostname of each host.
resp, err := c.Hostname.Get(ctx, "_all")

// Run a command on one host.
resp, err := c.Command.Exec(ctx, "web-01", client.CommandExecRequest{
    Command: "uptime",
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TraceIDOf added in v0.3.0

func TraceIDOf(
	h http.Header,
) string

TraceIDOf returns the trace ID of an answer's headers, from its W3C traceresponse header, or "" when it has none. A program that reads the answers itself, as the CLI's transport does for a request that failed, uses it.

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
	// Reason is why the request failed, as the API names it, such as
	// not_found or not_managed. A program branches on it, not on Message.
	// It is empty when the answer gives none.
	Reason types.Reason
	// Body is the answer as it came, for a status whose body is not an
	// error, such as a probe's 503. Request sets it.
	Body []byte
}

APIError is the base error type for OSAPI API errors.

func (*APIError) Answer added in v0.3.0

func (e *APIError) Answer() (int, []byte)

Answer is the status and the body of the answer, for a caller that prints a status whose body is not an error.

func (*APIError) Error

func (e *APIError) Error() string

Error returns a formatted error string.

type Admission added in v0.3.0

type Admission struct {
	// When the node was admitted.
	AdmittedAt time.Time `json:"admitted_at,omitzero"`

	// When the node was rejected or revoked.
	DecidedAt time.Time `json:"decided_at,omitzero"`

	// The node's public P-256 encryption key, which the fingerprint covers.
	EncryptionKey string `json:"encryption_key,omitempty"`

	// The fingerprint of the node's two public keys: signing and encryption.
	Fingerprint string `json:"fingerprint"`

	// The hostname the node gave.
	Hostname string `json:"hostname"`

	// On an admitted record that a join made, the ID of the join token that
	// admitted the node.
	JoinToken string `json:"join_token,omitempty"`

	// When the node last reported.
	LastSeen time.Time `json:"last_seen,omitzero"`

	// The machine ID of the node.
	MachineID string `json:"machine_id"`

	// Whether the node is running now: it is in the registry.
	Online bool `json:"online"`

	// The state of a node's admission record: pending, admitted, rejected or
	// revoked.
	Previous types.AdmissionState `json:"previous,omitzero"`

	// On a pending record, the fingerprint of the earlier record; a different one
	// is a new key.
	PreviousFingerprint string `json:"previous_fingerprint,omitempty"`

	// Why the node was rejected.
	Reason string `json:"reason,omitempty"`

	// When the node asked to join.
	RequestedAt time.Time `json:"requested_at,omitzero"`

	// The state of a node's admission record: pending, admitted, rejected or
	// revoked.
	State types.AdmissionState `json:"state"`
}

Admission is the Admission of the spec.

type AdmissionAdmitInput added in v0.3.0

type AdmissionAdmitInput struct {
	// The machine_id of the path: the machine ID of the node.
	MachineID string `json:"-"`

	// The fingerprint that osapi pki key get --name agent prints on the machine.
	Fingerprint string `json:"fingerprint"`
}

AdmissionAdmitInput is the input of AdmissionService.Admit. A field of the path goes in the path, and each other field in the body.

type AdmissionListParams added in v0.3.0

type AdmissionListParams struct {
	// State is the state of the query: only the records in this state: pending,
	// admitted, rejected or revoked. The zero value leaves it out.
	State types.AdmissionState
}

AdmissionListParams are the parameters of AdmissionService.List that a request can leave out.

type AdmissionRejectInput added in v0.3.0

type AdmissionRejectInput struct {
	// The machine_id of the path: the machine ID of the node.
	MachineID string `json:"-"`

	// Why the machine is rejected; the machine and the record keep it.
	Reason string `json:"reason,omitempty"`
}

AdmissionRejectInput is the input of AdmissionService.Reject. A field of the path goes in the path, and each other field in the body.

type AdmissionService added in v0.3.0

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

AdmissionService calls the API's Admission group: admit, reject and revoke the nodes that ask to join.

func (*AdmissionService) Admit added in v0.3.0

func (s *AdmissionService) Admit(
	ctx context.Context,
	input AdmissionAdmitInput,
) error

Admit is the operation AdmitMachine: admit a pending machine.

Admits a pending machine. The fingerprint must be the one that `osapi pki key get --name agent` prints on the machine: it proves that the request came from the machine the operator is looking at.

It sends POST /api/admission/{machine_id}/admit, and needs the permission admission:write.

func (*AdmissionService) Delete added in v0.3.0

func (s *AdmissionService) Delete(
	ctx context.Context,
	machineID string,
) error

Delete is the operation DeleteMachine: delete a machine.

Removes a machine's key and each record of it, and keeps none. A machine that asks again is new. Use it for a machine that goes away on purpose, such as a VM that is rebuilt; revoke a machine that is not trusted.

It sends DELETE /api/admission/{machine_id}, and needs the permission admission:write.

func (*AdmissionService) Get added in v0.3.0

func (s *AdmissionService) Get(
	ctx context.Context,
	machineID string,
) (*Response[Admission], error)

Get is the operation GetAdmission: get a machine's admission record.

Returns one machine's admission record by machine ID.

It sends GET /api/admission/{machine_id}, and needs the permission admission:read.

func (*AdmissionService) List added in v0.3.0

List is the operation GetAdmissions: list admission records.

Returns each machine's admission record: pending, admitted, rejected or revoked, with whether it is online and when it was last seen.

It sends GET /api/admission, and needs the permission admission:read.

func (*AdmissionService) Reject added in v0.3.0

func (s *AdmissionService) Reject(
	ctx context.Context,
	input AdmissionRejectInput,
) error

Reject is the operation RejectMachine: reject a pending machine.

Rejects a pending machine, and keeps a record of the decision, so a machine that asks again is flagged.

It sends POST /api/admission/{machine_id}/reject, and needs the permission admission:write.

func (*AdmissionService) Revoke added in v0.3.0

func (s *AdmissionService) Revoke(
	ctx context.Context,
	machineID string,
) error

Revoke is the operation RevokeMachine: revoke an admitted machine.

Removes an admitted machine's key, and keeps a record of the decision. Nothing the machine signs verifies afterwards; to return, it asks again.

It sends POST /api/admission/{machine_id}/revoke, and needs the permission admission:write.

type AgentConfigResponse added in v0.3.0

type AgentConfigResponse struct {
	// How often the agent collects its facts; empty keeps the agent's config file.
	FactsInterval string `json:"facts_interval,omitempty"`

	// The labels that the controller gives the agent.
	Labels map[string]string `json:"labels,omitempty"`

	// LogLevel is the level that a process logs at, one of its Values.
	LogLevel types.LogLevel `json:"log_level,omitzero"`

	// The most jobs that the agent runs at the same time; empty keeps the agent's
	// config file.
	MaxJobs int `json:"max_jobs,omitempty"`

	// When the config last changed.
	UpdatedAt time.Time `json:"updated_at,omitzero"`

	// One more at each change; 0 when nothing was set.
	Version int `json:"version"`
}

AgentConfigResponse is the AgentConfigResponse of the spec.

type AgentDetail added in v0.3.0

type AgentDetail struct {
	// Agent hostname.
	Hostname string `json:"hostname"`

	// Formatted label string.
	Labels string `json:"labels,omitempty"`

	// Time since last heartbeat registration.
	Registered string `json:"registered"`
}

AgentDetail is the AgentDetail of the spec.

type AgentInfo added in v0.3.0

type AgentInfo struct {
	// CPU architecture.
	Architecture string `json:"architecture,omitempty"`

	// The conditions that hold now, such as HighLoad. A condition that does not
	// hold is not in the list.
	Conditions []NodeCondition `json:"conditions,omitempty"`

	// The agent has not applied the newest config that the controller holds for it
	// yet: it applies it at its next heartbeat, or it cannot reach the
	// controller's config.
	ConfigBehind bool `json:"config_behind,omitempty"`

	// The version of the controller's config of the agent that the agent applied.
	// Absent when it applied none.
	ConfigVersion int `json:"config_version,omitempty"`

	// The version of the config that the controller holds for the agent. Absent
	// when it holds none.
	ConfigWanted int `json:"config_wanted,omitempty"`

	// The fingerprint of the controller key that the agent verifies jobs with.
	ControllerKey string `json:"controller_key,omitempty"`

	// The fingerprint of the key that the controller switches to, which the agent
	// has: empty when no rotation of the controller's key is in progress, or the
	// agent has not taken it yet.
	ControllerKeyNext string `json:"controller_key_next,omitempty"`

	// Number of logical CPUs.
	CPUCount int `json:"cpu_count,omitempty"`

	// Extended facts from additional providers.
	Facts map[string]any `json:"facts,omitempty"`

	// The SHA256 fingerprint of the agent's PKI public key. Empty until the agent
	// loads its keys.
	Fingerprint string `json:"fingerprint,omitempty"`

	// Fully qualified domain name.
	FQDN string `json:"fqdn,omitempty"`

	// The hostname of the agent.
	Hostname string `json:"hostname"`

	// Interfaces is the property interfaces.
	Interfaces []NetworkInterfaceResponse `json:"interfaces,omitempty"`

	// OS kernel version.
	KernelVersion string `json:"kernel_version,omitempty"`

	// Whether the controller holds this agent's public key, recorded when its
	// enrollment was accepted. False for an agent that has not enrolled since the
	// key store existed, which is what to re-enrol before enabling enforcement.
	KeyStored bool `json:"key_stored,omitempty"`

	// Key-value labels configured on the agent.
	Labels map[string]string `json:"labels,omitempty"`

	// The system load averages for 1, 5, and 15 minutes.
	LoadAverage LoadAverageResponse `json:"load_average,omitzero"`

	// The permanent machine identifier.
	MachineID string `json:"machine_id,omitempty"`

	// Memory usage information.
	Memory MemoryResponse `json:"memory,omitzero"`

	// The programs that the agent's behaviors declare and that the host lacks. A
	// behavior fails until its program is installed.
	MissingPrograms []string `json:"missing_programs,omitempty"`

	// The fingerprint of the NATS server's next certificate, which the agent
	// trusts during a rotation of it.
	NATSCertNext string `json:"nats_cert_next,omitempty"`

	// Operating system information.
	OSInfo OSInfoResponse `json:"os_info,omitzero"`

	// Package manager.
	PackageMgr string `json:"package_mgr,omitempty"`

	// Name of the interface used for the default route.
	PrimaryInterface string `json:"primary_interface,omitempty"`

	// When the agent last refreshed its heartbeat.
	RegisteredAt time.Time `json:"registered_at,omitzero"`

	// Network routing table entries.
	Routes []RouteResponse `json:"routes,omitempty"`

	// Init system.
	ServiceMgr string `json:"service_mgr,omitempty"`

	// When the agent process started.
	StartedAt time.Time `json:"started_at,omitzero"`

	// The scheduling state of an agent: Ready, Draining, Cordoned or Pending. A
	// drain that the agent has not applied yet is Draining.
	State types.AgentState `json:"state"`

	// Agent state transition history.
	Timeline []TimelineEvent `json:"timeline,omitempty"`

	// The system uptime.
	Uptime string `json:"uptime,omitempty"`

	// Whether this agent's registration was signed by its stored key and claims
	// the hostname it enrolled under. Only a verified registration decides where
	// work is routed. True when the controller is not enforcing verification.
	Verified bool `json:"verified,omitempty"`

	// The build version of the agent binary. Absent for an agent that does not
	// report it.
	Version string `json:"version,omitempty"`
}

AgentInfo is the AgentInfo of the spec.

type AgentJoinInput added in v0.3.0

type AgentJoinInput struct {
	// The agent's public P-256 encryption key: base64url, with no padding, of the
	// 65-byte uncompressed point.
	EncryptionKey string `json:"encryption_key"`

	// The hostname of the host.
	Hostname string `json:"hostname"`

	// The machine ID of the host.
	MachineID string `json:"machine_id"`

	// The agent's Ed25519 signing key, in base64.
	PublicKey string `json:"public_key"`

	// The signature of the request by the signing key, in base64.
	Signature string `json:"signature"`

	// The join token, osapi_jt_<id>.<secret>, from osapi controller join token
	// create. A secret: a reference, secret://<vault>/<key>, or the value.
	Token string `json:"token"`
}

AgentJoinInput is the input of AgentService.Join. A field of the path goes in the path, and each other field in the body.

type AgentService

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

AgentService calls the API's Agent group: operations related to agent discovery and details.

func (*AgentService) Drain

func (s *AgentService) Drain(
	ctx context.Context,
	hostname string,
) error

Drain is the operation DrainAgent: drain an agent.

Stop the agent from accepting new jobs. In-flight jobs continue to completion.

It sends POST /api/agent/{hostname}/drain, and needs the permission agent:write.

func (*AgentService) Facts added in v0.3.0

Facts is the operation GetAgentFacts: list the fact keys.

Returns the fact keys that an input can refer to as @fact.<key>: the built-in keys and the custom keys that agents register.

It sends GET /api/agent/facts, and needs the permission agent:read.

func (*AgentService) Get

func (s *AgentService) Get(
	ctx context.Context,
	hostname string,
) (*Response[AgentInfo], error)

Get is the operation GetAgentDetails: get agent details.

Get detailed information about a specific agent by hostname.

It sends GET /api/agent/{hostname}, and needs the permission agent:read.

func (*AgentService) Getconfig added in v0.3.0

func (s *AgentService) Getconfig(
	ctx context.Context,
	hostname string,
) (*Response[AgentConfigResponse], error)

Getconfig is the operation GetAgentConfig: read the config of an agent.

Returns the config that the controller holds for the agent, with its version.

It sends GET /api/agent/config/{hostname}, and needs the permission agent:read.

func (*AgentService) Join added in v0.3.0

Join is the operation JoinAgent: join an agent with a join token.

An agent calls it one time, at its first start, over HTTPS, after it checks the controller's certificate against the fingerprint of its join string. A token that admits admits the machine at once, as admit does, and the admission record names the token. The request is signed with the agent's signing key, which shows that it holds the key that it asks the controller to admit. It needs no bearer token: the join token authorizes it.

It sends POST /api/agent/join.

func (*AgentService) List

List is the operation GetAgents: list active agents.

Discover all active agents in the fleet.

It sends GET /api/agent, and needs the permission agent:read.

func (*AgentService) Setconfig added in v0.3.0

func (s *AgentService) Setconfig(
	ctx context.Context,
	hostname string,
	input AgentSetconfigInput,
) (*Response[AgentConfigResponse], error)

Setconfig is the operation PutAgentConfig: set the config of an agent.

Sets the labels, the max jobs, the log level and the facts interval of the agent as the next version of its config. The agent applies them at once: it takes the jobs of the new labels, runs at most max jobs at the same time, logs at the level, collects its facts at the interval, and no restart is necessary.

It sends PUT /api/agent/config/{hostname}, and needs the permission agent:write.

func (*AgentService) Undrain

func (s *AgentService) Undrain(
	ctx context.Context,
	hostname string,
) error

Undrain is the operation UndrainAgent: undrain an agent.

Resume accepting jobs on a drained agent.

It sends POST /api/agent/{hostname}/undrain, and needs the permission agent:write.

type AgentSetconfigInput added in v0.3.0

type AgentSetconfigInput struct {
	// How often the agent collects its facts, as a Go duration such as 5m. Empty
	// keeps the interval of the agent's config file.
	FactsInterval string `json:"facts_interval,omitempty"`

	// The labels of the agent, as key=value. They replace the labels of the
	// agent's config file with the same keys. Empty removes each.
	Labels map[string]string `json:"labels,omitempty"`

	// LogLevel is the level that a process logs at, one of its Values.
	LogLevel types.LogLevel `json:"log_level,omitzero"`

	// The most jobs that the agent runs at the same time. It replaces max_jobs of
	// the agent's config file; empty keeps the file's.
	MaxJobs int `json:"max_jobs,omitempty"`
}

AgentSetconfigInput is the input of AgentService.Setconfig. A field of the path goes in the path, and each other field in the body.

type AgentStats

type AgentStats struct {
	// Per-agent registration details.
	Agents []AgentDetail `json:"agents,omitempty"`

	// Number of agents with Ready status.
	Ready int `json:"ready"`

	// Total number of registered agents.
	Total int `json:"total"`
}

AgentStats is the AgentStats of the spec.

type AuditEntry

type AuditEntry struct {
	// What a change that did not go through the API did, such as agent.admit or
	// jointoken.create.
	Action string `json:"action,omitempty"`

	// The kind of who made a change that did not go through the API: system,
	// join-token, agent or local. Absent for a request through the API.
	Actor string `json:"actor,omitempty"`

	// The steps on one line for each host, such as web-01: managedfile update
	// (changed).
	Chain []string `json:"chain,omitempty"`

	// Request duration in milliseconds.
	DurationMS int64 `json:"duration_ms"`

	// Unique identifier for the audit entry.
	ID string `json:"id"`

	// The job this request created, absent when it created none. Joins the entry
	// to that job's own status timeline.
	JobID string `json:"job_id,omitempty"`

	// HTTP method.
	Method string `json:"method"`

	// OpenAPI operation ID.
	OperationID string `json:"operation_id,omitempty"`

	// Request URL path.
	Path string `json:"path"`

	// What the request asked for, with sensitive values replaced. Recorded for
	// methods that change something.
	RequestSummary string `json:"request_summary,omitempty"`

	// HTTP response status code.
	ResponseCode int `json:"response_code"`

	// Roles from the JWT token.
	Roles []string `json:"roles"`

	// Client IP address.
	SourceIP string `json:"source_ip"`

	// The calls of other behaviors that the method of the job made, for each host
	// that answered before the request returned, also when one failed. Absent when
	// no host made a call.
	Steps []AuditEntryStepsItem `json:"steps,omitempty"`

	// What the action was on, such as a machine ID or a join token's ID.
	Target string `json:"target,omitempty"`

	// The target scope of the JWT token, absent when the token acts on each host.
	Targets []string `json:"targets,omitempty"`

	// When the request was processed.
	Timestamp time.Time `json:"timestamp"`

	// OpenTelemetry trace ID for correlation.
	TraceID string `json:"trace_id,omitempty"`

	// Who did it: the authenticated user (JWT subject), or the name of another
	// actor.
	User string `json:"user"`
}

AuditEntry is the AuditEntry of the spec.

type AuditEntryResponse added in v0.3.0

type AuditEntryResponse struct {
	// Entry is the property entry.
	Entry AuditEntry `json:"entry"`
}

AuditEntryResponse is the AuditEntryResponse of the spec.

type AuditEntryStepsItem added in v0.3.0

type AuditEntryStepsItem struct {
	// The host that answered the job.
	Hostname string `json:"hostname"`

	// The calls, in the order that the method made them.
	Steps []types.Step `json:"steps"`
}

AuditEntryStepsItem is the AuditEntryStepsItem of the spec.

type AuditListParams added in v0.3.0

type AuditListParams struct {
	// Limit is the limit of the query: maximum number of entries to return. The
	// zero value leaves it out.
	Limit int

	// Offset is the offset of the query: number of entries to skip. The zero value
	// leaves it out.
	Offset int

	// Writes is the writes of the query: only the requests that change something:
	// each method but GET. The zero value leaves it out.
	Writes bool

	// User is the user of the query: only the entries of this user, the subject of
	// the token. The zero value leaves it out.
	User string

	// Operation is the operation of the query: only the entries whose operation ID
	// or path has this text, such as hostname. The zero value leaves it out.
	Operation string

	// Status is the status of the query: only the entries with this response
	// status, such as 403. The zero value leaves it out.
	Status int
}

AuditListParams are the parameters of AuditService.List that a request can leave out.

type AuditService

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

AuditService calls the API's Audit group: audit log endpoints for viewing API activity.

func (*AuditService) Export

Export is the operation GetAuditExport: export all audit log entries.

Returns all audit log entries without pagination for export. A token with a target scope gets only the entries of requests to a target in its scope.

It sends GET /api/audit/export, and needs the permission audit:read.

func (*AuditService) Get

Get is the operation GetAuditLogByID: get a single audit log entry.

Returns a single audit log entry by ID. An entry of a request to a target outside the target scope of the token is not found.

It sends GET /api/audit/{id}, and needs the permission audit:read.

func (*AuditService) List

List is the operation GetAuditLogs: list audit log entries.

Returns a paginated list of audit log entries, newest first. A token with a target scope gets only the entries of requests to a target in its scope, and the total includes only those entries.

It sends GET /api/audit, and needs the permission audit:read.

type AuthError

type AuthError struct {
	APIError
}

AuthError represents authentication/authorization errors (401, 403).

func (*AuthError) Unwrap

func (e *AuthError) Unwrap() error

Unwrap returns the underlying APIError.

type Averages added in v0.3.0

type Averages struct {
	// The load average over 15 minutes.
	Min15 float64 `json:"15min"`

	// The load average over 1 minute.
	Min1 float64 `json:"1min"`

	// The load average over 5 minutes.
	Min5 float64 `json:"5min"`
}

Averages is the Averages of the spec.

type CatalogArea added in v0.3.0

type CatalogArea struct {
	// The label of the area.
	Label string `json:"label"`

	// The name of the area.
	Name string `json:"name"`
}

CatalogArea is the CatalogArea of the spec.

type CatalogBehavior added in v0.3.0

type CatalogBehavior struct {
	// The area of the behavior, or empty for an internal behavior.
	Area string `json:"area"`

	// The chain of the behavior, as osapi dsl chain list prints it.
	Chain string `json:"chain"`

	// What the behavior manages.
	Doc string `json:"doc"`

	// Only other behaviors call it: it has no route.
	Internal bool `json:"internal"`

	// The methods of the behavior.
	Methods []CatalogMethod `json:"methods"`

	// The name of the behavior.
	Name string `json:"name"`

	// The behavior that the behavior is under, such as user for sshkey.
	Parent string `json:"parent,omitempty"`

	// The platforms of the providers of the behavior.
	Platforms []string `json:"platforms"`

	// The title of the behavior.
	Title string `json:"title"`

	// The behaviors that call the behavior.
	UsedBy []string `json:"used_by"`

	// The behaviors that the behavior calls.
	Uses []string `json:"uses"`
}

CatalogBehavior is the CatalogBehavior of the spec.

type CatalogCall added in v0.3.0

type CatalogCall struct {
	// The behavior that is called.
	Behavior string `json:"behavior"`

	// The calls that the call makes.
	Calls []CatalogCall `json:"calls,omitempty"`

	// The method that is called.
	Method string `json:"method"`
}

CatalogCall is the CatalogCall of the spec.

type CatalogColumn added in v0.3.0

type CatalogColumn struct {
	// The columns of an object, or of a list of objects.
	Columns []CatalogColumn `json:"columns,omitempty"`

	// What the field is.
	Doc string `json:"doc"`

	// ColumnKind is what a field of an answer holds.
	Kind types.ColumnKind `json:"kind"`

	// The label of the field.
	Label string `json:"label"`

	// The json name of the field.
	Name string `json:"name"`

	// The render tag of the field, such as bytes.
	Render string `json:"render,omitempty"`
}

CatalogColumn is the CatalogColumn of the spec.

type CatalogControllerMethod added in v0.3.0

type CatalogControllerMethod struct {
	// What the method does, in one line.
	Doc string `json:"doc"`

	// The endpoint group.
	Group string `json:"group"`

	// The method.
	Method string `json:"method"`

	// An operationId of an operation that needs a permission.
	Operation OperationID `json:"operation"`

	// A permission that osapi knows, as resource:verb.
	Permission types.Permission `json:"permission"`
}

CatalogControllerMethod is the CatalogControllerMethod of the spec.

type CatalogExample added in v0.3.0

type CatalogExample struct {
	// What the example does.
	Doc string `json:"doc"`

	// The input of the example.
	Input any `json:"input"`

	// The output of the example.
	Output any `json:"output,omitempty"`
}

CatalogExample is the CatalogExample of the spec.

type CatalogField added in v0.3.0

type CatalogField struct {
	// What the field is.
	Doc string `json:"doc"`

	// FieldIn is where a field of a request goes.
	In types.FieldIn `json:"in"`

	// FieldKind is how a form takes the value of a field.
	Kind types.FieldKind `json:"kind"`

	// The json name of the field.
	Name string `json:"name"`

	// The values that the field takes: those of its type with enum, or of its
	// oneof rule.
	Options []string `json:"options,omitempty"`

	// The request needs the field.
	Required bool `json:"required"`

	// The field is a secret.
	Secret bool `json:"secret,omitempty"`
}

CatalogField is the CatalogField of the spec.

type CatalogMethod added in v0.3.0

type CatalogMethod struct {
	// The calls that the examples of the method make to other behaviors.
	Calls []CatalogCall `json:"calls"`

	// The fields of the rows that the method answers, as the CLI's output reads
	// them.
	Columns []CatalogColumn `json:"columns"`

	// What the method interrupts.
	Disruption string `json:"disruption,omitempty"`

	// The method can interrupt a host, such as a reboot.
	Disruptive bool `json:"disruptive,omitempty"`

	// What the method does.
	Doc string `json:"doc"`

	// The examples of the method.
	Examples []CatalogExample `json:"examples"`

	// The fields of the input.
	Fields []CatalogField `json:"fields"`

	// The HTTP method of the route. An internal behavior has no route.
	HttpMethod string `json:"http_method,omitempty"`

	// The input type and its fields, a required one marked *.
	Input string `json:"input"`

	// What a method does to a host, by the verb of its permission: read, write or
	// action.
	Kind types.MethodKind `json:"kind"`

	// The rest of what the method does.
	Long string `json:"long,omitempty"`

	// The name of the method.
	Name string `json:"name"`

	// The output type and its fields.
	Output string `json:"output"`

	// The path of the route.
	Path string `json:"path,omitempty"`

	// A permission that osapi knows, as resource:verb.
	Permission types.Permission `json:"permission,omitzero"`

	// The platforms that the method runs on: those that its On limits it to, else
	// each platform of the behavior.
	Platforms []string `json:"platforms"`

	// The host platforms that the method runs on, as the agent decides, and * for
	// a Linux host whose platform gohai has no family for.
	RunsOn []string `json:"runs_on"`
}

CatalogMethod is the CatalogMethod of the spec.

type CatalogOperation added in v0.3.0

type CatalogOperation struct {
	// An operationId of an operation that needs a permission.
	ID OperationID `json:"id"`

	// A permission that osapi knows, as resource:verb.
	Permission types.Permission `json:"permission"`
}

CatalogOperation is the CatalogOperation of the spec.

type CatalogResponse added in v0.3.0

type CatalogResponse struct {
	// Each area, in order, with its label.
	Areas []CatalogArea `json:"areas"`

	// Each behavior that the API serves, and each internal behavior, in the order
	// of the registry.
	Behaviors []CatalogBehavior `json:"behaviors"`

	// Each method of an endpoint group of the Object Store area: a call of the
	// controller that takes no target.
	Controller []CatalogControllerMethod `json:"controller"`

	// The tone of a count above zero, by what it counts: ok, warn or err.
	CountTones map[string]string `json:"count_tones"`

	// The host platforms that gohai names. A method's runs_on has * for any other
	// Linux.
	HostFamilies []string `json:"host_families"`

	// The permission of each operation that needs one, in the order of the
	// operationIds.
	Operations []CatalogOperation `json:"operations"`

	// The outcomes of a host, from the best to the worst, as the CLI's summary
	// orders them.
	Outcomes []string `json:"outcomes"`

	// Each permission that osapi knows.
	Permissions []types.Permission `json:"permissions"`

	// The render tags of an output field, as the CLI reads them. short= takes a
	// number, such as short=12.
	RenderTags []string `json:"render_tags"`

	// The built-in roles, in order, with the permissions of each.
	Roles []CatalogRole `json:"roles"`

	// The tone of each status word, as the CLI colors it: ok, warn or err.
	StatusTones map[string]string `json:"status_tones"`

	// The targets that name no host: each agent, or any one agent.
	Targets []CatalogTarget `json:"targets"`
}

CatalogResponse is the CatalogResponse of the spec.

type CatalogRole added in v0.3.0

type CatalogRole struct {
	// Who the role is for.
	Description string `json:"description"`

	// The name of the role, as a token names it.
	Name string `json:"name"`

	// The permissions of the role.
	Permissions []types.Permission `json:"permissions"`
}

CatalogRole is the CatalogRole of the spec.

type CatalogService added in v0.3.0

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

CatalogService calls the API's Catalog group: the behaviors, the permissions and the roles that the controller serves, for the UI.

func (*CatalogService) Get added in v0.3.0

Get is the operation GetCatalog: get the catalog.

Returns each behavior with its methods, the areas, the permissions, the built-in roles, the permission of each operation, the tones of the statuses and the counts, and the host families. The UI reads it after sign-in. Each built-in role has catalog:read.

It sends GET /api/catalog, and needs the permission catalog:read.

type CatalogTarget added in v0.3.0

type CatalogTarget struct {
	// What it sends the job to.
	Doc string `json:"doc"`

	// Its label.
	Label string `json:"label"`

	// The target, as a method takes it.
	Value string `json:"value"`
}

CatalogTarget is the CatalogTarget of the spec.

type CertificateCreateInput added in v0.3.0

type CertificateCreateInput struct {
	// The name of the CA, such as internal-ca, which osapi writes as
	// osapi-internal-ca.crt.
	Name string `json:"name"`

	// The object of the Object Store that has the PEM of the CA, as osapi client
	// file upload stored it.
	Object string `json:"object"`
}

CertificateCreateInput is the input of CertificateService.Create. A field of the path goes in the path, and each other field in the body.

type CertificateEntry added in v0.3.0

type CertificateEntry struct {
	// Whether the host trusts it: false for a system CA that the trust store turns
	// off.
	Enabled bool `json:"enabled,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// The SHA-256 of the certificate, in hex.
	Fingerprint string `json:"fingerprint,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Whether osapi deployed it, and its writes change it.
	Managed bool `json:"managed,omitempty"`

	// The CA: the name it was deployed with for a CA that osapi deployed, else its
	// file's name.
	Name string `json:"name,omitempty"`

	// When it expires.
	NotAfter string `json:"not_after,omitempty"`

	// The object that osapi deployed it from.
	Object string `json:"object,omitempty"`

	// The file, or on macOS the keychain, that has it.
	Path string `json:"path,omitempty"`

	// system for a CA of the distribution, local for one an administrator added.
	Source string `json:"source,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// Its subject, such as CN=ISRG Root X1,O=Internet Security Research
	// Group,C=US.
	Subject string `json:"subject,omitempty"`
}

CertificateEntry is the CertificateEntry of the spec.

type CertificateResult added in v0.3.0

type CertificateResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The CA.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

CertificateResult is the CertificateResult of the spec.

type CertificateService

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

CertificateService calls the API's Certificate group: the certificate authorities that the host trusts.

func (*CertificateService) Create

Create is the operation PostNodeCertificate: add a certificate authority to the trust store.

Writes the PEM of the object as a file with the osapi- prefix, such as osapi-internal-ca.crt for internal-ca, in the family's local directory: /usr/local/share/ca-certificates on the Debian family, /etc/pki/trust/anchors on SUSE, /etc/pki/ca-trust/source/anchors on RHEL and Fedora. Then it rebuilds the trust store: with update-ca-certificates on the Debian family and SUSE, and with update-ca-trust on the others. Alpine reports skipped. A CA that osapi deployed already with the same content does not change and reports changed: false. A file of that name that osapi did not write is refused. macOS reports skipped.

It sends POST /api/node/{hostname}/certificate, and needs the permission certificate:write.

func (*CertificateService) Delete

func (s *CertificateService) Delete(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[CertificateResult]], error)

Delete is the operation DeleteNodeCertificate: remove a certificate authority that osapi deployed.

Removes the file of the CA and rebuilds the trust store: with update-ca-certificates --fresh on the Debian family and SUSE, which removes the links of the CA from /etc/ssl/certs, and update-ca-trust on the RHEL family. A CA that osapi did not deploy does not change and reports changed: false: a system CA is not osapi's to remove. macOS reports skipped.

It sends DELETE /api/node/{hostname}/certificate/{name}, and needs the permission certificate:write.

func (*CertificateService) Get added in v0.3.0

Get is the operation GetNodeCertificateByKey: get one certificate authority.

Reads one CA from the same list, by the name that list gives it. A CA that the host does not trust is not found. A name with a slash, such as a system CA of the Debian family, is in list only.

It sends GET /api/node/{hostname}/certificate/{name}, and needs the permission certificate:read.

func (*CertificateService) List

List is the operation GetNodeCertificate: list the certificate authorities that the host trusts.

Lists each CA of the trust store through gohai: the distribution's and the local ones on Linux, from the family's directories, and the system keychains on macOS, each with its subject, fingerprint and expiry. A CA that osapi deployed reads by the name that it was deployed with, not its file's osapi- name, and is managed.

It sends GET /api/node/{hostname}/certificate, and needs the permission certificate:read.

func (*CertificateService) Update

Update is the operation PutNodeCertificate: write a certificate authority that osapi deployed again.

Writes the CA from the object, or from the one that it was deployed from when the object is empty, and rebuilds the trust store when the file changed. A CA that osapi did not deploy is not found. macOS reports skipped.

It sends PUT /api/node/{hostname}/certificate/{name}, and needs the permission certificate:write.

type CertificateUpdateInput added in v0.3.0

type CertificateUpdateInput struct {
	// The name of the path: the CA that osapi deployed, such as internal-ca.
	Name string `json:"-"`

	// The object that has the PEM; the one it was deployed from when empty.
	Object string `json:"object,omitempty"`
}

CertificateUpdateInput is the input of CertificateService.Update. A field of the path goes in the path, and each other field in the body.

type Check added in v0.3.0

type Check struct {
	// Why the check failed. Absent when it is ok.
	Error string `json:"error,omitempty"`

	// What was checked, such as nats.
	Name string `json:"name"`

	// ok, or error.
	Status string `json:"status"`
}

Check is the Check of the spec.

type Client

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

Client is the top-level OSAPI SDK client. Use New() to create one. Each typed service is a field of the embedded services, such as c.DNS.

func New

func New(
	baseURL string,
	bearerToken string,
	opts ...Option,
) *Client

New creates an OSAPI SDK client.

func (*Client) Request added in v0.3.0

func (c *Client) Request(
	ctx context.Context,
	method string,
	path string,
	body []byte,
) (*Response[json.RawMessage], error)

Request sends one request to an API path, such as /api/node/web-01/sysctl/vm.swappiness, with body as its JSON body when body is not nil, and returns the response body. It is for a route the SDK has no typed method for. An answer outside 2xx is returned as the SDK's error types, as every typed method returns it.

func (*Client) Send added in v0.3.0

func (c *Client) Send(
	ctx context.Context,
	method string,
	path string,
	contentType string,
	body []byte,
) (*Response[json.RawMessage], error)

Send is Request with the content type of the body, such as the multipart/form-data of an upload.

type Collection

type Collection[T any] struct {
	Results []T    `json:"results"`
	JobID   string `json:"job_id"`
}

Collection is a generic wrapper for collection responses from node queries.

func (Collection[T]) First

func (c Collection[T]) First() (T, bool)

First returns the first result and true, or the zero value and false if the collection is empty.

type CommandExecInput added in v0.3.0

type CommandExecInput struct {
	// Its arguments, each one word, such as -la /tmp.
	Args []string `json:"args,omitempty"`

	// The program, a name on the agent's PATH or a path, such as ls.
	Command string `json:"command"`

	// The directory to run it in; the agent's own when empty.
	Cwd string `json:"cwd,omitempty"`

	// Seconds to let it run before it is stopped, up to 300; 30 when 0.
	Timeout int `json:"timeout,omitempty"`
}

CommandExecInput is the input of CommandService.Exec. A field of the path goes in the path, and each other field in the body.

type CommandResult

type CommandResult struct {
	// Whether the host changed: true, since a command can change anything.
	Changed bool `json:"changed,omitempty"`

	// How long it ran, in milliseconds.
	DurationMS int64 `json:"duration_ms,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Its exit code.
	ExitCode int `json:"exit_code,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// What it wrote to standard error.
	Stderr string `json:"stderr,omitempty"`

	// What it wrote to standard output.
	Stdout string `json:"stdout,omitempty"`
}

CommandResult is the CommandResult of the spec.

type CommandService

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

CommandService calls the API's Command group: run a command on target hosts.

func (*CommandService) Exec

Exec is the operation PostNodeCommandExec: run a program with its arguments.

Runs the program with its arguments, each one word, with no shell between them: a ; or a | in an argument is that character. It answers with standard output and standard error apart, the exit code and the duration. A program that exits non-zero is a result, not an error. Only the admin role may run it, and the agent runs it only where agent.command.enabled is true.

It sends POST /api/node/{hostname}/command/exec, and needs the permission command:execute.

func (*CommandService) Shell

Shell is the operation PostNodeCommandShell: run a command line through /bin/sh -c.

Runs the command line through /bin/sh -c, so pipes, redirects and variables work. It answers as exec does. Its permission is command:shell, apart from exec's command:execute: a token that may run a program may not open a shell. Only the admin role gets it.

It sends POST /api/node/{hostname}/command/shell, and needs the permission command:shell.

type CommandShellInput added in v0.3.0

type CommandShellInput struct {
	// The command line, which /bin/sh -c reads, such as ls -la /tmp | grep log.
	Command string `json:"command"`

	// The directory to run it in; the agent's own when empty.
	Cwd string `json:"cwd,omitempty"`

	// Seconds to let it run before it is stopped, up to 300; 30 when 0.
	Timeout int `json:"timeout,omitempty"`
}

CommandShellInput is the input of CommandService.Shell. A field of the path goes in the path, and each other field in the body.

type ComponentEntry added in v0.3.0

type ComponentEntry struct {
	// Listen address of a sub-component, such as :8080.
	Address string `json:"address,omitempty"`

	// Time since component started.
	Age string `json:"age,omitempty"`

	// The sub-components of the component, such as its api and its metrics server,
	// sorted by name.
	Components []ComponentEntry `json:"components,omitempty"`

	// Active conditions.
	Conditions []types.ConditionType `json:"conditions,omitempty"`

	// Process CPU usage percentage.
	CPUPercent float64 `json:"cpu_percent,omitempty"`

	// Component hostname.
	Hostname string `json:"hostname,omitempty"`

	// Process RSS memory in bytes.
	MemBytes int64 `json:"mem_bytes,omitempty"`

	// Component status.
	Status string `json:"status,omitempty"`

	// Component type (agent, controller, nats), or the name of a sub-component,
	// such as api.
	Type string `json:"type,omitempty"`

	// Where a person opens a sub-component, from its url config key.
	URL string `json:"url,omitempty"`

	// Build version of the component's binary.
	Version string `json:"version,omitempty"`
}

ComponentEntry is the ComponentEntry of the spec.

type ConflictError

type ConflictError struct {
	APIError
}

ConflictError represents conflict errors (409).

func (*ConflictError) Unwrap

func (e *ConflictError) Unwrap() error

Unwrap returns the underlying APIError.

type ConnectivityPingInput added in v0.3.0

type ConnectivityPingInput struct {
	// The IPv4 or IPv6 address to ping, or an @fact. reference that the agent
	// resolves.
	Address string `json:"address"`
}

ConnectivityPingInput is the input of ConnectivityService.Ping. A field of the path goes in the path, and each other field in the body.

type ConnectivityPingResult added in v0.3.0

type ConnectivityPingResult struct {
	// Average round-trip time in milliseconds, with two decimals. Absent when no
	// reply came back.
	AvgRTT string `json:"avg_rtt,omitempty"`

	// Always false: a ping changes nothing on the host.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Maximum round-trip time in milliseconds, with two decimals. Absent when no
	// reply came back.
	MaxRTT string `json:"max_rtt,omitempty"`

	// Minimum round-trip time in milliseconds, with two decimals. Absent when no
	// reply came back.
	MinRTT string `json:"min_rtt,omitempty"`

	// Percentage of packet loss.
	PacketLoss float64 `json:"packet_loss,omitempty"`

	// Number of packets received.
	PacketsReceived int `json:"packets_received,omitempty"`

	// Number of packets sent.
	PacketsSent int `json:"packets_sent,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

ConnectivityPingResult is the ConnectivityPingResult of the spec.

type ConnectivityService added in v0.3.0

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

ConnectivityService calls the API's Connectivity group: whether the host reaches an address, by ICMP ping.

func (*ConnectivityService) Ping added in v0.3.0

Ping is the operation PostNodeConnectivityPing: ping an address from the host.

Sends three ICMP echo requests from the host and reports how many came back, and their round-trip times. A host that does not answer is 100% loss, not an error. It changes nothing, so it reports changed: false. On Linux the agent pings without root when net.ipv4.ping_group_range admits its group.

It sends POST /api/node/{hostname}/connectivity/ping, and needs the permission connectivity:execute.

type CreateJobResponse added in v0.3.0

type CreateJobResponse struct {
	// Unique identifier for the created job.
	JobID string `json:"job_id"`

	// The KV revision number.
	Revision int64 `json:"revision,omitempty"`

	// The status of a job, which the controller computes from what each agent did:
	// submitted, processing, completed, failed, partial_failure (completed on some
	// agents and failed on others) or skipped (each agent skipped it).
	Status types.JobStatus `json:"status"`

	// Creation timestamp.
	Timestamp string `json:"timestamp,omitempty"`
}

CreateJobResponse is the CreateJobResponse of the spec.

type DNSService

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

DNSService calls the API's DNS group: the DNS resolvers of each interface of the host.

func (*DNSService) Delete

func (s *DNSService) Delete(
	ctx context.Context,
	hostname string,
	interfaceName string,
) (*Response[Collection[DnsResult]], error)

Delete is the operation DeleteNodeDns: drop the DNS resolvers osapi set on an interface.

Removes the interface's netplan file and applies what is left. An interface osapi set nothing on does not change.

It sends DELETE /api/node/{hostname}/dns/{interface_name}, and needs the permission dns:write.

func (*DNSService) Get

func (s *DNSService) Get(
	ctx context.Context,
	hostname string,
	interfaceName string,
) (*Response[Collection[DnsEntry]], error)

Get is the operation GetNodeDnsByKey: get the DNS resolvers of an interface.

Reads the servers and the search domains of the interface: resolvectl on Linux, with resolv.conf on a host that has no resolvers per interface, such as a container, and scutil on macOS.

It sends GET /api/node/{hostname}/dns/{interface_name}, and needs the permission dns:read.

func (*DNSService) Update

func (s *DNSService) Update(
	ctx context.Context,
	hostname string,
	input DNSUpdateInput,
) (*Response[Collection[DnsResult]], error)

Update is the operation PutNodeDns: set the DNS resolvers of an interface.

Writes a netplan file of the interface's own, such as /etc/netplan/osapi-dns-eth0.yaml for eth0, under the netplan definition that matches the interface, and applies it. A definition that matches several interfaces, such as cloud-init's all for en*, gives each of them the resolvers. An empty list keeps the interface's servers or domains, and an interface with no resolvers yet starts from none. override_dhcp drops the servers DHCP gives. It runs on the Debian family, and elsewhere, and in a container, reports skipped.

It sends PUT /api/node/{hostname}/dns/{interface_name}, and needs the permission dns:write.

type DNSUpdateInput added in v0.3.0

type DNSUpdateInput struct {
	// The interface_name of the path: the interface, such as eth0, or a fact such
	// as @fact.interface.primary.
	InterfaceName string `json:"-"`

	// Use only these servers: drop the ones DHCP gives.
	OverrideDHCP bool `json:"override_dhcp,omitempty"`

	// The search domains; the interface's own when empty.
	SearchDomains []string `json:"search_domains,omitempty"`

	// The DNS servers, IPv4 or IPv6; the interface's own when empty.
	Servers []string `json:"servers,omitempty"`
}

DNSUpdateInput is the input of DNSService.Update. A field of the path goes in the path, and each other field in the body.

type DeadLetter added in v0.3.0

type DeadLetter struct {
	// The consumer of the agents that the delivery was for.
	Consumer string `json:"consumer"`

	// How often NATS delivered the job before it gave up.
	Deliveries int `json:"deliveries"`

	// The error of the job, when it has one.
	Error string `json:"error,omitempty"`

	// The job that the delivery carried, or empty when the job stream no longer
	// has it.
	JobID string `json:"job_id,omitempty"`

	// What the job asked for, with each secret masked.
	Operation DeadLetterOperation `json:"operation,omitzero"`

	// The dead letter's sequence in the dead letter stream.
	Seq int `json:"seq"`

	// The target of the job.
	Target string `json:"target,omitempty"`

	// When NATS gave up on the delivery.
	Time time.Time `json:"time"`
}

DeadLetter is the DeadLetter of the spec.

type DeadLetterList added in v0.3.0

type DeadLetterList struct {
	// Items is the property items.
	Items []DeadLetter `json:"items"`

	// The number of dead letters that the stream holds.
	TotalItems int `json:"total_items"`
}

DeadLetterList is the DeadLetterList of the spec.

type DeadLetterOperation added in v0.3.0

type DeadLetterOperation struct {
	// The data of the operation, with each secret masked.
	Data any `json:"data,omitempty"`

	// The operation, such as node.hostname.get.
	Type string `json:"type"`
}

DeadLetterOperation: What the job asked for, with each secret masked.

type Disk

type Disk struct {
	// The bytes free to use.
	Free int `json:"free"`

	// Where the filesystem is mounted.
	Name string `json:"name"`

	// The size of the filesystem in bytes.
	Total int `json:"total"`

	// The bytes in use.
	Used int `json:"used"`
}

Disk is the Disk of the spec.

type DiskEntry added in v0.3.0

type DiskEntry struct {
	// Each local filesystem.
	Disks []Disk `json:"disks,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

DiskEntry is the DiskEntry of the spec.

type DiskService

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

DiskService calls the API's Disk group: get the disk usage of target hosts.

func (*DiskService) Get

func (s *DiskService) Get(
	ctx context.Context,
	hostname string,
) (*Response[Collection[DiskEntry]], error)

Get is the operation GetNodeDisk: get the disk usage of the host.

Reads the size, the used space and the free space of each local filesystem, in bytes: the mounts of /proc/mounts on Linux and of mount on macOS, with their sizes from df. Local is ext4, xfs and btrfs on Linux, and apfs and hfs on macOS. Network and special filesystems are left out.

It sends GET /api/node/{hostname}/disk, and needs the permission disk:read.

type DnsEntry added in v0.3.0

type DnsEntry struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The search domains.
	SearchDomains []string `json:"search_domains,omitempty"`

	// The DNS servers.
	Servers []string `json:"servers,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

DnsEntry is the DnsEntry of the spec.

type DnsResult added in v0.3.0

type DnsResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The interface.
	InterfaceName string `json:"interface_name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

DnsResult is the DnsResult of the spec.

type DockerCreateInput added in v0.3.0

type DockerCreateInput struct {
	// Start the container once it is created.
	AutoStart bool `json:"auto_start,omitempty"`

	// The command, in place of the image's own.
	Command []string `json:"command,omitempty"`

	// The hostname inside the container.
	ContainerHostname string `json:"container_hostname,omitempty"`

	// The DNS servers of the container.
	DNS []string `json:"dns,omitempty"`

	// The environment variables of the container. A secret: a reference,
	// secret://<vault>/<key>, or the value.
	Env map[string]string `json:"env,omitempty"`

	// The image to run, such as alpine:3.20; docker pulls it when the host does
	// not have it.
	Image string `json:"image"`

	// The container's name.
	Name string `json:"name"`

	// The published ports, each host:container, such as 8080:80.
	Ports []string `json:"ports,omitempty"`

	// The bind mounts, each host:container, such as /srv/data:/data.
	Volumes []string `json:"volumes,omitempty"`
}

DockerCreateInput is the input of DockerService.Create. A field of the path goes in the path, and each other field in the body.

type DockerEntry added in v0.3.0

type DockerEntry struct {
	// When it was created, RFC 3339.
	Created string `json:"created,omitempty"`

	// The names of its environment variables; osapi never reads their values.
	EnvNames []string `json:"env_names,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// The state of its health check: healthy, unhealthy or starting; empty without
	// one.
	Health string `json:"health,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The container's full ID.
	ID string `json:"id,omitempty"`

	// The image it runs.
	Image string `json:"image,omitempty"`

	// The mounts, source:destination, with :ro when read only.
	Mounts []string `json:"mounts,omitempty"`

	// The container's name.
	Name string `json:"name,omitempty"`

	// The networks, with the container's address and gateway on each.
	Networks []string `json:"networks,omitempty"`

	// The published ports, host:port->container port.
	Ports []string `json:"ports,omitempty"`

	// running, exited, created, paused or restarting.
	State string `json:"state,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// What docker says of its state, such as Up 2 minutes.
	Summary string `json:"summary,omitempty"`
}

DockerEntry is the DockerEntry of the spec.

type DockerExecInput added in v0.3.0

type DockerExecInput struct {
	// The name of the path: the container's name or ID.
	Name string `json:"-"`

	// The command and its arguments.
	Command []string `json:"command"`

	// Environment variables for the command. A secret: a reference,
	// secret://<vault>/<key>, or the value.
	Env map[string]string `json:"env,omitempty"`

	// The directory the command runs in.
	WorkingDir string `json:"working_dir,omitempty"`
}

DockerExecInput is the input of DockerService.Exec. A field of the path goes in the path, and each other field in the body.

type DockerExecResult

type DockerExecResult struct {
	// Always true: osapi cannot tell what the command changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// The command's exit code.
	ExitCode int `json:"exit_code,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// What the command wrote to standard error.
	Stderr string `json:"stderr,omitempty"`

	// What the command wrote to standard output.
	Stdout string `json:"stdout,omitempty"`
}

DockerExecResult is the DockerExecResult of the spec.

type DockerListParams

type DockerListParams struct {
	// State is the state of the query: only the containers in this state: running,
	// stopped or all, the default. The zero value leaves it out.
	State types.ContainerState
}

DockerListParams are the parameters of DockerService.List that a request can leave out.

type DockerResult

type DockerResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The container's full ID, for create.
	ID string `json:"id,omitempty"`

	// The container.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

DockerResult is the DockerResult of the spec.

type DockerService

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

DockerService calls the API's Docker group: the Docker containers of the host.

func (*DockerService) Create

func (s *DockerService) Create(
	ctx context.Context,
	hostname string,
	input DockerCreateInput,
) (*Response[Collection[DockerResult]], error)

Create is the operation PostNodeDocker: create a container.

Runs docker create, which pulls the image when the host does not have it. The environment goes on docker's standard input, not in its arguments, which each user of the host can read. auto_start starts the container once it is made. A container of the name that the host has already is not made again, and reports changed: false.

It sends POST /api/node/{hostname}/docker, and needs the permission docker:write.

func (*DockerService) Delete added in v0.3.0

func (s *DockerService) Delete(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[DockerResult]], error)

Delete is the operation DeleteNodeDocker: remove a container.

Runs docker rm -f, which also removes a container that runs: a delete leaves no container of the name. A container that the host does not have reports changed: false.

It sends DELETE /api/node/{hostname}/docker/{name}, and needs the permission docker:write.

func (*DockerService) Exec

Exec is the operation PostNodeDockerExec: run a command in a container.

Runs docker exec, and answers what the command wrote to standard output and to standard error, and its exit code. A command that exits with a code other than 0 is an answer, not a failure. It changes what the command changes, which osapi cannot tell, so it reports changed: true. Its permission is docker:exec, which only the admin role gets, apart from the docker:execute of start and stop. An agent with agent.command.enabled false refuses it, as it refuses a command.

It sends POST /api/node/{hostname}/docker/{name}/exec, and needs the permission docker:exec.

func (*DockerService) Get added in v0.3.0

func (s *DockerService) Get(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[DockerEntry]], error)

Get is the operation GetNodeDockerByKey: get one container.

Reads one container by its name, its ID or the start of its ID. A container that the host does not have is not found.

It sends GET /api/node/{hostname}/docker/{name}, and needs the permission docker:read.

func (*DockerService) List

func (s *DockerService) List(
	ctx context.Context,
	hostname string,
	params DockerListParams,
) (*Response[Collection[DockerEntry]], error)

List is the operation GetNodeDocker: list the containers of the host.

Reads each container through gohai's docker collector, which runs docker ps and docker inspect. state limits the list to the running or the stopped ones. A host whose docker does not answer reports skipped. The environment of a container shows only the names of its variables: osapi never reads their values.

It sends GET /api/node/{hostname}/docker, and needs the permission docker:read.

func (*DockerService) Start

func (s *DockerService) Start(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[DockerResult]], error)

Start is the operation PostNodeDockerStart: start a container.

Runs docker start. A container that runs already reports changed: false, and one that the host does not have is not found.

It sends POST /api/node/{hostname}/docker/{name}/start, and needs the permission docker:execute.

func (*DockerService) Stop

func (s *DockerService) Stop(
	ctx context.Context,
	hostname string,
	input DockerStopInput,
) (*Response[Collection[DockerResult]], error)

Stop is the operation PostNodeDockerStop: stop a container.

Runs docker stop, which waits timeout seconds before docker kills the container, or docker's default of 10 when it is 0. A container that does not run reports changed: false.

It sends POST /api/node/{hostname}/docker/{name}/stop, and needs the permission docker:execute.

type DockerStopInput added in v0.3.0

type DockerStopInput struct {
	// The name of the path: the container's name or ID.
	Name string `json:"-"`

	// Seconds to wait before docker kills it; docker's default when 0.
	Timeout int `json:"timeout,omitempty"`
}

DockerStopInput is the input of DockerService.Stop. A field of the path goes in the path, and each other field in the body.

type Entry added in v0.3.0

type Entry struct {
	// How long the host has run, in seconds.
	Seconds int `json:"seconds"`

	// How long the host has run, in days, hours and minutes.
	Uptime string `json:"uptime"`
}

Entry is the Entry of the spec.

type ErrorResponse added in v0.3.0

type ErrorResponse struct {
	// Additional details about the error.
	Details string `json:"details,omitempty"`

	// A description of the error that occurred.
	Error string `json:"error,omitempty"`

	// Why the request failed, as a word that a program can branch on. The HTTP
	// status is the class of the problem; the reason is the cause, and the error
	// is the message for a person, which can change between releases.
	// invalid_request: the request breaks a rule, such as a missing field (400).
	// unauthorized: no token, or a token that is not valid (401). forbidden: the
	// token does not have the permission (403). not_found: the host or osapi does
	// not have what the request names (404). not_managed: the item is there, but
	// osapi did not deploy it, so osapi does not change it (409). not_installed:
	// the host does not have a program that the request needs (409). conflict: the
	// state of the item blocks the request, such as a create of one that exists
	// (409). unavailable: a part that osapi depends on is down, such as NATS
	// (503). server_error: the controller failed; its log has the cause (500). It
	// is one of: invalid_request, unauthorized, forbidden, not_found, not_managed,
	// not_installed, conflict, unavailable, server_error.
	Reason ErrorResponseReason `json:"reason,omitzero"`
}

ErrorResponse is the ErrorResponse of the spec.

type ErrorResponseReason added in v0.3.0

type ErrorResponseReason string

ErrorResponseReason: Why the request failed, as a word that a program can branch on. The HTTP status is the class of the problem; the reason is the cause, and the error is the message for a person, which can change between releases. invalid_request: the request breaks a rule, such as a missing field (400). unauthorized: no token, or a token that is not valid (401). forbidden: the token does not have the permission (403). not_found: the host or osapi does not have what the request names (404). not_managed: the item is there, but osapi did not deploy it, so osapi does not change it (409). not_installed: the host does not have a program that the request needs (409). conflict: the state of the item blocks the request, such as a create of one that exists (409). unavailable: a part that osapi depends on is down, such as NATS (503). server_error: the controller failed; its log has the cause (500).

const (
	ErrorResponseReasonInvalidRequest ErrorResponseReason = "invalid_request"
	ErrorResponseReasonUnauthorized   ErrorResponseReason = "unauthorized"
	ErrorResponseReasonForbidden      ErrorResponseReason = "forbidden"
	ErrorResponseReasonNotFound       ErrorResponseReason = "not_found"
	ErrorResponseReasonNotManaged     ErrorResponseReason = "not_managed"
	ErrorResponseReasonNotInstalled   ErrorResponseReason = "not_installed"
	ErrorResponseReasonConflict       ErrorResponseReason = "conflict"
	ErrorResponseReasonUnavailable    ErrorResponseReason = "unavailable"
	ErrorResponseReasonServerError    ErrorResponseReason = "server_error"
)

The values of ErrorResponseReason.

type FactKeyEntry added in v0.3.0

type FactKeyEntry struct {
	// Whether this is a built-in fact key.
	Builtin bool `json:"builtin,omitempty"`

	// Human-readable description of the fact.
	Description string `json:"description,omitempty"`

	// The fact key, such as 'interface.primary'.
	Key string `json:"key"`
}

FactKeyEntry is the FactKeyEntry of the spec.

type FactKeysResponse added in v0.3.0

type FactKeysResponse struct {
	// Available fact keys for @fact. references.
	Items []FactKeyEntry `json:"items"`

	// Total number of fact keys.
	TotalItems int `json:"total_items"`
}

FactKeysResponse is the FactKeysResponse of the spec.

type FileChanged

type FileChanged struct {
	// Name is the name of the file.
	Name string `json:"name"`
	// SHA256 is the SHA-256 of the content.
	SHA256 string `json:"sha256"`
	// Changed is true when the content differs from the stored file, or
	// no file has the name.
	Changed bool `json:"changed"`
}

FileChanged is whether content differs from the file of the same name in the Object Store.

type FileDeleteResult added in v0.3.0

type FileDeleteResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Absolute path of the file.
	Path string `json:"path,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

FileDeleteResult is the FileDeleteResult of the spec.

type FileInfo added in v0.3.0

type FileInfo struct {
	// ContentType is how a deploy treats a file: raw writes its bytes as they are;
	// template renders it with Go text/template and the agent's facts.
	ContentType types.ContentType `json:"content_type"`

	// The name of the file.
	Name string `json:"name"`

	// SHA-256 hash of the file content.
	SHA256 string `json:"sha256"`

	// File size in bytes.
	Size int `json:"size"`

	// Source of the file: 'system' or 'user'.
	Source string `json:"source"`
}

FileInfo is the FileInfo of the spec.

type FileInfoResponse added in v0.3.0

type FileInfoResponse struct {
	// ContentType is how a deploy treats a file: raw writes its bytes as they are;
	// template renders it with Go text/template and the agent's facts.
	ContentType types.ContentType `json:"content_type"`

	// The name of the file.
	Name string `json:"name"`

	// SHA-256 hash of the file content.
	SHA256 string `json:"sha256"`

	// File size in bytes.
	Size int `json:"size"`
}

FileInfoResponse is the FileInfoResponse of the spec.

type FileListResponse added in v0.3.0

type FileListResponse struct {
	// List of stored files.
	Items []FileInfo `json:"items"`

	// Total number of files.
	TotalItems int `json:"total_items"`
}

FileListResponse is the FileListResponse of the spec.

type FileService

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

FileService calls the API's File group: object Store file management operations.

func (*FileService) Delete

func (s *FileService) Delete(
	ctx context.Context,
	name string,
) error

Delete is the operation DeleteFileByName: delete a file.

Delete a file from the Object Store.

It sends DELETE /api/file/{name}, and needs the permission file:write.

func (*FileService) Get

func (s *FileService) Get(
	ctx context.Context,
	name string,
) (*Response[FileInfoResponse], error)

Get is the operation GetFileByName: get file metadata.

Get metadata for a specific file in the Object Store.

It sends GET /api/file/{name}, and needs the permission file:read.

func (*FileService) GetChanged

func (s *FileService) GetChanged(
	ctx context.Context,
	name string,
	file io.Reader,
) (*Response[FileChanged], error)

GetChanged computes the SHA-256 of the content and compares it with the SHA-256 of the stored file. Changed is true when the content differs, or the file does not exist yet.

func (*FileService) List

List is the operation GetFiles: list stored files.

List all files stored in the Object Store.

It sends GET /api/file, and needs the permission file:read.

func (*FileService) Stale added in v0.3.0

Stale is the operation GetFileStale: list stale file deployments.

Returns deployments where the source object in the Object Store has been updated since the file was last deployed. Controller-only check that compares state KV SHA-256 hashes against current object content.

It sends GET /api/file/stale, and needs the permission file:read.

func (*FileService) Update added in v0.3.0

func (s *FileService) Update(
	ctx context.Context,
	name string,
	contentType types.ContentType,
	file io.Reader,
) (*Response[FileUploadResponse], error)

Update replaces a file in the Object Store, or creates it when the name is new.

func (*FileService) Upload

func (s *FileService) Upload(
	ctx context.Context,
	name string,
	contentType types.ContentType,
	file io.Reader,
) (*Response[FileUploadResponse], error)

Upload creates a file in the Object Store. It computes the SHA-256 of the content first, and skips the upload when the stored file has the same content. A file with other content is a ConflictError: Update replaces it.

type FileStatus added in v0.3.0

type FileStatus struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Absolute path of the file.
	Path string `json:"path,omitempty"`

	// SHA-256 of the file on the host, when it is there.
	SHA256 string `json:"sha256,omitempty"`

	// in-sync, drifted, missing or unmanaged.
	State string `json:"state,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

FileStatus is the FileStatus of the spec.

type FileUpdateResult added in v0.3.0

type FileUpdateResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Absolute path of the file.
	Path string `json:"path,omitempty"`

	// SHA-256 of the content that the file holds.
	SHA256 string `json:"sha256,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

FileUpdateResult is the FileUpdateResult of the spec.

type FileUploadResponse added in v0.3.0

type FileUploadResponse struct {
	// Whether the file content changed. False when the Object Store already held
	// an object with the same SHA-256 digest.
	Changed bool `json:"changed"`

	// ContentType is how a deploy treats a file: raw writes its bytes as they are;
	// template renders it with Go text/template and the agent's facts.
	ContentType types.ContentType `json:"content_type"`

	// The name of the uploaded file.
	Name string `json:"name"`

	// SHA-256 hash of the file content.
	SHA256 string `json:"sha256"`

	// File size in bytes.
	Size int `json:"size"`
}

FileUploadResponse is the FileUploadResponse of the spec.

type GroupAccount added in v0.3.0

type GroupAccount struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Its numeric group ID.
	GID int `json:"gid,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The users it has as members, besides those whose primary group it is.
	Members []string `json:"members,omitempty"`

	// The group.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

GroupAccount is the GroupAccount of the spec.

type GroupCreateInput added in v0.3.0

type GroupCreateInput struct {
	// Its numeric group ID; the system assigns one when it is 0.
	GID int `json:"gid,omitempty"`

	// The group to add, such as developers.
	Name string `json:"name"`

	// Add it as a system group, with an ID from the system range.
	System bool `json:"system,omitempty"`
}

GroupCreateInput is the input of GroupService.Create. A field of the path goes in the path, and each other field in the body.

type GroupResult added in v0.3.0

type GroupResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The group.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

GroupResult is the GroupResult of the spec.

type GroupService

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

GroupService calls the API's Group group: the groups of the host.

func (*GroupService) Create

func (s *GroupService) Create(
	ctx context.Context,
	hostname string,
	input GroupCreateInput,
) (*Response[Collection[GroupResult]], error)

Create is the operation PostNodeGroup: add a group.

Adds the group with groupadd, with the ID when one is given. A group that the host has already does not change and reports changed: false, whatever its ID. It runs on the Debian family only, and elsewhere reports skipped.

It sends POST /api/node/{hostname}/group, and needs the permission group:write.

func (*GroupService) Delete

func (s *GroupService) Delete(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[GroupResult]], error)

Delete is the operation DeleteNodeGroup: remove a group.

Removes the group with groupdel. A group that the host does not have does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped.

It sends DELETE /api/node/{hostname}/group/{name}, and needs the permission group:write.

func (*GroupService) Get

func (s *GroupService) Get(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[GroupAccount]], error)

Get is the operation GetNodeGroupByKey: get one group.

Reads one group from the same list. A group that the host does not have is not found.

It sends GET /api/node/{hostname}/group/{name}, and needs the permission group:read.

func (*GroupService) List

func (s *GroupService) List(
	ctx context.Context,
	hostname string,
) (*Response[Collection[GroupAccount]], error)

List is the operation GetNodeGroup: list the groups of the host.

Lists each group with its ID and its members, by name, from /etc/group through gohai, on every platform. The members are the users that /etc/group names; a user whose primary group it is is not listed again.

It sends GET /api/node/{hostname}/group, and needs the permission group:read.

func (*GroupService) Update

func (s *GroupService) Update(
	ctx context.Context,
	hostname string,
	input GroupUpdateInput,
) (*Response[Collection[GroupResult]], error)

Update is the operation PutNodeGroup: set the members of a group.

Sets the members with gpasswd -M, in place of the members that the group has. The same members, in any order, do not change it and report changed: false. A group that the host does not have is not found. It runs on the Debian family only, and elsewhere reports skipped.

It sends PUT /api/node/{hostname}/group/{name}, and needs the permission group:write.

type GroupUpdateInput added in v0.3.0

type GroupUpdateInput struct {
	// The name of the path: the group to remove, such as developers.
	Name string `json:"-"`

	// Its members, which replace the members it has; none when empty.
	Members []string `json:"members,omitempty"`
}

GroupUpdateInput is the input of GroupService.Update. A field of the path goes in the path, and each other field in the body.

type HealthResponse added in v0.3.0

type HealthResponse struct {
	// Health status.
	Status string `json:"status"`
}

HealthResponse is the HealthResponse of the spec.

type HealthService

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

HealthService calls the API's Health group: health check endpoints for liveness, readiness, and detailed status.

func (*HealthService) Liveness added in v0.3.0

func (s *HealthService) Liveness(
	ctx context.Context,
) (*Response[HealthResponse], error)

Liveness is the operation GetHealth: liveness probe.

Returns 200 if the process is alive. No checks performed.

It sends GET /api/health.

func (*HealthService) Ready added in v0.3.0

func (s *HealthService) Ready(
	ctx context.Context,
) (*Response[ReadyResponse], error)

Ready is the operation GetHealthReady: readiness probe.

Returns 200 when the service is ready to accept traffic.

It sends GET /api/health/ready.

func (*HealthService) Status added in v0.3.0

Status is the operation GetHealthStatus: system status and component health.

Returns per-component health status with system metrics. Requires authentication.

It sends GET /api/health/status, and needs the permission health:read.

type HealthStatusParams added in v0.3.0

type HealthStatusParams struct {
	// Component is the component of the query: show only the components of this
	// type: controller, nats or agent. The other parts of the status stay. The
	// zero value leaves it out.
	Component types.ComponentType
}

HealthStatusParams are the parameters of HealthService.Status that a request can leave out.

type HostnameEntry added in v0.3.0

type HostnameEntry struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The hostname of the host.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

HostnameEntry is the HostnameEntry of the spec.

type HostnameResult

type HostnameResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The hostname of the host.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

HostnameResult is the HostnameResult of the spec.

type HostnameService

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

HostnameService calls the API's Hostname group: get or set the hostname of target hosts.

func (*HostnameService) Get

Get is the operation GetNodeHostname: get the hostname of the host.

Reads the host's name as the hostname command prints it, on Linux and on macOS. It makes no DNS lookup.

It sends GET /api/node/{hostname}/hostname, and needs the permission hostname:read.

func (*HostnameService) Update

Update is the operation PutNodeHostname: set the hostname of the host.

Sets the static hostname with hostnamectl set-hostname, which keeps it after a reboot. A host that already has the name does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped. In a container the runtime owns the hostname, so there it also reports skipped.

It sends PUT /api/node/{hostname}/hostname, and needs the permission hostname:write.

type HostnameUpdateInput added in v0.3.0

type HostnameUpdateInput struct {
	// The hostname to set, such as web-01.
	Name string `json:"name"`
}

HostnameUpdateInput is the input of HostnameService.Update. A field of the path goes in the path, and each other field in the body.

type ImageDeleteInput added in v0.3.0

type ImageDeleteInput struct {
	// The image of the path: the image, by its reference or its ID.
	Image string `json:"-"`

	// Remove it also when a container uses it.
	Force bool `json:"force,omitempty"`
}

ImageDeleteInput is the input of ImageService.Delete. A field of the path goes in the path, and each other field in the body.

type ImageEntry added in v0.3.0

type ImageEntry struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The image's ID.
	ID string `json:"id,omitempty"`

	// Its repository, such as alpine.
	Repository string `json:"repository,omitempty"`

	// Its size, as docker prints it, such as 7.8MB.
	Size string `json:"size,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// Its tag, such as 3.20.
	Tag string `json:"tag,omitempty"`
}

ImageEntry is the ImageEntry of the spec.

type ImagePullInput added in v0.3.0

type ImagePullInput struct {
	// The image, such as alpine:3.20.
	Image string `json:"image"`
}

ImagePullInput is the input of ImageService.Pull. A field of the path goes in the path, and each other field in the body.

type ImagePullResult added in v0.3.0

type ImagePullResult struct {
	// Whether the pull got a new image: false when the host had it already.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The image.
	Image string `json:"image,omitempty"`

	// The ID of the image that the host has now.
	ImageID string `json:"image_id,omitempty"`

	// Its size in bytes.
	Size int64 `json:"size,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

ImagePullResult is the ImagePullResult of the spec.

type ImageResult added in v0.3.0

type ImageResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The image.
	Image string `json:"image,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

ImageResult is the ImageResult of the spec.

type ImageService added in v0.3.0

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

ImageService calls the API's Image group: the Docker images of the host.

func (*ImageService) Delete added in v0.3.0

func (s *ImageService) Delete(
	ctx context.Context,
	hostname string,
	input ImageDeleteInput,
) (*Response[Collection[ImageResult]], error)

Delete is the operation DeleteNodeImage: remove an image.

Runs docker rmi, with -f when force is set, which removes an image that a container uses. An image that the host does not have reports changed: false.

It sends DELETE /api/node/{hostname}/image/{image}, and needs the permission image:write.

func (*ImageService) List added in v0.3.0

func (s *ImageService) List(
	ctx context.Context,
	hostname string,
) (*Response[Collection[ImageEntry]], error)

List is the operation GetNodeImage: list the images of the host.

Reads each image through gohai's docker collector, which runs docker images. A host whose docker does not answer reports skipped.

It sends GET /api/node/{hostname}/image, and needs the permission image:read.

func (*ImageService) Pull added in v0.3.0

func (s *ImageService) Pull(
	ctx context.Context,
	hostname string,
	input ImagePullInput,
) (*Response[Collection[ImagePullResult]], error)

Pull is the operation PostNodeImagePull: pull an image.

Runs docker pull, and answers the ID and the size of the image that the host has after it. A pull that gets nothing new, because the host had the image of that reference already, reports changed: false.

It sends POST /api/node/{hostname}/image/pull, and needs the permission image:execute.

type InterfaceCreateInput added in v0.3.0

type InterfaceCreateInput struct {
	// The name of the path: the interface, such as eth0, or a fact such as
	// @fact.interface.primary.
	Name string `json:"-"`

	// The static addresses, in CIDR notation, such as 10.0.0.5/24.
	Addresses []string `json:"addresses,omitempty"`

	// Take an IPv4 address from DHCP.
	DHCP4 bool `json:"dhcp4,omitempty"`

	// Take an IPv6 address from DHCP.
	DHCP6 bool `json:"dhcp6,omitempty"`

	// The IPv4 default gateway.
	Gateway4 string `json:"gateway4,omitempty"`

	// The IPv6 default gateway.
	Gateway6 string `json:"gateway6,omitempty"`

	// The MAC address to set.
	MACAddress string `json:"mac_address,omitempty"`

	// The MTU, from 68 to 9000.
	MTU int `json:"mtu,omitempty"`

	// InterfaceType is the type of a network interface that osapi manages.
	Type types.InterfaceType `json:"type,omitzero"`

	// Turn on wake-on-LAN.
	Wakeonlan bool `json:"wakeonlan,omitempty"`
}

InterfaceCreateInput is the input of InterfaceService.Create. A field of the path goes in the path, and each other field in the body.

type InterfaceEntry added in v0.3.0

type InterfaceEntry struct {
	// Each of its addresses, in CIDR notation.
	Addresses []string `json:"addresses,omitempty"`

	// Whether DHCP gave it an IPv4 address: a route of it has proto dhcp.
	DHCP4 bool `json:"dhcp4,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Its first IPv4 address that is not link-local.
	IPv4 string `json:"ipv4,omitempty"`

	// Its first IPv6 address that is not link-local.
	IPv6 string `json:"ipv6,omitempty"`

	// Its MAC address; empty for one without, such as lo.
	MAC string `json:"mac,omitempty"`

	// Its MTU.
	MTU int `json:"mtu,omitempty"`

	// The interface.
	Name string `json:"name,omitempty"`

	// Whether it has the default route.
	Primary bool `json:"primary,omitempty"`

	// up or down.
	State string `json:"state,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

InterfaceEntry is the InterfaceEntry of the spec.

type InterfaceResult added in v0.3.0

type InterfaceResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The interface.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

InterfaceResult is the InterfaceResult of the spec.

type InterfaceRouteCreateInput added in v0.3.0

type InterfaceRouteCreateInput struct {
	// The name of the path: the interface, such as eth0, or a fact such as
	// @fact.interface.primary.
	Name string `json:"-"`

	// Where the route goes, in CIDR notation, such as 10.0.0.0/8; not a default
	// route.
	Destination string `json:"destination"`

	// The metric, from 0 to 4294967295; none when it is 0.
	Metric int `json:"metric,omitempty"`

	// The gateway, an address of the destination's family, such as 192.168.1.1.
	Via string `json:"via"`
}

InterfaceRouteCreateInput is the input of InterfaceRouteService.Create. A field of the path goes in the path, and each other field in the body.

type InterfaceRouteDeleteInput added in v0.3.0

type InterfaceRouteDeleteInput struct {
	// The name of the path: the interface, such as eth0, or a fact such as
	// @fact.interface.primary.
	Name string `json:"-"`

	// The destination of the route, in CIDR notation, such as 10.0.0.0/8.
	Destination string `json:"destination"`
}

InterfaceRouteDeleteInput is the input of InterfaceRouteService.Delete. A field of the path goes in the path, and each other field in the body.

type InterfaceRouteEntry added in v0.3.0

type InterfaceRouteEntry struct {
	// The destination in CIDR notation, or default.
	Destination string `json:"destination,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// inet or inet6.
	Family string `json:"family,omitempty"`

	// The gateway; empty for a route on the link.
	Gateway string `json:"gateway,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The interface the route goes out of.
	Interface string `json:"interface,omitempty"`

	// The metric; 0 when the kernel gives none.
	Metric int `json:"metric,omitempty"`

	// Where the route came from, such as kernel, dhcp or static; empty on macOS.
	Proto string `json:"proto,omitempty"`

	// The scope, such as link; empty for a global route.
	Scope string `json:"scope,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

InterfaceRouteEntry is the InterfaceRouteEntry of the spec.

type InterfaceRouteResult added in v0.3.0

type InterfaceRouteResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// The destination of the route.
	Destination string `json:"destination,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

InterfaceRouteResult is the InterfaceRouteResult of the spec.

type InterfaceRouteService added in v0.3.0

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

InterfaceRouteService calls the API's InterfaceRoute group: the routes of an interface.

func (*InterfaceRouteService) Create added in v0.3.0

Create is the operation PostNodeInterfaceRoute: add a static route to an interface.

Adds the route to the interface's netplan file, such as /etc/netplan/osapi-osapi0-routes.yaml for osapi0, under a netplan definition that is the interface's own, and applies it. A route osapi already has, the same, does not change; one to the same destination by another gateway or metric is refused: update changes it. A default route is refused: the interface behavior sets the gateway. An interface the host does not have is not found. An interface that a match defines, such as cloud-init's all for en*, is refused, because the route would go on each interface the match takes. It runs on the Debian family, and elsewhere, and in a container, reports skipped.

It sends POST /api/node/{hostname}/interface/{name}/route, and needs the permission interface:write.

func (*InterfaceRouteService) Delete added in v0.3.0

Delete is the operation DeleteNodeInterfaceRoute: drop a route that osapi wrote.

Drops the route from the interface's netplan file and applies what is left; the last route removes the file. A route osapi does not have does not change.

It sends DELETE /api/node/{hostname}/interface/{name}/route, and needs the permission interface:write.

func (*InterfaceRouteService) List added in v0.3.0

List is the operation GetNodeInterfaceRoute: list the routes of an interface.

Reads the routes of the main table that go out of the interface: ip route on Linux, netstat on macOS. proto says where a route came from, such as dhcp, kernel or static. An interface with no routes has none; one the host does not have is not found.

It sends GET /api/node/{hostname}/interface/{name}/route, and needs the permission interface:read.

func (*InterfaceRouteService) Update added in v0.3.0

Update is the operation PutNodeInterfaceRoute: change the gateway or the metric of a route.

Writes the route over the one osapi has to the same destination, and applies it. A destination osapi has no route to is not found: create adds it.

It sends PUT /api/node/{hostname}/interface/{name}/route, and needs the permission interface:write.

type InterfaceRouteUpdateInput added in v0.3.0

type InterfaceRouteUpdateInput struct {
	// The name of the path: the interface, such as eth0, or a fact such as
	// @fact.interface.primary.
	Name string `json:"-"`

	// Where the route goes, in CIDR notation, such as 10.0.0.0/8; not a default
	// route.
	Destination string `json:"destination"`

	// The metric, from 0 to 4294967295; none when it is 0.
	Metric int `json:"metric,omitempty"`

	// The gateway, an address of the destination's family, such as 192.168.1.1.
	Via string `json:"via"`
}

InterfaceRouteUpdateInput is the input of InterfaceRouteService.Update. A field of the path goes in the path, and each other field in the body.

type InterfaceService

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

InterfaceService calls the API's Interface group: the network interfaces of the host.

func (*InterfaceService) Create

Create is the operation PostNodeInterface: configure a network interface.

Writes a netplan file of the interface's own, such as /etc/netplan/osapi-osapi0.yaml for osapi0, under a netplan definition that is the interface's own, and applies it. type is ethernet, the default, or dummy. An ethernet is an interface the host has, in the netplan section that netplan status gives for it: one the host does not have is not found. A dummy goes under dummy-devices, and netplan apply makes it, so the host need not have it. dummy-devices needs netplan 0.107 or later. dhcp4 and dhcp6 are false unless given, so the interface has only the addresses given. An interface that a match defines, such as cloud-init's all for en*, is refused, because the config would change each interface the match takes, now and later. An interface osapi already configures does not change: update replaces its config. It runs on the Debian family, and elsewhere, and in a container, reports skipped.

It sends POST /api/node/{hostname}/interface/{name}, and needs the permission interface:write.

func (*InterfaceService) Delete

func (s *InterfaceService) Delete(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[InterfaceResult]], error)

Delete is the operation DeleteNodeInterface: drop the config osapi has of a network interface.

Removes the interface's netplan file and applies what is left. netplan apply leaves the link of a dummy, so delete then deletes the link with ip link delete. An interface osapi does not configure does not change.

It sends DELETE /api/node/{hostname}/interface/{name}, and needs the permission interface:write.

func (*InterfaceService) Get

func (s *InterfaceService) Get(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[InterfaceEntry]], error)

Get is the operation GetNodeInterfaceByKey: get a network interface of the host.

Reads the interface as list does.

It sends GET /api/node/{hostname}/interface/{name}, and needs the permission interface:read.

func (*InterfaceService) List

List is the operation GetNodeInterface: list the network interfaces of the host.

Reads each interface but the loopback, in the order of its index: /sys/class/net and ip on Linux, ifconfig and netstat on macOS. dhcp4 is true when a route of the interface has proto dhcp, and primary when it has the default route.

It sends GET /api/node/{hostname}/interface, and needs the permission interface:read.

func (*InterfaceService) Update

Update is the operation PutNodeInterface: change the config osapi has of a network interface.

Writes the interface's netplan file over the one osapi has, as create writes it, and applies it. Without type dummy, the config goes in the section that netplan status gives, which is dummy-devices for a dummy, so a dummy stays a dummy. An interface osapi does not configure is not found: create configures it.

It sends PUT /api/node/{hostname}/interface/{name}, and needs the permission interface:write.

type InterfaceUpdateInput added in v0.3.0

type InterfaceUpdateInput struct {
	// The name of the path: the interface, such as eth0, or a fact such as
	// @fact.interface.primary.
	Name string `json:"-"`

	// The static addresses, in CIDR notation, such as 10.0.0.5/24.
	Addresses []string `json:"addresses,omitempty"`

	// Take an IPv4 address from DHCP.
	DHCP4 bool `json:"dhcp4,omitempty"`

	// Take an IPv6 address from DHCP.
	DHCP6 bool `json:"dhcp6,omitempty"`

	// The IPv4 default gateway.
	Gateway4 string `json:"gateway4,omitempty"`

	// The IPv6 default gateway.
	Gateway6 string `json:"gateway6,omitempty"`

	// The MAC address to set.
	MACAddress string `json:"mac_address,omitempty"`

	// The MTU, from 68 to 9000.
	MTU int `json:"mtu,omitempty"`

	// InterfaceType is the type of a network interface that osapi manages.
	Type types.InterfaceType `json:"type,omitzero"`

	// Turn on wake-on-LAN.
	Wakeonlan bool `json:"wakeonlan,omitempty"`
}

InterfaceUpdateInput is the input of InterfaceService.Update. A field of the path goes in the path, and each other field in the body.

type JobDeadlettersParams added in v0.3.0

type JobDeadlettersParams struct {
	// Limit is the limit of the query: the most dead letters to list, the newest
	// first (1-100). The zero value leaves it out.
	Limit int
}

JobDeadlettersParams are the parameters of JobService.Deadletters that a request can leave out.

type JobDetailResponse added in v0.3.0

type JobDetailResponse struct {
	// How far each agent got, by hostname.
	AgentStates []JobDetailResponseAgentStatesItem `json:"agent_states,omitempty"`

	// The calls of other behaviors that the method made on each host, one line for
	// each host, such as web-01: netplan update (changed) → managedfile update
	// (changed).
	Chain []string `json:"chain,omitempty"`

	// Whether the operation modified system state. Null for pending/failed jobs;
	// true/false for completed jobs.
	Changed bool `json:"changed,omitempty"`

	// Creation timestamp.
	Created string `json:"created,omitempty"`

	// Error message if failed.
	Error string `json:"error,omitempty"`

	// Agent hostname that processed the job.
	Hostname string `json:"hostname,omitempty"`

	// Unique identifier of the job.
	ID string `json:"id,omitempty"`

	// What the job asked for, with each secret masked.
	Operation JobDetailResponseOperation `json:"operation,omitzero"`

	// What each agent answered, by hostname.
	Responses []JobDetailResponseResponsesItem `json:"responses,omitempty"`

	// The result data if completed.
	Result any `json:"result,omitempty"`

	// The status of a job, which the controller computes from what each agent did:
	// submitted, processing, completed, failed, partial_failure (completed on some
	// agents and failed on others) or skipped (each agent skipped it).
	Status types.JobStatus `json:"status,omitzero"`

	// The target the request gave: _any, _all, a hostname, or a label such as
	// group:web.dev. A job stored before targets were kept has the host that
	// answered.
	Target string `json:"target,omitempty"`

	// Chronological sequence of job lifecycle events.
	Timeline []JobDetailResponseTimelineItem `json:"timeline,omitempty"`

	// Last update timestamp.
	UpdatedAt string `json:"updated_at,omitempty"`
}

JobDetailResponse is the JobDetailResponse of the spec.

type JobDetailResponseAgentStatesItem added in v0.3.0

type JobDetailResponseAgentStatesItem struct {
	// Duration is the property duration.
	Duration string `json:"duration,omitempty"`

	// Error is the property error.
	Error string `json:"error,omitempty"`

	// Hostname is the property hostname.
	Hostname string `json:"hostname"`

	// The status of a job on one host. The controller records submitted and
	// retried; an agent records acknowledged, started, completed, failed or
	// skipped; and timeout is a host whose agent did not answer in time.
	Status types.AgentJobStatus `json:"status,omitzero"`
}

JobDetailResponseAgentStatesItem is the JobDetailResponseAgentStatesItem of the spec.

type JobDetailResponseOperation added in v0.3.0

type JobDetailResponseOperation struct {
	// The data of the operation, with each secret masked.
	Data any `json:"data,omitempty"`

	// The operation, such as node.hostname.get.
	Type string `json:"type"`
}

JobDetailResponseOperation: What the job asked for, with each secret masked.

type JobDetailResponseResponsesItem added in v0.3.0

type JobDetailResponseResponsesItem struct {
	// Changed is the property changed.
	Changed bool `json:"changed,omitempty"`

	// Agent result data.
	Data any `json:"data,omitempty"`

	// Error is the property error.
	Error string `json:"error,omitempty"`

	// Hostname is the property hostname.
	Hostname string `json:"hostname"`

	// The status of a job on one host. The controller records submitted and
	// retried; an agent records acknowledged, started, completed, failed or
	// skipped; and timeout is a host whose agent did not answer in time.
	Status types.AgentJobStatus `json:"status,omitzero"`

	// The calls of other behaviors that the method made on the host, also when one
	// failed.
	Steps []types.Step `json:"steps,omitempty"`
}

JobDetailResponseResponsesItem is the JobDetailResponseResponsesItem of the spec.

type JobDetailResponseTimelineItem added in v0.3.0

type JobDetailResponseTimelineItem struct {
	// Error details if applicable.
	Error string `json:"error,omitempty"`

	// The status of a job on one host. The controller records submitted and
	// retried; an agent records acknowledged, started, completed, failed or
	// skipped; and timeout is a host whose agent did not answer in time.
	Event types.AgentJobStatus `json:"event,omitzero"`

	// Agent or source that generated the event.
	Hostname string `json:"hostname,omitempty"`

	// Human-readable description of the event.
	Message string `json:"message,omitempty"`

	// ISO 8601 timestamp of the event.
	Timestamp string `json:"timestamp,omitempty"`
}

JobDetailResponseTimelineItem is the JobDetailResponseTimelineItem of the spec.

type JobListParams added in v0.3.0

type JobListParams struct {
	// Status is the status of the query: filter jobs by status. The zero value
	// leaves it out.
	Status types.JobStatus

	// Limit is the limit of the query: maximum number of jobs per page (1-100).
	// The zero value leaves it out.
	Limit int

	// Offset is the offset of the query: number of jobs to skip for pagination.
	// The zero value leaves it out.
	Offset int
}

JobListParams are the parameters of JobService.List that a request can leave out.

type JobRetryInput added in v0.3.0

type JobRetryInput struct {
	// The id of the path: UUID of the job to retry.
	ID string `json:"-"`

	// The target of the retried job: _any, _all, a hostname, or a label such as
	// group:web.dev.
	TargetHostname string `json:"target_hostname,omitempty"`
}

JobRetryInput is the input of JobService.Retry. A field of the path goes in the path, and each other field in the body.

type JobService

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

JobService calls the API's Job group: operations related to the job queue.

func (*JobService) Deadletters added in v0.3.0

func (s *JobService) Deadletters(
	ctx context.Context,
	params JobDeadlettersParams,
) (*Response[DeadLetterList], error)

Deadletters is the operation ListDeadLetters: list the dead letters.

Lists the newest jobs whose delivery to an agent used up its retries, from the dead letter stream, each with its job's operation, target and error. A job goes back to the queue with retry. A token with a target scope gets only the dead letters of the jobs whose target is in its scope.

It sends GET /api/job/deadletter, and needs the permission job:read.

func (*JobService) Delete

func (s *JobService) Delete(
	ctx context.Context,
	id string,
) error

Delete is the operation DeleteJobByID: delete a job.

Delete a specific job by its ID. A job whose target is outside the target scope of the token is not found.

It sends DELETE /api/job/{id}, and needs the permission job:write.

func (*JobService) Get

Get is the operation GetJobByID: get job detail.

Retrieve details of a specific job by its ID. A job whose target is outside the target scope of the token is not found.

It sends GET /api/job/{id}, and needs the permission job:read.

func (*JobService) List

func (s *JobService) List(
	ctx context.Context,
	params JobListParams,
) (*Response[ListJobsResponse], error)

List is the operation GetJobs: list jobs.

Retrieve jobs, optionally filtered by status. A token with a target scope gets only the jobs whose target is in its scope, and the counts include only those jobs.

It sends GET /api/job, and needs the permission job:read.

func (*JobService) Retry

Retry is the operation RetryJobByID: retry a job.

Create a new job using the same operation data as an existing job. The original job is preserved. Returns the new job ID.

It sends POST /api/job/{id}/retry, and needs the permission job:write.

type JobStats

type JobStats struct {
	// Number of completed jobs.
	Completed int `json:"completed"`

	// Number of jobs in the dead letter queue.
	DLQ int `json:"dlq"`

	// Number of failed jobs.
	Failed int `json:"failed"`

	// Number of jobs currently processing.
	Processing int `json:"processing"`

	// Number of jobs that no agent has taken.
	Submitted int `json:"submitted"`

	// Total number of jobs.
	Total int `json:"total"`
}

JobStats is the JobStats of the spec.

type JoinResponse added in v0.3.0

type JoinResponse struct {
	// The controller's Ed25519 public key, in base64, which the agent keeps and
	// checks each job with.
	ControllerPublicKey string `json:"controller_public_key"`
}

JoinResponse is the JoinResponse of the spec.

type KVBucketInfo

type KVBucketInfo struct {
	// Total bytes in the bucket.
	Bytes int `json:"bytes"`

	// Number of keys in the bucket.
	Keys int `json:"keys"`

	// KV bucket name.
	Name string `json:"name"`
}

KVBucketInfo is the KVBucketInfo of the spec.

type ListAdmissionResponse added in v0.3.0

type ListAdmissionResponse struct {
	// The admission records, in hostname order.
	Items []Admission `json:"items"`

	// The number of records.
	TotalItems int `json:"total_items"`
}

ListAdmissionResponse is the ListAdmissionResponse of the spec.

type ListAgentsResponse added in v0.3.0

type ListAgentsResponse struct {
	// The active agents.
	Items []AgentInfo `json:"items"`

	// Total number of active agents.
	TotalItems int `json:"total_items"`
}

ListAgentsResponse is the ListAgentsResponse of the spec.

type ListAuditResponse added in v0.3.0

type ListAuditResponse struct {
	// The audit entries for this page.
	Items []AuditEntry `json:"items"`

	// Total number of audit entries.
	TotalItems int `json:"total_items"`
}

ListAuditResponse is the ListAuditResponse of the spec.

type ListJobsResponse added in v0.3.0

type ListJobsResponse struct {
	// Items is the property items.
	Items []JobDetailResponse `json:"items,omitempty"`

	// Count of all jobs by status. Derived from key names during the listing pass,
	// with no extra reads.
	StatusCounts map[string]int `json:"status_counts,omitempty"`

	// Total number of jobs matching the filter.
	TotalItems int `json:"total_items,omitempty"`
}

ListJobsResponse is the ListJobsResponse of the spec.

type LoadAverageResponse added in v0.3.0

type LoadAverageResponse struct {
	// Load average for the last 15 minutes.
	Min15 float64 `json:"15min"`

	// Load average for the last 1 minute.
	Min1 float64 `json:"1min"`

	// Load average for the last 5 minutes.
	Min5 float64 `json:"5min"`
}

LoadAverageResponse: The system load averages for 1, 5, and 15 minutes.

type LoadEntry added in v0.3.0

type LoadEntry struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// LoadAverage is the property load_average.
	LoadAverage Averages `json:"load_average,omitzero"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

LoadEntry is the LoadEntry of the spec.

type LoadService

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

LoadService calls the API's Load group: get the load averages of target hosts.

func (*LoadService) Get

func (s *LoadService) Get(
	ctx context.Context,
	hostname string,
) (*Response[Collection[LoadEntry]], error)

Get is the operation GetNodeLoad: get the load averages of the host.

Reads the averages of the run queue over 1, 5 and 15 minutes.

It sends GET /api/node/{hostname}/load, and needs the permission load:read.

type LogEntry

type LogEntry struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The message.
	Message string `json:"message,omitempty"`

	// The process that wrote it.
	PID int `json:"pid,omitempty"`

	// Priority is the property priority.
	Priority Priority `json:"priority,omitzero"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// When journald recorded it, in RFC 3339.
	Timestamp string `json:"timestamp,omitempty"`

	// The syslog identifier that wrote it.
	Unit string `json:"unit,omitempty"`
}

LogEntry is the LogEntry of the spec.

type LogListParams added in v0.3.0

type LogListParams struct {
	// Unit is the unit of the query: only the entries of this systemd unit, such
	// as nginx.service. The zero value leaves it out.
	Unit string

	// Lines is the lines of the query: how many of the newest entries; 100 when it
	// is not set. The zero value leaves it out.
	Lines int

	// Since is the since of the query: only the entries since this time, in any
	// form that journalctl --since takes, such as 1 hour ago. The zero value
	// leaves it out.
	Since string

	// Priority is the priority of the query: only the entries at this priority or
	// above. The zero value leaves it out.
	Priority Priority
}

LogListParams are the parameters of LogService.List that a request can leave out.

type LogService

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

LogService calls the API's Log group: the entries of the systemd journal.

func (*LogService) List added in v0.3.0

func (s *LogService) List(
	ctx context.Context,
	hostname string,
	params LogListParams,
) (*Response[Collection[LogEntry]], error)

List is the operation GetNodeLog: list the entries of the journal.

Runs journalctl --output=json, the newest entries last: the last 100 unless lines says, of one unit when unit says, since a time when since says, and at a priority or above when priority says. A priority is its name, such as err or info. The hand-written log domain read the Debian family only; this reads each Linux host that has journald.

It sends GET /api/node/{hostname}/log, and needs the permission log:read.

type LogSourceService added in v0.3.0

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

LogSourceService calls the API's LogSource group: the sources that write to the systemd journal.

func (*LogSourceService) List added in v0.3.0

List is the operation GetNodeLogSource: list the sources of the journal.

Runs journalctl --field=SYSLOG_IDENTIFIER: each syslog identifier that has an entry, once, sorted. A name here is what log list takes as unit when the source is a systemd unit.

It sends GET /api/node/{hostname}/log/source, and needs the permission log:read.

type LogSourceSource added in v0.3.0

type LogSourceSource struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The syslog identifier, such as sshd.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

LogSourceSource is the LogSourceSource of the spec.

type MemoryEntry added in v0.3.0

type MemoryEntry struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Memory is the property memory.
	Memory Usage `json:"memory,omitzero"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

MemoryEntry is the MemoryEntry of the spec.

type MemoryResponse added in v0.3.0

type MemoryResponse struct {
	// Free memory in bytes.
	Free int `json:"free"`

	// Total memory in bytes.
	Total int `json:"total"`

	// Used memory in bytes.
	Used int `json:"used"`
}

MemoryResponse: Memory usage information.

type MemoryService

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

MemoryService calls the API's Memory group: get the memory usage of target hosts.

func (*MemoryService) Get

func (s *MemoryService) Get(
	ctx context.Context,
	hostname string,
) (*Response[Collection[MemoryEntry]], error)

Get is the operation GetNodeMemory: get the memory usage of the host.

Reads the total, the free and the used memory, in bytes. Used is the total less what is available, which includes the cache, as free(1) reports it.

It sends GET /api/node/{hostname}/memory, and needs the permission memory:read.

type MethodSpec added in v0.3.0

type MethodSpec struct {
	// Name is the Go name of the method, such as Update.
	Name string `json:"name"`
	// Doc is what the method does.
	Doc string `json:"doc"`
	// Permission is the permission that the call needs, such as
	// hostname:write.
	Permission string `json:"permission"`
	// HTTP is the method and the path that the call sends, such as
	// PUT /node/{hostname}/hostname.
	HTTP string `json:"http"`
	// Input is the Go type of its request body, empty when it has none.
	Input string `json:"input,omitempty"`
	// Result is the Go type of its answer, such as Collection[HostnameResult].
	Result string `json:"result,omitempty"`
	// Examples is the number of examples of the call in the SDK's examples.
	Examples int `json:"examples"`
	// Program is a method that a program calls, not a person, such as the
	// agent's join. It has no example, which would run it against a
	// controller.
	Program bool `json:"program,omitempty"`
}

MethodSpec is one method of a service.

type NATSInfo

type NATSInfo struct {
	// Connected NATS server URL.
	URL string `json:"url"`

	// NATS server version.
	Version string `json:"version"`
}

NATSInfo is the NATSInfo of the spec.

type NTPCreateInput added in v0.3.0

type NTPCreateInput struct {
	// The NTP servers, hostnames or IP addresses.
	Servers []string `json:"servers"`
}

NTPCreateInput is the input of NTPService.Create. A field of the path goes in the path, and each other field in the body.

type NTPService

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

NTPService calls the API's NTP group: the NTP servers of chrony, and its sync status.

func (*NTPService) Create

func (s *NTPService) Create(
	ctx context.Context,
	hostname string,
	input NTPCreateInput,
) (*Response[Collection[NtpResult]], error)

Create is the operation PostNodeNtp: set the NTP servers that chrony uses.

Writes a server line for each server to /etc/chrony/sources.d/osapi-ntp.sources, and reloads the sources with chronyc reload sources. A file that has the same servers does not change, and reports changed: false.

It sends POST /api/node/{hostname}/ntp, and needs the permission ntp:write.

func (*NTPService) Delete

func (s *NTPService) Delete(
	ctx context.Context,
	hostname string,
) (*Response[Collection[NtpResult]], error)

Delete is the operation DeleteNodeNtp: remove the NTP servers that osapi set.

Removes /etc/chrony/sources.d/osapi-ntp.sources and reloads the sources, so chrony uses its other sources. When osapi set no servers, it reports changed: false.

It sends DELETE /api/node/{hostname}/ntp, and needs the permission ntp:write.

func (*NTPService) Get

func (s *NTPService) Get(
	ctx context.Context,
	hostname string,
) (*Response[Collection[NtpStatus]], error)

Get is the operation GetNodeNtp: get the sync status of chrony and its sources.

Reads chronyc tracking, for whether chrony is synchronized, its stratum, its offset from NTP time and the source that it follows, and chronyc sources, for each source that it has.

It sends GET /api/node/{hostname}/ntp, and needs the permission ntp:read.

func (*NTPService) Update

func (s *NTPService) Update(
	ctx context.Context,
	hostname string,
	input NTPUpdateInput,
) (*Response[Collection[NtpResult]], error)

Update is the operation PutNodeNtp: replace the NTP servers that osapi set.

The same as create, for servers that osapi set already. It fails with not found when osapi set none. The servers that the file has already report changed: false.

It sends PUT /api/node/{hostname}/ntp, and needs the permission ntp:write.

type NTPUpdateInput added in v0.3.0

type NTPUpdateInput struct {
	// The NTP servers, hostnames or IP addresses.
	Servers []string `json:"servers"`
}

NTPUpdateInput is the input of NTPService.Update. A field of the path goes in the path, and each other field in the body.

type NetworkInterfaceResponse added in v0.3.0

type NetworkInterfaceResponse struct {
	// AddressFamily is the IP address family of an interface.
	Family types.AddressFamily `json:"family,omitzero"`

	// IPv4 is the property ipv4.
	IPv4 string `json:"ipv4,omitempty"`

	// IPv6 is the property ipv6.
	IPv6 string `json:"ipv6,omitempty"`

	// MAC is the property mac.
	MAC string `json:"mac,omitempty"`

	// Name is the property name.
	Name string `json:"name"`
}

NetworkInterfaceResponse is the NetworkInterfaceResponse of the spec.

type NodeCondition added in v0.3.0

type NodeCondition struct {
	// LastTransitionTime is the property last_transition_time.
	LastTransitionTime time.Time `json:"last_transition_time"`

	// Reason is the property reason.
	Reason string `json:"reason,omitempty"`

	// A condition that an agent or a component evaluates.
	Type types.ConditionType `json:"type"`
}

NodeCondition is the NodeCondition of the spec.

type NodeFileDeleteInput added in v0.3.0

type NodeFileDeleteInput struct {
	// Absolute path of the file on the host.
	Path string `json:"path"`
}

NodeFileDeleteInput is the input of NodeFileService.Delete. A field of the path goes in the path, and each other field in the body.

type NodeFileService added in v0.3.0

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

NodeFileService calls the API's NodeFile group: files of the object store, deployed to the host.

func (*NodeFileService) Delete added in v0.3.0

Delete is the operation DeleteNodeFile: remove a file that osapi deployed.

Removes the file and keeps its record, marked undeployed, so status reports unmanaged. A path that osapi did not deploy, or deleted already, does not change and reports changed: false. The object stays in the object store.

It sends DELETE /api/node/{hostname}/file, and needs the permission file:write.

func (*NodeFileService) Get added in v0.3.0

func (s *NodeFileService) Get(
	ctx context.Context,
	hostname string,
	path string,
) (*Response[Collection[FileStatus]], error)

Get is the operation GetNodeFile: show whether a deployed file holds what osapi wrote.

Compares the file on the host with the record that osapi keeps of what it deployed: in-sync when they agree, drifted when something changed the file, missing when osapi deployed the file and it is gone, and unmanaged when osapi did not deploy the path or undeployed it. A path that is a directory is refused.

It sends GET /api/node/{hostname}/file, and needs the permission file:read.

func (*NodeFileService) Update added in v0.3.0

Update is the operation PutNodeFile: deploy an object of the object store to a path.

Writes the object at the path with its mode and ownership, and keeps a record of it. A template object, or content_type template, is rendered first with .Facts, .Vars and .Hostname. The record keeps the SHA-256 of the object as it was read. A file that holds the content, mode and owner already, from the same object, does not change and reports changed: false. osapi client file stale list compares the object now with that SHA-256, so it shows the deployments whose object changed since.

It sends PUT /api/node/{hostname}/file, and needs the permission file:write.

type NodeFileUpdateInput added in v0.3.0

type NodeFileUpdateInput struct {
	// ContentType is how a deploy treats a file: raw writes its bytes as they are;
	// template renders it with Go text/template and the agent's facts.
	ContentType types.ContentType `json:"content_type,omitzero"`

	// Group that owns the file; left as written when empty.
	Group string `json:"group,omitempty"`

	// Permissions in octal, such as 0644; when empty, a file keeps its mode and a
	// new file gets 0644.
	Mode string `json:"mode,omitempty"`

	// The object of the object store, from osapi client file list.
	ObjectName string `json:"object_name"`

	// User that owns the file; left as written when empty.
	Owner string `json:"owner,omitempty"`

	// Absolute path of the file on the host.
	Path string `json:"path"`

	// Variables of a template, as .Vars, each as key=value.
	Vars map[string]string `json:"vars,omitempty"`
}

NodeFileUpdateInput is the input of NodeFileService.Update. A field of the path goes in the path, and each other field in the body.

type NotFoundError

type NotFoundError struct {
	APIError
}

NotFoundError represents resource not found errors (404).

func (*NotFoundError) Unwrap

func (e *NotFoundError) Unwrap() error

Unwrap returns the underlying APIError.

type NtpResult added in v0.3.0

type NtpResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

NtpResult is the NtpResult of the spec.

type NtpStatus added in v0.3.0

type NtpStatus struct {
	// The source that chrony follows now.
	CurrentSource string `json:"current_source,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The offset of the system clock from NTP time, such as +0.000003422s.
	Offset string `json:"offset,omitempty"`

	// The sources that chrony has.
	Servers []string `json:"servers,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// The NTP stratum of the host.
	Stratum int `json:"stratum,omitempty"`

	// Whether chrony is synchronized to a source.
	Synchronized bool `json:"synchronized,omitempty"`
}

NtpStatus is the NtpStatus of the spec.

type OSInfoResponse added in v0.3.0

type OSInfoResponse struct {
	// The name of the Linux distribution.
	Distribution string `json:"distribution"`

	// The platform family that the agent picks providers by, as gohai names it:
	// debian, suse, darwin and so on. A method runs on a host whose family is one
	// of its platforms.
	Family string `json:"family,omitempty"`

	// The version of the Linux distribution.
	Version string `json:"version"`
}

OSInfoResponse: Operating system information.

type OSService

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

OSService calls the API's OS group: get the operating system of target hosts.

func (*OSService) Get

func (s *OSService) Get(
	ctx context.Context,
	hostname string,
) (*Response[Collection[OsEntry]], error)

Get is the operation GetNodeOs: get the operating system of the host.

Reads the distribution and its version: the ID and VERSION_ID of /etc/os-release on Linux, and darwin with the ProductVersion of sw_vers on macOS, such as darwin 15.5.

It sends GET /api/node/{hostname}/os, and needs the permission os:read.

type ObjectStoreInfo

type ObjectStoreInfo struct {
	// Object Store bucket name.
	Name string `json:"name"`

	// Total bytes in the store.
	Size int `json:"size"`
}

ObjectStoreInfo is the ObjectStoreInfo of the spec.

type OperationID added in v0.3.0

type OperationID string

OperationID: An operationId of an operation that needs a permission.

const (
	OperationIDAdmitMachine             OperationID = "AdmitMachine"
	OperationIDDeleteFileByName         OperationID = "DeleteFileByName"
	OperationIDDeleteJobByID            OperationID = "DeleteJobByID"
	OperationIDDeleteMachine            OperationID = "DeleteMachine"
	OperationIDDeleteNodeCertificate    OperationID = "DeleteNodeCertificate"
	OperationIDDeleteNodeDns            OperationID = "DeleteNodeDns"
	OperationIDDeleteNodeDocker         OperationID = "DeleteNodeDocker"
	OperationIDDeleteNodeFile           OperationID = "DeleteNodeFile"
	OperationIDDeleteNodeGroup          OperationID = "DeleteNodeGroup"
	OperationIDDeleteNodeImage          OperationID = "DeleteNodeImage"
	OperationIDDeleteNodeInterface      OperationID = "DeleteNodeInterface"
	OperationIDDeleteNodeInterfaceRoute OperationID = "DeleteNodeInterfaceRoute"
	OperationIDDeleteNodeNtp            OperationID = "DeleteNodeNtp"
	OperationIDDeleteNodePackage        OperationID = "DeleteNodePackage"
	OperationIDDeleteNodeSchedule       OperationID = "DeleteNodeSchedule"
	OperationIDDeleteNodeService        OperationID = "DeleteNodeService"
	OperationIDDeleteNodeSysctl         OperationID = "DeleteNodeSysctl"
	OperationIDDeleteNodeUser           OperationID = "DeleteNodeUser"
	OperationIDDeleteNodeUserSshkey     OperationID = "DeleteNodeUserSshkey"
	OperationIDDeleteSecret             OperationID = "DeleteSecret"
	OperationIDDrainAgent               OperationID = "DrainAgent"
	OperationIDGetAdmission             OperationID = "GetAdmission"
	OperationIDGetAdmissions            OperationID = "GetAdmissions"
	OperationIDGetAgentConfig           OperationID = "GetAgentConfig"
	OperationIDGetAgentDetails          OperationID = "GetAgentDetails"
	OperationIDGetAgentFacts            OperationID = "GetAgentFacts"
	OperationIDGetAgents                OperationID = "GetAgents"
	OperationIDGetAuditExport           OperationID = "GetAuditExport"
	OperationIDGetAuditLogByID          OperationID = "GetAuditLogByID"
	OperationIDGetAuditLogs             OperationID = "GetAuditLogs"
	OperationIDGetCatalog               OperationID = "GetCatalog"
	OperationIDGetFileByName            OperationID = "GetFileByName"
	OperationIDGetFileStale             OperationID = "GetFileStale"
	OperationIDGetFiles                 OperationID = "GetFiles"
	OperationIDGetHealthStatus          OperationID = "GetHealthStatus"
	OperationIDGetJobByID               OperationID = "GetJobByID"
	OperationIDGetJobs                  OperationID = "GetJobs"
	OperationIDGetNodeCertificate       OperationID = "GetNodeCertificate"
	OperationIDGetNodeCertificateByKey  OperationID = "GetNodeCertificateByKey"
	OperationIDGetNodeDisk              OperationID = "GetNodeDisk"
	OperationIDGetNodeDnsByKey          OperationID = "GetNodeDnsByKey"
	OperationIDGetNodeDocker            OperationID = "GetNodeDocker"
	OperationIDGetNodeDockerByKey       OperationID = "GetNodeDockerByKey"
	OperationIDGetNodeFile              OperationID = "GetNodeFile"
	OperationIDGetNodeGroup             OperationID = "GetNodeGroup"
	OperationIDGetNodeGroupByKey        OperationID = "GetNodeGroupByKey"
	OperationIDGetNodeHostname          OperationID = "GetNodeHostname"
	OperationIDGetNodeImage             OperationID = "GetNodeImage"
	OperationIDGetNodeInterface         OperationID = "GetNodeInterface"
	OperationIDGetNodeInterfaceByKey    OperationID = "GetNodeInterfaceByKey"
	OperationIDGetNodeInterfaceRoute    OperationID = "GetNodeInterfaceRoute"
	OperationIDGetNodeLoad              OperationID = "GetNodeLoad"
	OperationIDGetNodeLog               OperationID = "GetNodeLog"
	OperationIDGetNodeLogSource         OperationID = "GetNodeLogSource"
	OperationIDGetNodeMemory            OperationID = "GetNodeMemory"
	OperationIDGetNodeNtp               OperationID = "GetNodeNtp"
	OperationIDGetNodeOs                OperationID = "GetNodeOs"
	OperationIDGetNodePackage           OperationID = "GetNodePackage"
	OperationIDGetNodePackageByKey      OperationID = "GetNodePackageByKey"
	OperationIDGetNodePackageUpdates    OperationID = "GetNodePackageUpdates"
	OperationIDGetNodeProcess           OperationID = "GetNodeProcess"
	OperationIDGetNodeProcessByKey      OperationID = "GetNodeProcessByKey"
	OperationIDGetNodeSchedule          OperationID = "GetNodeSchedule"
	OperationIDGetNodeScheduleByKey     OperationID = "GetNodeScheduleByKey"
	OperationIDGetNodeService           OperationID = "GetNodeService"
	OperationIDGetNodeServiceByKey      OperationID = "GetNodeServiceByKey"
	OperationIDGetNodeStatus            OperationID = "GetNodeStatus"
	OperationIDGetNodeSysctl            OperationID = "GetNodeSysctl"
	OperationIDGetNodeSysctlByKey       OperationID = "GetNodeSysctlByKey"
	OperationIDGetNodeTimezone          OperationID = "GetNodeTimezone"
	OperationIDGetNodeUptime            OperationID = "GetNodeUptime"
	OperationIDGetNodeUser              OperationID = "GetNodeUser"
	OperationIDGetNodeUserByKey         OperationID = "GetNodeUserByKey"
	OperationIDGetNodeUserSshkey        OperationID = "GetNodeUserSshkey"
	OperationIDGetPKICert               OperationID = "GetPKICert"
	OperationIDGetPKIKeyRotation        OperationID = "GetPKIKeyRotation"
	OperationIDGetPKINATSCertRotation   OperationID = "GetPKINATSCertRotation"
	OperationIDGetSecret                OperationID = "GetSecret"
	OperationIDGetSecretValue           OperationID = "GetSecretValue"
	OperationIDGetSecretVaults          OperationID = "GetSecretVaults"
	OperationIDGetSecrets               OperationID = "GetSecrets"
	OperationIDGetTrace                 OperationID = "GetTrace"
	OperationIDListDeadLetters          OperationID = "ListDeadLetters"
	OperationIDListPKICerts             OperationID = "ListPKICerts"
	OperationIDPostFile                 OperationID = "PostFile"
	OperationIDPostNodeCertificate      OperationID = "PostNodeCertificate"
	OperationIDPostNodeCommandExec      OperationID = "PostNodeCommandExec"
	OperationIDPostNodeCommandShell     OperationID = "PostNodeCommandShell"
	OperationIDPostNodeConnectivityPing OperationID = "PostNodeConnectivityPing"
	OperationIDPostNodeDocker           OperationID = "PostNodeDocker"
	OperationIDPostNodeDockerExec       OperationID = "PostNodeDockerExec"
	OperationIDPostNodeDockerStart      OperationID = "PostNodeDockerStart"
	OperationIDPostNodeDockerStop       OperationID = "PostNodeDockerStop"
	OperationIDPostNodeGroup            OperationID = "PostNodeGroup"
	OperationIDPostNodeImagePull        OperationID = "PostNodeImagePull"
	OperationIDPostNodeInterface        OperationID = "PostNodeInterface"
	OperationIDPostNodeInterfaceRoute   OperationID = "PostNodeInterfaceRoute"
	OperationIDPostNodeNtp              OperationID = "PostNodeNtp"
	OperationIDPostNodePackage          OperationID = "PostNodePackage"
	OperationIDPostNodePowerReboot      OperationID = "PostNodePowerReboot"
	OperationIDPostNodePowerShutdown    OperationID = "PostNodePowerShutdown"
	OperationIDPostNodeProcessSignal    OperationID = "PostNodeProcessSignal"
	OperationIDPostNodeSchedule         OperationID = "PostNodeSchedule"
	OperationIDPostNodeService          OperationID = "PostNodeService"
	OperationIDPostNodeServiceDisable   OperationID = "PostNodeServiceDisable"
	OperationIDPostNodeServiceEnable    OperationID = "PostNodeServiceEnable"
	OperationIDPostNodeServiceRestart   OperationID = "PostNodeServiceRestart"
	OperationIDPostNodeServiceStart     OperationID = "PostNodeServiceStart"
	OperationIDPostNodeServiceStop      OperationID = "PostNodeServiceStop"
	OperationIDPostNodeSysctl           OperationID = "PostNodeSysctl"
	OperationIDPostNodeUser             OperationID = "PostNodeUser"
	OperationIDPostNodeUserSshkey       OperationID = "PostNodeUserSshkey"
	OperationIDPutAgentConfig           OperationID = "PutAgentConfig"
	OperationIDPutFileByName            OperationID = "PutFileByName"
	OperationIDPutNodeCertificate       OperationID = "PutNodeCertificate"
	OperationIDPutNodeDns               OperationID = "PutNodeDns"
	OperationIDPutNodeFile              OperationID = "PutNodeFile"
	OperationIDPutNodeGroup             OperationID = "PutNodeGroup"
	OperationIDPutNodeHostname          OperationID = "PutNodeHostname"
	OperationIDPutNodeInterface         OperationID = "PutNodeInterface"
	OperationIDPutNodeInterfaceRoute    OperationID = "PutNodeInterfaceRoute"
	OperationIDPutNodeNtp               OperationID = "PutNodeNtp"
	OperationIDPutNodePackageUpdates    OperationID = "PutNodePackageUpdates"
	OperationIDPutNodeSchedule          OperationID = "PutNodeSchedule"
	OperationIDPutNodeService           OperationID = "PutNodeService"
	OperationIDPutNodeSysctl            OperationID = "PutNodeSysctl"
	OperationIDPutNodeTimezone          OperationID = "PutNodeTimezone"
	OperationIDPutNodeUser              OperationID = "PutNodeUser"
	OperationIDPutNodeUserPassword      OperationID = "PutNodeUserPassword"
	OperationIDPutSecret                OperationID = "PutSecret"
	OperationIDRejectMachine            OperationID = "RejectMachine"
	OperationIDRetryJobByID             OperationID = "RetryJobByID"
	OperationIDRevokeMachine            OperationID = "RevokeMachine"
	OperationIDRotatePKIKey             OperationID = "RotatePKIKey"
	OperationIDRotatePKINATSCert        OperationID = "RotatePKINATSCert"
	OperationIDUndrainAgent             OperationID = "UndrainAgent"
)

The values of OperationID.

type Option

type Option func(*Client)

Option configures the Client.

func WithHTTPTransport

func WithHTTPTransport(
	transport http.RoundTripper,
) Option

WithHTTPTransport sets a custom base HTTP transport. Without it, the client sends through its own clone of http.DefaultTransport, so a caller that closes the idle connections of http.DefaultTransport (for example httptest.Server.Close) does not break a request of this client.

func WithLogger

func WithLogger(
	logger *slog.Logger,
) Option

WithLogger sets a custom logger. Defaults to slog.Default().

type OsEntry added in v0.3.0

type OsEntry struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// OSInfo is the property os_info.
	OSInfo Release `json:"os_info,omitzero"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

OsEntry is the OsEntry of the spec.

type PKICert added in v0.3.0

type PKICert struct {
	// The component that serves it: controller, nats or agent.
	Component string `json:"component"`

	// The days that are left until it expires.
	DaysLeft int `json:"days_left,omitempty"`

	// When the certificate expires.
	Expires time.Time `json:"expires,omitzero"`

	// The certificate's file on the host.
	File string `json:"file"`

	// The SHA-256 fingerprint of the certificate.
	Fingerprint string `json:"fingerprint,omitempty"`

	// Whether FIPS 186-5 and SP 800-131A approve the key and the signature
	// algorithms.
	FipsApproved bool `json:"fips_approved,omitempty"`

	// The host that serves the certificate.
	Hostname string `json:"hostname"`

	// The algorithm and size of the public key, such as ECDSA P-256.
	Key string `json:"key,omitempty"`

	// The name of the certificate, such as api or agent-metrics.
	Name string `json:"name"`

	// The DNS names and the IP addresses that the certificate is for.
	Names []string `json:"names,omitempty"`

	// The algorithm that signed the certificate, such as ECDSA-SHA256.
	Signature string `json:"signature,omitempty"`

	// self-signed, which osapi made, or cert_file, the operator's.
	Source string `json:"source"`

	// ok; not made, when the component has not started on the host; or unreadable,
	// with the reason.
	State string `json:"state"`
}

PKICert is the PKICert of the spec.

type PKICertList added in v0.3.0

type PKICertList struct {
	// Items is the property items.
	Items []PKICert `json:"items"`

	// The number of certificates.
	TotalItems int `json:"total_items"`
}

PKICertList is the PKICertList of the spec.

type PKIKeyRotation added in v0.3.0

type PKIKeyRotation struct {
	// The admitted agents that the switch waits for: each one that reported within
	// the grace period.
	Agents []PKIKeyRotationAgent `json:"agents,omitempty"`

	// The fingerprint of the key that the controller signs jobs with.
	Current string `json:"current"`

	// The fingerprint of the key that the controller switches to. Empty when no
	// rotation is in progress.
	Next string `json:"next,omitempty"`

	// When the rotation started.
	StartedAt time.Time `json:"started_at,omitzero"`

	// When the controller switches at the latest: the start and
	// controller.pki.rotation_grace_period. It switches before, once each agent
	// has the next key.
	SwitchBy time.Time `json:"switch_by,omitzero"`
}

PKIKeyRotation is the PKIKeyRotation of the spec.

type PKIKeyRotationAgent added in v0.3.0

type PKIKeyRotationAgent struct {
	// Whether the agent reports that it has the next key.
	HasNext bool `json:"has_next"`

	// The hostname of the agent.
	Hostname string `json:"hostname"`

	// The machine ID of the agent.
	MachineID string `json:"machine_id"`
}

PKIKeyRotationAgent is the PKIKeyRotationAgent of the spec.

type PKINATSCertRotation added in v0.3.0

type PKINATSCertRotation struct {
	// The admitted agents that the switch waits for: each one that reported within
	// the grace period.
	Agents []PKINATSCertRotationAgent `json:"agents,omitempty"`

	// The fingerprint of the certificate that the NATS server serves.
	Current string `json:"current"`

	// The fingerprint of the certificate that the server switches to. Empty when
	// no rotation is in progress.
	Next string `json:"next,omitempty"`

	// When the rotation started.
	StartedAt time.Time `json:"started_at,omitzero"`

	// When the server switches at the latest: the start and
	// controller.pki.rotation_grace_period. It switches before, once each agent
	// trusts the next certificate.
	SwitchBy time.Time `json:"switch_by,omitzero"`
}

PKINATSCertRotation is the PKINATSCertRotation of the spec.

type PKINATSCertRotationAgent added in v0.3.0

type PKINATSCertRotationAgent struct {
	// Whether the agent reports that it trusts the next certificate.
	HasNext bool `json:"has_next"`

	// The hostname of the agent.
	Hostname string `json:"hostname"`

	// The machine ID of the agent.
	MachineID string `json:"machine_id"`
}

PKINATSCertRotationAgent is the PKINATSCertRotationAgent of the spec.

type PackageCreateInput added in v0.3.0

type PackageCreateInput struct {
	// The package to install, such as curl.
	Name string `json:"name"`

	// The version to install, such as 8.5.0-2ubuntu10; the newest when empty.
	Version string `json:"version,omitempty"`
}

PackageCreateInput is the input of PackageService.Create. A field of the path goes in the path, and each other field in the body.

type PackageInstalled added in v0.3.0

type PackageInstalled struct {
	// The architecture it is built for, such as amd64.
	Architecture string `json:"architecture,omitempty"`

	// Its one-line summary.
	Description string `json:"description,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The package database that has it: dpkg, rpm or brew.
	Manager string `json:"manager,omitempty"`

	// The package.
	Name string `json:"name,omitempty"`

	// Its installed size in bytes.
	Size int64 `json:"size,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// The installed version.
	Version string `json:"version,omitempty"`
}

PackageInstalled is the PackageInstalled of the spec.

type PackageResult added in v0.3.0

type PackageResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The package.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

PackageResult is the PackageResult of the spec.

type PackageService

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

PackageService calls the API's Package group: the packages installed on the host.

func (*PackageService) Create added in v0.3.0

Create is the operation PostNodePackage: install a package.

Installs the package with apt-get install, at the version when one is given. A package that is installed, at that version when one is given, does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped.

It sends POST /api/node/{hostname}/package, and needs the permission package:write.

func (*PackageService) Delete added in v0.3.0

func (s *PackageService) Delete(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[PackageResult]], error)

Delete is the operation DeleteNodePackage: remove a package.

Removes the package with apt-get remove. A package that is not installed does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped.

It sends DELETE /api/node/{hostname}/package/{name}, and needs the permission package:write.

func (*PackageService) Get

func (s *PackageService) Get(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[PackageInstalled]], error)

Get is the operation GetNodePackageByKey: get one installed package.

Reads one package from the same list. A package that is not installed is not found.

It sends GET /api/node/{hostname}/package/{name}, and needs the permission package:read.

func (*PackageService) List

List is the operation GetNodePackage: list the packages installed on the host.

Lists each installed package with its version: dpkg on the Debian family, rpm on the other Linux families, and Homebrew on macOS.

It sends GET /api/node/{hostname}/package, and needs the permission package:read.

type PackageUpdatesAvailable added in v0.3.0

type PackageUpdatesAvailable struct {
	// The installed version.
	CurrentVersion string `json:"current_version,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The package.
	Name string `json:"name,omitempty"`

	// The version the index has.
	NewVersion string `json:"new_version,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

PackageUpdatesAvailable is the PackageUpdatesAvailable of the spec.

type PackageUpdatesResult added in v0.3.0

type PackageUpdatesResult struct {
	// Whether the refresh got new index data.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

PackageUpdatesResult is the PackageUpdatesResult of the spec.

type PackageUpdatesService added in v0.3.0

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

PackageUpdatesService calls the API's PackageUpdates group: the updates the package index has for the host.

func (*PackageUpdatesService) List added in v0.3.0

List is the operation GetNodePackageUpdates: list the packages the index has newer versions of.

Runs apt list --upgradable: each package with its installed version and the version the index has. Refresh the index first for what the repositories have now.

It sends GET /api/node/{hostname}/package/updates, and needs the permission package:read.

func (*PackageUpdatesService) Update added in v0.3.0

Update is the operation PutNodePackageUpdates: refresh the package index.

Runs apt-get update. It reports changed: true when the Release file of a repository under /var/lib/apt/lists changed, and changed: false when each repository was unchanged.

It sends PUT /api/node/{hostname}/package/updates, and needs the permission package:write.

type PkiGetParams added in v0.3.0

type PkiGetParams struct {
	// Hostname is the hostname of the query: the host of the certificate. Empty is
	// the controller's host, which has the certificates of the controller. The
	// zero value leaves it out.
	Hostname string
}

PkiGetParams are the parameters of PkiService.Get that a request can leave out.

type PkiListParams added in v0.3.0

type PkiListParams struct {
	// Hostname is the hostname of the query: only the certificates of this host:
	// the controller's hostname, or an agent's. The zero value leaves it out.
	Hostname string
}

PkiListParams are the parameters of PkiService.List that a request can leave out.

type PkiService added in v0.3.0

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

PkiService calls the API's Pki group: the certificates of the fleet, and the rotation of the controller's key and of the NATS server's certificate.

func (*PkiService) Get added in v0.3.0

func (s *PkiService) Get(
	ctx context.Context,
	name string,
	params PkiGetParams,
) (*Response[PKICert], error)

Get is the operation GetPKICert: get one certificate of a host.

Reads one certificate of one host: the controller's host when the hostname is empty, or the agent of the hostname.

It sends GET /api/pki/cert/{name}, and needs the permission pki:read.

func (*PkiService) List added in v0.3.0

func (s *PkiService) List(
	ctx context.Context,
	params PkiListParams,
) (*Response[PKICertList], error)

List is the operation ListPKICerts: list the certificates of the fleet.

Lists the certificates of the controller's host, the API's, the controller's metrics and the NATS server's, and the certificates that each agent reports in its registration, with their expiry. A certificate that a host has not made is not made.

It sends GET /api/pki/cert, and needs the permission pki:read.

func (*PkiService) Natscertrotate added in v0.3.0

func (s *PkiService) Natscertrotate(
	ctx context.Context,
) (*Response[PKINATSCertRotation], error)

Natscertrotate is the operation RotatePKINATSCert: rotate the NATS server's certificate.

Starts the rotation of the NATS server's self-signed certificate, which each joined agent pins, with no restart and no new join. The controller makes the next certificate beside the current one, and signs a record that gives both to the agents. Each agent trusts the next one at its next heartbeat. The controller renames it into place when each admitted agent that reported within controller.pki.rotation_grace_period trusts it, or when the grace period ends, and NATS serves it at its next handshake. A rotation in progress is not started again. It runs on the controller's host, which must hold the NATS server's certificate, and refuses a certificate of the operator's cert_file.

It sends POST /api/pki/nats, and needs the permission pki:write.

func (*PkiService) Natscertrotation added in v0.3.0

func (s *PkiService) Natscertrotation(
	ctx context.Context,
) (*Response[PKINATSCertRotation], error)

Natscertrotation is the operation GetPKINATSCertRotation: show the rotation of the NATS server's certificate.

Shows the certificate that the NATS server serves, and during a rotation the certificate that it switches to, when it switches at the latest, and each admitted agent that the switch waits for, with whether it trusts the next certificate.

It sends GET /api/pki/nats, and needs the permission pki:read.

func (*PkiService) Rotate added in v0.3.0

func (s *PkiService) Rotate(
	ctx context.Context,
) (*Response[PKIKeyRotation], error)

Rotate is the operation RotatePKIKey: rotate the controller's key.

Starts the rotation of the controller's key, with no new admission of the agents. The controller makes the next key, and signs a record that gives it to the agents with its current key. Each agent takes it at its next heartbeat. The controller switches to the next key when each admitted agent that reported within controller.pki.rotation_grace_period has it, or when the grace period ends. An agent that does not have it then needs a new admission. A rotation in progress is not started again.

It sends POST /api/pki/key, and needs the permission pki:write.

func (*PkiService) Rotation added in v0.3.0

func (s *PkiService) Rotation(
	ctx context.Context,
) (*Response[PKIKeyRotation], error)

Rotation is the operation GetPKIKeyRotation: show the rotation of the controller's key.

Shows the key that the controller signs jobs with, and during a rotation the key that it switches to, when it switches at the latest, and each admitted agent that the switch waits for, with whether it has the next key.

It sends GET /api/pki/key, and needs the permission pki:read.

type PowerRebootInput added in v0.3.0

type PowerRebootInput struct {
	// Seconds before the host goes down. It rounds to whole minutes, at least one.
	Delay int `json:"delay,omitempty"`

	// A message to the logged-in users first.
	Message string `json:"message,omitempty"`
}

PowerRebootInput is the input of PowerService.Reboot. A field of the path goes in the path, and each other field in the body.

type PowerResult

type PowerResult struct {
	// reboot or shutdown.
	Action string `json:"action,omitempty"`

	// Always true: each run changes the host.
	Changed bool `json:"changed,omitempty"`

	// Seconds before the host goes down.
	Delay int `json:"delay,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

PowerResult is the PowerResult of the spec.

type PowerService

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

PowerService calls the API's Power group: reboot or shut down the host.

func (*PowerService) Reboot

func (s *PowerService) Reboot(
	ctx context.Context,
	hostname string,
	input PowerRebootInput,
) (*Response[Collection[PowerResult]], error)

Reboot is the operation PostNodePowerReboot: reboot the host.

Runs shutdown -r -- +N, with N the delay in whole minutes and at least one, so the agent can answer before the host goes down. A message goes to the logged-in users. Each run changes the host.

It sends POST /api/node/{hostname}/power/reboot, and needs the permission power:execute.

func (*PowerService) Shutdown

func (s *PowerService) Shutdown(
	ctx context.Context,
	hostname string,
	input PowerShutdownInput,
) (*Response[Collection[PowerResult]], error)

Shutdown is the operation PostNodePowerShutdown: shut the host down.

Runs shutdown -h -- +N, with N the delay in whole minutes and at least one, so the agent can answer before the host goes down. A message goes to the logged-in users. Each run changes the host.

It sends POST /api/node/{hostname}/power/shutdown, and needs the permission power:execute.

type PowerShutdownInput added in v0.3.0

type PowerShutdownInput struct {
	// Seconds before the host goes down. It rounds to whole minutes, at least one.
	Delay int `json:"delay,omitempty"`

	// A message to the logged-in users first.
	Message string `json:"message,omitempty"`
}

PowerShutdownInput is the input of PowerService.Shutdown. A field of the path goes in the path, and each other field in the body.

type Priority added in v0.3.0

type Priority string

Priority: Only the entries at this priority or above.

const (
	PriorityEmerg   Priority = "emerg"
	PriorityAlert   Priority = "alert"
	PriorityCrit    Priority = "crit"
	PriorityErr     Priority = "err"
	PriorityWarning Priority = "warning"
	PriorityNotice  Priority = "notice"
	PriorityInfo    Priority = "info"
	PriorityDebug   Priority = "debug"
)

The values of Priority.

type ProcessEntry added in v0.3.0

type ProcessEntry struct {
	// Its full command line.
	Command string `json:"command,omitempty"`

	// Its CPU time as a percent of the time since it started.
	CPUPercent float64 `json:"cpu_percent,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Its resident memory as a percent of the host's memory.
	MemPercent float64 `json:"mem_percent,omitempty"`

	// Its resident memory in bytes.
	MemRSS int64 `json:"mem_rss,omitempty"`

	// The name of the process.
	Name string `json:"name,omitempty"`

	// The process ID.
	PID int `json:"pid,omitempty"`

	// When it started, in RFC 3339.
	StartTime string `json:"start_time,omitempty"`

	// Its state, such as running or sleep.
	State string `json:"state,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// The user that runs it.
	User string `json:"user,omitempty"`
}

ProcessEntry is the ProcessEntry of the spec.

type ProcessResult added in v0.3.0

type ProcessResult struct {
	// Whether the signal was sent.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The process ID.
	PID int `json:"pid,omitempty"`

	// Signal is a signal that osapi sends to a process, by its name without SIG.
	Signal types.Signal `json:"signal,omitzero"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

ProcessResult is the ProcessResult of the spec.

type ProcessService

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

ProcessService calls the API's Process group: the processes of the host.

func (*ProcessService) Get

func (s *ProcessService) Get(
	ctx context.Context,
	hostname string,
	pid int,
) (*Response[Collection[ProcessEntry]], error)

Get is the operation GetNodeProcessByKey: get one process.

Reads one process by its ID, without the others. A process that the host does not have is not found.

It sends GET /api/node/{hostname}/process/{pid}, and needs the permission process:read.

func (*ProcessService) List

func (s *ProcessService) List(
	ctx context.Context,
	hostname string,
) (*Response[Collection[ProcessEntry]], error)

List is the operation GetNodeProcess: list the processes of the host.

Lists each process with its user, state, CPU and memory, its command line and when it started, through gohai: from /proc on Linux and from ps on macOS. A process that stops while the list is read is not in it.

It sends GET /api/node/{hostname}/process, and needs the permission process:read.

func (*ProcessService) Signal

Signal is the operation PostNodeProcessSignal: send a signal to a process.

Sends TERM, KILL, HUP, INT, USR1 or USR2 to one process with kill, and reports changed: true. A process that the host does not have is not found. A process ID below 1 is refused, because kill sends to a group of processes for 0 and for a negative ID.

It sends POST /api/node/{hostname}/process/{pid}/signal, and needs the permission process:execute.

type ProcessSignalInput added in v0.3.0

type ProcessSignalInput struct {
	// The pid of the path: the process ID, such as 1234.
	PID int `json:"-"`

	// Signal is a signal that osapi sends to a process, by its name without SIG.
	Signal types.Signal `json:"signal"`
}

ProcessSignalInput is the input of ProcessService.Signal. A field of the path goes in the path, and each other field in the body.

type ReadyResponse added in v0.3.0

type ReadyResponse struct {
	// Error message when not ready.
	Error string `json:"error,omitempty"`

	// Readiness status.
	Status string `json:"status"`
}

ReadyResponse is the ReadyResponse of the spec.

type Release added in v0.3.0

type Release struct {
	// The distribution, such as ubuntu, or darwin.
	Distribution string `json:"distribution"`

	// The version of the distribution, such as 24.04.
	Version string `json:"version"`
}

Release is the Release of the spec.

type Response

type Response[T any] struct {
	Data T
	// contains filtered or unexported fields
}

Response wraps a domain type with raw JSON for CLI --json mode.

func NewResponse

func NewResponse[T any](
	data T,
	rawJSON []byte,
) *Response[T]

NewResponse creates a Response with the given data and raw JSON body.

func (*Response[T]) RawJSON

func (r *Response[T]) RawJSON() []byte

RawJSON returns the raw HTTP response body.

func (*Response[T]) TraceID added in v0.3.0

func (r *Response[T]) TraceID() string

TraceID returns the ID of the trace of the request, from the traceresponse header of the controller. It is empty when the controller did not trace the request. Search the tracing backend for it to see the whole request: the controller, the queue, and the work of each agent.

type RouteResponse added in v0.3.0

type RouteResponse struct {
	// Destination network address.
	Destination string `json:"destination"`

	// Gateway address.
	Gateway string `json:"gateway"`

	// Network interface name.
	Interface string `json:"interface"`

	// Network mask in CIDR notation.
	Mask string `json:"mask,omitempty"`

	// Route metric.
	Metric int `json:"metric,omitempty"`
}

RouteResponse: A network routing table entry.

type ScheduleCreateInput added in v0.3.0

type ScheduleCreateInput struct {
	// ContentType is how a deploy treats a file: raw writes its bytes as they are;
	// template renders it with Go text/template and the agent's facts.
	ContentType types.ContentType `json:"content_type,omitzero"`

	// Interval is how often a scheduled job runs, in place of a cron schedule.
	Interval types.Interval `json:"interval,omitzero"`

	// The entry, and its file name, such as backup.
	Name string `json:"name"`

	// The object that holds the entry, from osapi client file upload.
	Object string `json:"object"`

	// A cron expression, such as */5 * * * *; give it or interval.
	Schedule string `json:"schedule,omitempty"`

	// The user the entry runs as.
	User string `json:"user,omitempty"`

	// The vars of a template, as key=value.
	Vars map[string]string `json:"vars,omitempty"`
}

ScheduleCreateInput is the input of ScheduleService.Create. A field of the path goes in the path, and each other field in the body.

type ScheduleEntry added in v0.3.0

type ScheduleEntry struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Its interval, for a script in /etc/cron.daily and the like.
	Interval string `json:"interval,omitempty"`

	// The entry.
	Name string `json:"name,omitempty"`

	// The object it was deployed from.
	Object string `json:"object,omitempty"`

	// Its cron expression, for an entry in /etc/cron.d.
	Schedule string `json:"schedule,omitempty"`

	// Where its file is: cron.d, or the interval.
	Source string `json:"source,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// The user it runs as.
	User string `json:"user,omitempty"`
}

ScheduleEntry is the ScheduleEntry of the spec.

type ScheduleResult added in v0.3.0

type ScheduleResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The entry.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

ScheduleResult is the ScheduleResult of the spec.

type ScheduleService added in v0.2.0

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

ScheduleService calls the API's Schedule group: the cron entries that osapi deploys.

func (*ScheduleService) Create added in v0.2.0

Create is the operation PostNodeSchedule: deploy a cron entry.

Gets the object from the object store and writes it as /etc/cron.d/backup for backup, mode 0644, for a cron expression, or as /etc/cron.daily/backup, mode 0755, for a daily interval. An object of content type template, or content_type template, is rendered with the agent's facts and the vars. A file that has the content does not change. An entry of the name in a different directory does not change: move it with delete and create. A file at the path that osapi did not deploy is refused. An entry runs as its user, root included, so only admin can deploy one.

It sends POST /api/node/{hostname}/schedule, and needs the permission schedule:write.

func (*ScheduleService) Delete added in v0.2.0

func (s *ScheduleService) Delete(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[ScheduleResult]], error)

Delete is the operation DeleteNodeSchedule: remove a cron entry that osapi deployed.

Removes the entry's file and its record. An entry that osapi did not deploy does not change, and a cron file that osapi did not deploy stays.

It sends DELETE /api/node/{hostname}/schedule/{name}, and needs the permission schedule:write.

func (*ScheduleService) Get added in v0.2.0

func (s *ScheduleService) Get(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[ScheduleEntry]], error)

Get is the operation GetNodeScheduleByKey: get one cron entry that osapi deployed.

Reads the entry from /etc/cron.d, then from each interval directory. An entry that osapi did not deploy is not found.

It sends GET /api/node/{hostname}/schedule/{name}, and needs the permission schedule:read.

func (*ScheduleService) List added in v0.2.0

func (s *ScheduleService) List(
	ctx context.Context,
	hostname string,
) (*Response[Collection[ScheduleEntry]], error)

List is the operation GetNodeSchedule: list the cron entries that osapi deployed.

Lists each file in /etc/cron.d and in /etc/cron.hourly, daily, weekly and monthly that osapi deployed, with its object, its cron expression or interval, and its user. A cron file that osapi did not deploy is not listed.

It sends GET /api/node/{hostname}/schedule, and needs the permission schedule:read.

func (*ScheduleService) Update added in v0.2.0

Update is the operation PutNodeSchedule: deploy a cron entry that osapi deployed again.

Writes a new object, or the entry's own, at the entry's path, with the fields that the request gives and the entry's own for the rest. A file that has the content does not change. An entry that osapi did not deploy is not found. The entry stays in its directory: an interval does not change with update.

It sends PUT /api/node/{hostname}/schedule/{name}, and needs the permission schedule:write.

type ScheduleUpdateInput added in v0.3.0

type ScheduleUpdateInput struct {
	// The name of the path: the entry, such as backup.
	Name string `json:"-"`

	// ContentType is how a deploy treats a file: raw writes its bytes as they are;
	// template renders it with Go text/template and the agent's facts.
	ContentType types.ContentType `json:"content_type,omitzero"`

	// The object to deploy; the entry's own when empty.
	Object string `json:"object,omitempty"`

	// A new cron expression; the entry's own when empty.
	Schedule string `json:"schedule,omitempty"`

	// The user the entry runs as; the entry's own when empty.
	User string `json:"user,omitempty"`

	// The vars of a template, as key=value.
	Vars map[string]string `json:"vars,omitempty"`
}

ScheduleUpdateInput is the input of ScheduleService.Update. A field of the path goes in the path, and each other field in the body.

type SecretInfo added in v0.3.0

type SecretInfo struct {
	// Who did the last update, or empty when it is not known.
	By string `json:"by"`

	// When the last update occurred.
	Changed time.Time `json:"changed"`

	// The name of the key.
	Key string `json:"key"`

	// The name of the vault.
	Vault string `json:"vault"`

	// 1 for the first value of the key, and one more for each update.
	Version int64 `json:"version"`
}

SecretInfo is the SecretInfo of the spec.

type SecretListResponse added in v0.3.0

type SecretListResponse struct {
	// The keys of the vault, sorted by key.
	Items []SecretInfo `json:"items"`

	// The number of keys.
	TotalItems int `json:"total_items"`
}

SecretListResponse is the SecretListResponse of the spec.

type SecretService added in v0.3.0

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

SecretService calls the API's Secret group: the vaults of the controller and the metadata of their keys. No operation gives a value.

func (*SecretService) Delete added in v0.3.0

func (s *SecretService) Delete(
	ctx context.Context,
	vault string,
	key string,
) error

Delete is the operation DeleteSecret: delete a key.

Delete a key from its vault. A request that uses its reference after that fails.

It sends DELETE /api/secret/{vault}/{key}, and needs the permission secret:write.

func (*SecretService) Get added in v0.3.0

func (s *SecretService) Get(
	ctx context.Context,
	vault string,
	key string,
) (*Response[SecretInfo], error)

Get is the operation GetSecret: get the metadata of a key.

Get the version of a key, when it changed and who changed it. The answer has no value.

It sends GET /api/secret/{vault}/{key}, and needs the permission secret:read.

func (*SecretService) List added in v0.3.0

func (s *SecretService) List(
	ctx context.Context,
	vault string,
) (*Response[SecretListResponse], error)

List is the operation GetSecrets: list the keys of a vault.

List the metadata of each key of a vault: its version, when it changed and who changed it. The list has no value.

It sends GET /api/secret/{vault}, and needs the permission secret:read.

func (*SecretService) Reveal added in v0.3.0

func (s *SecretService) Reveal(
	ctx context.Context,
	vault string,
	key string,
) (*Response[SecretValue], error)

Reveal is the operation GetSecretValue: reveal the value of a key.

Get the value of a key, for a tool that needs the value itself. It is the one method that gives a value, and it needs secret:reveal, which only the admin role has. The audit log records each call, with the vault, the key and the caller, and never the value.

It sends GET /api/secret/{vault}/{key}/value, and needs the permission secret:reveal.

func (*SecretService) Update added in v0.3.0

func (s *SecretService) Update(
	ctx context.Context,
	input SecretUpdateInput,
) (*Response[SecretInfo], error)

Update is the operation PutSecret: write the value of a key.

Write a value as the next version of a key, or as version 1 of a new key. The answer is the metadata of the key. The API never gives the value back.

It sends PUT /api/secret/{vault}/{key}, and needs the permission secret:write.

func (*SecretService) Vaults added in v0.3.0

Vaults is the operation GetSecretVaults: list the vaults.

List each vault of controller.secrets.vaults, with its type, its targets and whether it answers.

It sends GET /api/secret, and needs the permission secret:read.

type SecretUpdateInput added in v0.3.0

type SecretUpdateInput struct {
	// The vault of the path: the name of the vault, such as default.
	Vault string `json:"-"`

	// The key of the path: the name of the key, such as registry-token.
	Key string `json:"-"`

	// The value of the key, which no method gives back. A secret: a reference,
	// secret://<vault>/<key>, or the value.
	Value string `json:"value"`
}

SecretUpdateInput is the input of SecretService.Update. A field of the path goes in the path, and each other field in the body.

type SecretValue added in v0.3.0

type SecretValue struct {
	// The value of the key.
	Value string `json:"value"`
}

SecretValue is the SecretValue of the spec.

type ServerError

type ServerError struct {
	APIError
}

ServerError represents internal server errors (500).

func (*ServerError) Unwrap

func (e *ServerError) Unwrap() error

Unwrap returns the underlying APIError.

type ServiceCreateInput added in v0.3.0

type ServiceCreateInput struct {
	// The service, such as app for osapi-app.service.
	Name string `json:"name"`

	// The object that holds the unit file, from osapi client file upload.
	Object string `json:"object"`
}

ServiceCreateInput is the input of ServiceService.Create. A field of the path goes in the path, and each other field in the body.

type ServiceEntry added in v0.3.0

type ServiceEntry struct {
	// The Description= of its unit.
	Description string `json:"description,omitempty"`

	// Whether it starts at boot: the state of its unit file.
	Enabled bool `json:"enabled,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Whether osapi deployed it, so its writes and actions act on it.
	Managed bool `json:"managed,omitempty"`

	// The service, without .service.
	Name string `json:"name,omitempty"`

	// What systemd says it does now, such as running, exited or dead.
	State string `json:"state,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

ServiceEntry is the ServiceEntry of the spec.

type ServiceResult added in v0.3.0

type ServiceResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The service.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

ServiceResult is the ServiceResult of the spec.

type ServiceService

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

ServiceService calls the API's Service group: the services of the host: systemd on Linux, launchd on macOS.

func (*ServiceService) Create

Create is the operation PostNodeService: deploy a service.

Gets the object from the object store and writes it as the unit file of the service, such as /etc/systemd/system/osapi-app.service for app, then reloads systemd. A unit file at that path that osapi did not write, such as the agent's own osapi-agent.service, is refused. A unit file that already has the content does not change. The service does not start: start and enable are their own actions. On a Mac, the object is the plist of the daemon, /Library/LaunchDaemons/io.osapi.app.plist for app, with the label io.osapi.app, and launchd does not load it until start.

It sends POST /api/node/{hostname}/service, and needs the permission service:write.

func (*ServiceService) Delete

func (s *ServiceService) Delete(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[ServiceResult]], error)

Delete is the operation DeleteNodeService: remove a service that osapi deployed.

Stops and disables the service, removes its unit file and reloads systemd. A service with no unit file does not change. On a Mac, it boots the daemon out of launchd when it is loaded, and removes its plist.

It sends DELETE /api/node/{hostname}/service/{name}, and needs the permission service:write.

func (*ServiceService) Disable

func (s *ServiceService) Disable(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[ServiceResult]], error)

Disable is the operation PostNodeServiceDisable: make a service that osapi deployed not start at boot.

Disables the service. A service that is not enabled does not change. A service that osapi did not deploy is not found.

It sends POST /api/node/{hostname}/service/{name}/disable, and needs the permission service:execute.

func (*ServiceService) Enable

func (s *ServiceService) Enable(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[ServiceResult]], error)

Enable is the operation PostNodeServiceEnable: make a service that osapi deployed start at boot.

Enables the service. A service that is enabled does not change, and nor does a unit with no [Install] section, which systemd calls static: it cannot start at boot. A service that osapi did not deploy is not found.

It sends POST /api/node/{hostname}/service/{name}/enable, and needs the permission service:execute.

func (*ServiceService) Get

func (s *ServiceService) Get(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[ServiceEntry]], error)

Get is the operation GetNodeServiceByKey: get one service.

Reads one service from the same list, by its name with .service or without it. A service that osapi deployed reads by the name it was deployed with, such as app, as its writes take it, or by its unit's name, osapi-app. A service that systemd has not loaded is not found. On a Mac, a daemon that osapi deployed and launchd has not loaded is dead.

It sends GET /api/node/{hostname}/service/{name}, and needs the permission service:read.

func (*ServiceService) List

func (s *ServiceService) List(
	ctx context.Context,
	hostname string,
) (*Response[Collection[ServiceEntry]], error)

List is the operation GetNodeService: list the services of the host.

Lists each service that systemd has loaded, with its state, whether it starts at boot and its description, through gohai. A service that osapi deployed shows by the name it was deployed with, not its unit's osapi- name, and is managed. On a Mac, it lists each daemon that launchd has loaded in the system domain, by its label. A daemon that osapi deployed reads by the name it was deployed with, app for io.osapi.app.

It sends GET /api/node/{hostname}/service, and needs the permission service:read.

func (*ServiceService) Restart

func (s *ServiceService) Restart(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[ServiceResult]], error)

Restart is the operation PostNodeServiceRestart: restart a service that osapi deployed.

Restarts the service. It always changes the host. A service that osapi did not deploy is not found.

It sends POST /api/node/{hostname}/service/{name}/restart, and needs the permission service:execute.

func (*ServiceService) Start

func (s *ServiceService) Start(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[ServiceResult]], error)

Start is the operation PostNodeServiceStart: start a service that osapi deployed.

Starts the service. A service that runs does not change. A service that osapi did not deploy is not found.

It sends POST /api/node/{hostname}/service/{name}/start, and needs the permission service:execute.

func (*ServiceService) Stop

func (s *ServiceService) Stop(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[ServiceResult]], error)

Stop is the operation PostNodeServiceStop: stop a service that osapi deployed.

Stops the service. A service that does not run does not change. A service that osapi did not deploy is not found.

It sends POST /api/node/{hostname}/service/{name}/stop, and needs the permission service:execute.

func (*ServiceService) Update

Update is the operation PutNodeService: deploy a new unit file for a service.

Writes the object as the unit file of a service that osapi deployed, then reloads systemd when the file changed. A service that osapi did not deploy is not found. On a Mac, it writes the plist, and a daemon that runs keeps its old plist until restart.

It sends PUT /api/node/{hostname}/service/{name}, and needs the permission service:write.

type ServiceSpec added in v0.3.0

type ServiceSpec struct {
	// Name is the field of the service on Client, such as Hostname.
	Name string `json:"name"`
	// Doc is what the service does.
	Doc string `json:"doc"`
	// Area is the area of the API it is in, such as node.
	Area string `json:"area,omitempty"`
	// Node is true for a service of a node, whose methods take a target.
	Node bool `json:"node"`
	// Methods are its methods.
	Methods []MethodSpec `json:"methods"`
}

ServiceSpec is one service of the client, such as Hostname: what it does and each of its methods. Services lists them, so a program or an agent reads what the client can call from the client itself.

func Services added in v0.3.0

func Services() []ServiceSpec

Services is each service of the client and its methods, by the order of the spec.

type ServiceUpdateInput added in v0.3.0

type ServiceUpdateInput struct {
	// The name of the path: the service, such as app for osapi-app.service.
	Name string `json:"-"`

	// The object that holds the unit file, from osapi client file upload.
	Object string `json:"object"`
}

ServiceUpdateInput is the input of ServiceService.Update. A field of the path goes in the path, and each other field in the body.

type StaleDeployment

type StaleDeployment struct {
	// SHA-256 hash of the current object store content.
	CurrentSHA string `json:"current_sha"`

	// When the file was last deployed.
	DeployedAt string `json:"deployed_at"`

	// SHA-256 of the object when it was deployed.
	DeployedSHA string `json:"deployed_sha"`

	// Host where the file is deployed.
	Hostname string `json:"hostname"`

	// Name of the object in the Object Store.
	ObjectName string `json:"object_name"`

	// Deployment path on the target host.
	Path string `json:"path"`

	// Provider that manages this deployment.
	Provider string `json:"provider"`
}

StaleDeployment is the StaleDeployment of the spec.

type StaleDeploymentsResponse added in v0.3.0

type StaleDeploymentsResponse struct {
	// The stale deployments.
	Items []StaleDeployment `json:"items"`

	// Total number of stale deployments.
	TotalItems int `json:"total_items"`
}

StaleDeploymentsResponse is the StaleDeploymentsResponse of the spec.

type StatusEntry added in v0.3.0

type StatusEntry struct {
	// Each local filesystem.
	Disks []Disk `json:"disks,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Each read that failed, as name: error. The other fields still answer.
	Errors []string `json:"errors,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// LoadAverage is the property load_average.
	LoadAverage Averages `json:"load_average,omitzero"`

	// Memory is the property memory.
	Memory Usage `json:"memory,omitzero"`

	// The hostname of the host, as the hostname command prints it.
	Name string `json:"name,omitempty"`

	// OSInfo is the property os_info.
	OSInfo Release `json:"os_info,omitzero"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// Uptime is the property uptime.
	Uptime Entry `json:"uptime,omitzero"`
}

StatusEntry is the StatusEntry of the spec.

type StatusResponse added in v0.3.0

type StatusResponse struct {
	// Agents is the property agents.
	Agents AgentStats `json:"agents,omitzero"`

	// What the controller that answered checked for this answer: its connection to
	// NATS and to the KV store.
	Checks []Check `json:"checks"`

	// Total number of JetStream consumers: the sum of the consumers of each
	// stream.
	Consumers int `json:"consumers"`

	// Jobs is the property jobs.
	Jobs JobStats `json:"jobs,omitzero"`

	// KV bucket statistics.
	KVBuckets []KVBucketInfo `json:"kv_buckets,omitempty"`

	// NATS is the property nats.
	NATS NATSInfo `json:"nats,omitzero"`

	// Object Store statistics.
	ObjectStores []ObjectStoreInfo `json:"object_stores,omitempty"`

	// All registered components with health details, each with its sub-components.
	Registry []ComponentEntry `json:"registry,omitempty"`

	// Overall health status.
	Status string `json:"status"`

	// JetStream stream statistics.
	Streams []StreamInfo `json:"streams,omitempty"`

	// Time since server started.
	Uptime string `json:"uptime"`

	// Application version.
	Version string `json:"version"`
}

StatusResponse is the StatusResponse of the spec.

type StatusService

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

StatusService calls the API's Status group: the status summary of a node.

func (*StatusService) Get

func (s *StatusService) Get(
	ctx context.Context,
	hostname string,
) (*Response[Collection[StatusEntry]], error)

Get is the operation GetNodeStatus: get the status summary of the host.

Runs the get of the hostname, uptime, os, load, memory and disk behaviors on the host, and answers with each. A read that fails is in errors, as its name and its error, and the other fields still answer.

It sends GET /api/node/{hostname}/status, and needs the permission status:read.

type StreamInfo

type StreamInfo struct {
	// Total bytes in the stream.
	Bytes int `json:"bytes"`

	// Number of consumers on the stream.
	Consumers int `json:"consumers"`

	// Number of messages in the stream.
	Messages int `json:"messages"`

	// Stream name.
	Name string `json:"name"`
}

StreamInfo is the StreamInfo of the spec.

type SysctlCreateInput added in v0.3.0

type SysctlCreateInput struct {
	// Parameter name, such as net.ipv4.ip_forward.
	Key string `json:"key"`

	// Value to set.
	Value string `json:"value"`
}

SysctlCreateInput is the input of SysctlService.Create. A field of the path goes in the path, and each other field in the body.

type SysctlEntry added in v0.3.0

type SysctlEntry struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Parameter name.
	Key string `json:"key,omitempty"`

	// Whether osapi manages it: a file of its own sets it at boot.
	Managed bool `json:"managed,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// Current runtime value.
	Value string `json:"value,omitempty"`
}

SysctlEntry is the SysctlEntry of the spec.

type SysctlListParams added in v0.3.0

type SysctlListParams struct {
	// Prefix is the prefix of the query: only this parameter and the ones under
	// it, such as net.ipv4. The zero value leaves it out.
	Prefix string
}

SysctlListParams are the parameters of SysctlService.List that a request can leave out.

type SysctlMutationResult

type SysctlMutationResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Parameter name.
	Key string `json:"key,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

SysctlMutationResult is the SysctlMutationResult of the spec.

type SysctlService

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

SysctlService calls the API's Sysctl group: kernel parameters, written to sysctl.d files and applied.

func (*SysctlService) Create

Create is the operation PostNodeSysctl: manage a kernel parameter and apply it.

Writes osapi-net.ipv4.ip_forward.conf for net.ipv4.ip_forward to behaviors.sysctl.dir, /etc/sysctl.d by default, and applies it with sysctl -p. It fails when sysctl -p fails, because the value is not set. A second run with the same value changes nothing and reports changed: false. If the kernel has a different value, for example after a failed apply, it applies the value again.

It sends POST /api/node/{hostname}/sysctl, and needs the permission sysctl:write.

func (*SysctlService) Delete

func (s *SysctlService) Delete(
	ctx context.Context,
	hostname string,
	key string,
) (*Response[Collection[SysctlMutationResult]], error)

Delete is the operation DeleteNodeSysctl: stop the management of a kernel parameter.

Removes the file that osapi wrote for it and reloads with sysctl --system. Then a setting for the key in a different file takes effect. If there is no such setting, the parameter keeps its current value until the next reboot. A delete of a parameter that osapi does not manage reports changed: false.

It sends DELETE /api/node/{hostname}/sysctl/{key}, and needs the permission sysctl:write.

func (*SysctlService) Get

func (s *SysctlService) Get(
	ctx context.Context,
	hostname string,
	key string,
) (*Response[Collection[SysctlEntry]], error)

Get is the operation GetNodeSysctlByKey: get a kernel parameter's current value, and whether osapi manages it.

It sends GET /api/node/{hostname}/sysctl/{key}, and needs the permission sysctl:read.

func (*SysctlService) List

func (s *SysctlService) List(
	ctx context.Context,
	hostname string,
	params SysctlListParams,
) (*Response[Collection[SysctlEntry]], error)

List is the operation GetNodeSysctl: list the kernel's parameters and which osapi manages.

Lists every parameter the kernel shows under /proc/sys, with its current value, as sysctl -a does, and marks the ones osapi manages. A prefix, such as net.ipv4, limits the list to that part of the tree. The kernel can lack a parameter that osapi manages, for example when its module is not loaded. Then the list shows the value that osapi wrote.

It sends GET /api/node/{hostname}/sysctl, and needs the permission sysctl:read.

func (*SysctlService) Update

Update is the operation PutNodeSysctl: set a kernel parameter, manage it, and apply it.

The same as create, addressed by the parameter: osapi manages the parameter from then on whether it did before or not. Setting the value it already has reports changed: false.

It sends PUT /api/node/{hostname}/sysctl/{key}, and needs the permission sysctl:write.

type SysctlUpdateInput added in v0.3.0

type SysctlUpdateInput struct {
	// The key of the path: parameter name, such as net.ipv4.ip_forward.
	Key string `json:"-"`

	// Value to set.
	Value string `json:"value"`
}

SysctlUpdateInput is the input of SysctlService.Update. A field of the path goes in the path, and each other field in the body.

type TelemetryGetParams added in v0.3.0

type TelemetryGetParams struct {
	// All is the all of the query: show the NATS calls too, the reads and writes
	// of the job queue. The zero value leaves it out.
	All bool
}

TelemetryGetParams are the parameters of TelemetryService.Get that a request can leave out.

type TelemetryService added in v0.3.0

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

TelemetryService calls the API's Telemetry group: telemetry through the controller, such as the spans of a trace.

func (*TelemetryService) Get added in v0.3.0

Get is the operation GetTrace: get the spans of a trace.

Returns each span of a trace, read from the tracing backend at telemetry.tracing.url. The backend gets the spans a few seconds after the request, so a trace of a request that just ran can be not found yet. A token with a target scope gets a trace only when each target that the trace records is in its scope.

It sends GET /api/telemetry/trace/{id}, and needs the permission trace:read.

type TimelineEvent

type TimelineEvent struct {
	// Error is the property error.
	Error string `json:"error,omitempty"`

	// Event is the property event.
	Event string `json:"event"`

	// Hostname is the property hostname.
	Hostname string `json:"hostname,omitempty"`

	// Message is the property message.
	Message string `json:"message,omitempty"`

	// Timestamp is the property timestamp.
	Timestamp time.Time `json:"timestamp"`
}

TimelineEvent is the TimelineEvent of the spec.

type TimezoneEntry added in v0.3.0

type TimezoneEntry struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// The IANA name of the timezone, such as America/New_York.
	Timezone string `json:"timezone,omitempty"`

	// The offset from UTC now, such as -05:00.
	UTCOffset string `json:"utc_offset,omitempty"`
}

TimezoneEntry is the TimezoneEntry of the spec.

type TimezoneResult

type TimezoneResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// The timezone of the host.
	Timezone string `json:"timezone,omitempty"`
}

TimezoneResult is the TimezoneResult of the spec.

type TimezoneService

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

TimezoneService calls the API's Timezone group: the timezone of the host.

func (*TimezoneService) Get

Get is the operation GetNodeTimezone: get the timezone of the host.

Reads the IANA name of the timezone and its offset from UTC now: the zone that /etc/localtime links to, or /etc/timezone on Linux.

It sends GET /api/node/{hostname}/timezone, and needs the permission timezone:read.

func (*TimezoneService) Update

Update is the operation PutNodeTimezone: set the timezone of the host.

Sets the timezone with timedatectl set-timezone. A host that already has the timezone does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped.

It sends PUT /api/node/{hostname}/timezone, and needs the permission timezone:write.

type TimezoneUpdateInput added in v0.3.0

type TimezoneUpdateInput struct {
	// The IANA name of the timezone, such as UTC or America/New_York.
	Timezone string `json:"timezone"`
}

TimezoneUpdateInput is the input of TimezoneService.Update. A field of the path goes in the path, and each other field in the body.

type TraceNode added in v0.3.0

type TraceNode struct {
	// The spans under this one, in start order.
	Children []TraceNode `json:"children,omitempty"`

	// How far the span and the spans under it were moved forward, as a Go
	// duration, because the span started before its parent: the clock of its host
	// is behind. Empty when the span was not moved.
	ClockSkew string `json:"clock_skew,omitempty"`

	// What the span acted on, as key=value pairs, led by error= on a failed span.
	Detail string `json:"detail,omitempty"`

	// How long the span took, as a Go duration.
	Duration string `json:"duration"`

	// The name of the span, such as job.process.
	Name string `json:"name"`

	// What ran the span: the role of its service, such as controller, agent or
	// cli.
	On string `json:"on"`

	// Span is the property span.
	Span TraceSpan `json:"span"`

	// The job's status on a job.process, changed or unchanged on a behavior write,
	// and ok or error on other spans.
	Status string `json:"status"`
}

TraceNode is the TraceNode of the spec.

type TraceResponse added in v0.3.0

type TraceResponse struct {
	// From the start of the first span to the end of the last, as a Go duration.
	Duration string `json:"duration,omitempty"`

	// The number of spans that failed.
	FailedSpans int `json:"failed_spans,omitempty"`

	// The number of NATS calls left out, the bookkeeping of the job queue. all
	// shows them.
	NATSCalls int `json:"nats_calls,omitempty"`

	// The time that the NATS calls left out took, as a Go duration.
	NATSTime string `json:"nats_time,omitempty"`

	// The services that made the spans, in the order each first appears.
	Services []string `json:"services,omitempty"`

	// The spans that have no parent in the trace, each with its children, in start
	// order.
	Spans []TraceNode `json:"spans"`

	// When the first span started.
	Started time.Time `json:"started,omitzero"`

	// The trace ID.
	TraceID string `json:"trace_id"`
}

TraceResponse is the TraceResponse of the spec.

type TraceSpan added in v0.3.0

type TraceSpan struct {
	// The attributes of the span, each as text.
	Attributes map[string]string `json:"attributes"`

	// How long the span took, in milliseconds.
	DurationMS float64 `json:"duration_ms"`

	// The span kind, such as server, client, producer or consumer.
	Kind string `json:"kind,omitempty"`

	// The name of the span, such as job.process.
	Name string `json:"name"`

	// The ID of the parent span. Empty for the root.
	ParentSpanID string `json:"parent_span_id,omitempty"`

	// The service that made the span, such as osapi-agent.
	Service string `json:"service"`

	// The span ID.
	SpanID string `json:"span_id"`

	// When the span started.
	StartTime time.Time `json:"start_time"`

	// SpanStatus is whether the work of a span failed.
	Status types.SpanStatus `json:"status"`

	// The error of a failed span.
	StatusMessage string `json:"status_message,omitempty"`
}

TraceSpan is the TraceSpan of the spec.

type UnexpectedStatusError

type UnexpectedStatusError struct {
	APIError
}

UnexpectedStatusError represents unexpected HTTP status codes.

func (*UnexpectedStatusError) Unwrap

func (e *UnexpectedStatusError) Unwrap() error

Unwrap returns the underlying APIError.

type UptimeEntry added in v0.3.0

type UptimeEntry struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// How long the host has run, in seconds.
	Seconds int `json:"seconds,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// How long the host has run, in days, hours and minutes.
	Uptime string `json:"uptime,omitempty"`
}

UptimeEntry is the UptimeEntry of the spec.

type UptimeService

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

UptimeService calls the API's Uptime group: get the uptime of target hosts.

func (*UptimeService) Get

func (s *UptimeService) Get(
	ctx context.Context,
	hostname string,
) (*Response[Collection[UptimeEntry]], error)

Get is the operation GetNodeUptime: get the uptime of the host.

Reads how long the host has run since it booted: /proc/uptime on Linux, and the boot time that sysctl gives on macOS. The uptime is in days, hours and minutes, and in seconds.

It sends GET /api/node/{hostname}/uptime, and needs the permission uptime:read.

type Usage added in v0.3.0

type Usage struct {
	// Free memory in bytes.
	Free int `json:"free"`

	// Total memory in bytes.
	Total int `json:"total"`

	// Used memory in bytes: the total less what is available.
	Used int `json:"used"`
}

Usage is the Usage of the spec.

type UserAccount added in v0.3.0

type UserAccount struct {
	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Its primary group ID.
	GID int `json:"gid,omitempty"`

	// The groups it is a member of, besides its primary group.
	Groups []string `json:"groups,omitempty"`

	// Its home directory.
	Home string `json:"home,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// Whether a login with its password is refused.
	Locked bool `json:"locked,omitempty"`

	// The user.
	Name string `json:"name,omitempty"`

	// Its login shell.
	Shell string `json:"shell,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// Its numeric user ID.
	UID int `json:"uid,omitempty"`
}

UserAccount is the UserAccount of the spec.

type UserCreateInput added in v0.3.0

type UserCreateInput struct {
	// Its primary group ID; a group of its own when it is 0.
	GID int `json:"gid,omitempty"`

	// The groups it is a member of, besides its primary group.
	Groups []string `json:"groups,omitempty"`

	// Its home directory; /home/<name> when empty.
	Home string `json:"home,omitempty"`

	// The user to add, such as alice.
	Name string `json:"name"`

	// Its password, which osapi hashes on the controller; none when empty. A
	// secret: a reference, secret://<vault>/<key>, or the value.
	Password string `json:"password,omitempty"`

	// Its login shell, such as /bin/bash; the system's default when empty.
	Shell string `json:"shell,omitempty"`

	// Add it as a system user, with an ID from the system range.
	System bool `json:"system,omitempty"`

	// Its numeric user ID; the system assigns one when it is 0.
	UID int `json:"uid,omitempty"`
}

UserCreateInput is the input of UserService.Create. A field of the path goes in the path, and each other field in the body.

type UserPasswordResult added in v0.3.0

type UserPasswordResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The user.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

UserPasswordResult is the UserPasswordResult of the spec.

type UserPasswordService added in v0.3.0

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

UserPasswordService calls the API's UserPassword group: the password of a user.

func (*UserPasswordService) Update added in v0.3.0

Update is the operation PutNodeUserPassword: set the password of a user.

Sets the password with chpasswd -e, from its hash on standard input. The controller hashes the password, so the job and NATS have only the hash. Each call makes a new hash, so it always reports changed: true. A user that the host does not have is not found. It runs on the Debian family only, and elsewhere reports skipped.

It sends PUT /api/node/{hostname}/user/{name}/password, and needs the permission user:write.

type UserPasswordUpdateInput added in v0.3.0

type UserPasswordUpdateInput struct {
	// The name of the path: the user, such as alice.
	Name string `json:"-"`

	// The new password, which osapi hashes on the controller. A secret: a
	// reference, secret://<vault>/<key>, or the value.
	Password string `json:"password,omitempty"`
}

UserPasswordUpdateInput is the input of UserPasswordService.Update. A field of the path goes in the path, and each other field in the body.

type UserResult added in v0.3.0

type UserResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The user.
	Name string `json:"name,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

UserResult is the UserResult of the spec.

type UserSSHKeyCreateInput added in v0.3.0

type UserSSHKeyCreateInput struct {
	// The name of the path: the user, such as alice.
	Name string `json:"-"`

	// The public key line, such as ssh-ed25519 AAAA... alice@laptop, with options
	// before it if any.
	Key string `json:"key"`
}

UserSSHKeyCreateInput is the input of UserSSHKeyService.Create. A field of the path goes in the path, and each other field in the body.

type UserSSHKeyDeleteInput added in v0.3.0

type UserSSHKeyDeleteInput struct {
	// The name of the path: the user, such as alice.
	Name string `json:"-"`

	// The SHA256 fingerprint of the key, as list shows it.
	Fingerprint string `json:"fingerprint"`
}

UserSSHKeyDeleteInput is the input of UserSSHKeyService.Delete. A field of the path goes in the path, and each other field in the body.

type UserSSHKeyService added in v0.3.0

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

UserSSHKeyService calls the API's UserSSHKey group: the authorized SSH keys of a user.

func (*UserSSHKeyService) Create added in v0.3.0

Create is the operation PostNodeUserSshkey: add an authorized SSH key to a user.

Adds the key line to the end of ~/.ssh/authorized_keys of the user, and makes the directory and the file if they are missing, with modes 700 and 600, owned by the user. A key that the file has already, by its fingerprint, does not change it. A line with no public key is refused. A user that the host does not have is not found. It runs on the Debian family only, and elsewhere reports skipped.

It sends POST /api/node/{hostname}/user/{name}/sshkey, and needs the permission user:write.

func (*UserSSHKeyService) Delete added in v0.3.0

Delete is the operation DeleteNodeUserSshkey: remove an authorized SSH key of a user.

Removes each line of the key with the fingerprint from ~/.ssh/authorized_keys of the user, and keeps the other lines as they are. A key that the file does not have, a user with no file, or a user that the host does not have, changes nothing. It runs on the Debian family only, and elsewhere reports skipped.

It sends DELETE /api/node/{hostname}/user/{name}/sshkey, and needs the permission user:write.

func (*UserSSHKeyService) List added in v0.3.0

func (s *UserSSHKeyService) List(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[UserSshkeyKey]], error)

List is the operation GetNodeUserSshkey: list the authorized SSH keys of a user.

Reads ~/.ssh/authorized_keys of the user through gohai, with the type, the SHA256 fingerprint, the comment and the options of each key. A user with no file has no keys. A user that the host does not have is not found.

It sends GET /api/node/{hostname}/user/{name}/sshkey, and needs the permission user:read.

type UserService

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

UserService calls the API's User group: the users of the host.

func (*UserService) Create

func (s *UserService) Create(
	ctx context.Context,
	hostname string,
	input UserCreateInput,
) (*Response[Collection[UserResult]], error)

Create is the operation PostNodeUser: add a user.

Adds the user with useradd, with its home directory, and sets its password with chpasswd when one is given. The controller hashes the password, so the job and NATS have only the hash. A user that the host has already does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped.

It sends POST /api/node/{hostname}/user, and needs the permission user:write.

func (*UserService) Delete

func (s *UserService) Delete(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[UserResult]], error)

Delete is the operation DeleteNodeUser: remove a user.

Removes the user and its home directory with userdel -r. A user that the host does not have does not change and reports changed: false. It runs on the Debian family only, and elsewhere reports skipped.

It sends DELETE /api/node/{hostname}/user/{name}, and needs the permission user:write.

func (*UserService) Get

func (s *UserService) Get(
	ctx context.Context,
	hostname string,
	name string,
) (*Response[Collection[UserAccount]], error)

Get is the operation GetNodeUserByKey: get one user.

Reads one user from the same list. A user that the host does not have is not found.

It sends GET /api/node/{hostname}/user/{name}, and needs the permission user:read.

func (*UserService) List

func (s *UserService) List(
	ctx context.Context,
	hostname string,
) (*Response[Collection[UserAccount]], error)

List is the operation GetNodeUser: list the users of the host.

Lists each user with its IDs, home, shell, groups and whether it is locked, through gohai: from /etc/passwd, /etc/group and /etc/shadow on Linux, and from the directory service with dscl on macOS. The groups are those that list the user as a member, besides its primary group.

It sends GET /api/node/{hostname}/user, and needs the permission user:read.

func (*UserService) Update

func (s *UserService) Update(
	ctx context.Context,
	hostname string,
	input UserUpdateInput,
) (*Response[Collection[UserResult]], error)

Update is the operation PutNodeUser: change a user.

Changes what the input gives and the user does not have already, with usermod: its shell, its home, which usermod moves the files to, its groups, which replace the groups it has, and whether it is locked. The same values report changed: false. A user that the host does not have is not found. It runs on the Debian family only, and elsewhere reports skipped.

It sends PUT /api/node/{hostname}/user/{name}, and needs the permission user:write.

type UserSshkeyKey added in v0.3.0

type UserSshkeyKey struct {
	// The comment after the key, such as alice@laptop.
	Comment string `json:"comment,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// The SHA256 fingerprint of the key.
	Fingerprint string `json:"fingerprint,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// The options before the key, such as from="10.0.0.0/8".
	Options string `json:"options,omitempty"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`

	// The key type, such as ssh-ed25519.
	Type string `json:"type,omitempty"`
}

UserSshkeyKey is the UserSshkeyKey of the spec.

type UserSshkeyResult added in v0.3.0

type UserSshkeyResult struct {
	// Whether the host changed.
	Changed bool `json:"changed,omitempty"`

	// Error message if the agent failed.
	Error string `json:"error,omitempty"`

	// The SHA256 fingerprint of the key.
	Fingerprint string `json:"fingerprint,omitempty"`

	// Hostname of the agent that produced this result.
	Hostname string `json:"hostname"`

	// What happened on the host: ok, the operation ran and succeeded; failed, it
	// ran and did not succeed; skipped, the host's OS family does not support it;
	// timeout, the host did not answer, so nobody knows whether it ran.
	Status types.RowStatus `json:"status"`
}

UserSshkeyResult is the UserSshkeyResult of the spec.

type UserUpdateInput added in v0.3.0

type UserUpdateInput struct {
	// The name of the path: the user to remove, with its home directory, such as
	// alice.
	Name string `json:"-"`

	// The groups it is a member of, which replace the groups it has.
	Groups []string `json:"groups,omitempty"`

	// Its home directory, which usermod moves the files to.
	Home string `json:"home,omitempty"`

	// Lock is whether a user account refuses logins with its password.
	Lock types.Lock `json:"lock,omitzero"`

	// Its login shell, such as /bin/bash.
	Shell string `json:"shell,omitempty"`
}

UserUpdateInput is the input of UserService.Update. A field of the path goes in the path, and each other field in the body.

type ValidationError

type ValidationError struct {
	APIError
}

ValidationError represents validation errors (400).

func (*ValidationError) Unwrap

func (e *ValidationError) Unwrap() error

Unwrap returns the underlying APIError.

type VaultInfo added in v0.3.0

type VaultInfo struct {
	// Whether the vault answered a list of its keys.
	Answers bool `json:"answers"`

	// The name of the vault, as a reference gives it.
	Name string `json:"name"`

	// The targets that its secrets can go to. Empty is each host.
	Targets []string `json:"targets"`

	// The type of the vault, such as nats.
	Type string `json:"type"`
}

VaultInfo is the VaultInfo of the spec.

type VaultListResponse added in v0.3.0

type VaultListResponse struct {
	// The vaults of the controller.
	Items []VaultInfo `json:"items"`

	// The number of vaults.
	TotalItems int `json:"total_items"`
}

VaultListResponse is the VaultListResponse of the spec.

Source Files

Jump to

Keyboard shortcuts

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