caprf

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package caprf implements the CAPRF provisioning server client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseVars

func ParseVars(r io.Reader) (*config.MachineConfig, error)

ParseVars reads a /deploy/vars file and returns a MachineConfig. The file format is: export KEY="VALUE" (one per line).

Types

type Client

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

Client communicates with the CAPRF provisioning server.

func New

func New(varsPath string) (*Client, error)

New creates a CAPRF client by parsing the vars file at the given path.

func NewFromConfig

func NewFromConfig(cfg *config.MachineConfig) *Client

NewFromConfig creates a CAPRF client from an already-parsed config.

func (*Client) AcknowledgeCommand added in v0.0.2

func (c *Client) AcknowledgeCommand(ctx context.Context, cmdID, status, message string) error

AcknowledgeCommand reports command execution result back to the CAPRF server.

func (*Client) AcquireToken added in v0.0.8

func (c *Client) AcquireToken(ctx context.Context) error

AcquireToken exchanges the bootstrap token for a JWT if a token URL is configured. The acquired JWT replaces the bootstrap token for all subsequent API calls. The TokenManager is retained for background renewal.

func (*Client) CurrentToken added in v0.0.8

func (c *Client) CurrentToken() string

CurrentToken returns the latest token, preferring the token manager if active.

func (*Client) FetchCommands

func (c *Client) FetchCommands(ctx context.Context) ([]config.Command, error)

FetchCommands polls the CAPRF server for pending commands. Returns nil if no commands URL is configured.

func (*Client) GetConfig

func (c *Client) GetConfig(_ context.Context) (*config.MachineConfig, error)

GetConfig returns the parsed machine configuration.

func (*Client) Heartbeat

func (c *Client) Heartbeat(ctx context.Context) error

Heartbeat sends a keepalive to the CAPRF server. Returns nil if no heartbeat URL is configured (non-standby mode).

func (*Client) ReportFirmware

func (c *Client) ReportFirmware(ctx context.Context, data []byte) error

ReportFirmware sends a JSON firmware report to the CAPRF server.

func (*Client) ReportHealthChecks

func (c *Client) ReportHealthChecks(ctx context.Context, results []health.CheckResult) error

ReportHealthChecks sends health check results to the CAPRF server.

func (*Client) ReportInventory

func (c *Client) ReportInventory(ctx context.Context, data []byte) error

ReportInventory posts a hardware inventory JSON payload to the CAPRF server.

func (*Client) ReportMetrics added in v0.0.2

func (c *Client) ReportMetrics(ctx context.Context, data []byte) error

ReportMetrics posts provisioning metrics to the CAPRF server. Requires TelemetryEnabled. Uses MetricsURL, falling back to TelemetryURL.

func (*Client) ReportStatus

func (c *Client) ReportStatus(ctx context.Context, status config.Status, message string) error

ReportStatus sends a provisioning status to the CAPRF server.

func (*Client) SendEvent added in v0.0.2

func (c *Client) SendEvent(ctx context.Context, data []byte) error

SendEvent posts a single provisioning event to the CAPRF server.

func (*Client) SetTokenRenewalFatalHandler added in v0.0.8

func (c *Client) SetTokenRenewalFatalHandler(fn func())

SetTokenRenewalFatalHandler sets the callback invoked when token renewal is permanently exhausted.

func (*Client) ShipDebug

func (c *Client) ShipDebug(ctx context.Context, message string) error

ShipDebug sends a debug message to the CAPRF /debug endpoint.

func (*Client) ShipLog

func (c *Client) ShipLog(ctx context.Context, message string) error

ShipLog sends a log line to the CAPRF /log endpoint.

func (*Client) StartTokenRenewal added in v0.0.8

func (c *Client) StartTokenRenewal(ctx context.Context) error

StartTokenRenewal begins background JWT renewal if a token was acquired.

type RemoteHandler

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

RemoteHandler is a slog.Handler that ships log lines to the CAPRF /log endpoint. It wraps another handler so logs appear both in the console and remotely.

func NewRemoteHandler

func NewRemoteHandler(client *Client, inner slog.Handler, level slog.Leveler, bufSize int) *RemoteHandler

NewRemoteHandler creates a handler that sends logs to the CAPRF server. The inner handler is used for local console output. Buffer capacity controls how many log lines can be queued before dropping.

func (*RemoteHandler) Close

func (h *RemoteHandler) Close()

Close stops the background drain goroutine and flushes remaining logs. It closes the buffer to signal drain to finish, then waits up to 5s. If drain does not finish in time, the context is canceled to abort any in-flight HTTP requests.

func (*RemoteHandler) Enabled

func (h *RemoteHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled reports whether the handler handles records at the given level.

func (*RemoteHandler) Handle

func (h *RemoteHandler) Handle(ctx context.Context, r slog.Record) error

Handle sends the log record to both the inner handler and the remote buffer.

func (*RemoteHandler) WithAttrs

func (h *RemoteHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new handler with the given attributes.

func (*RemoteHandler) WithGroup

func (h *RemoteHandler) WithGroup(name string) slog.Handler

WithGroup returns a new handler with the given group name.

Jump to

Keyboard shortcuts

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