osapi

package
v0.0.0-...-a68c34b Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package osapi provides a Go SDK for the OSAPI REST API.

Create a client with New() and use the domain-specific services to interact with the API:

client, err := osapi.New("http://localhost:8080", "your-jwt-token")
if err != nil {
    log.Fatal(err)
}

// Get hostname
resp, err := client.Node.Hostname(ctx, "_any")

// Execute a command
resp, err := client.Node.Exec(ctx, osapi.ExecRequest{
    Command: "uptime",
    Target:  "_all",
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentService

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

AgentService provides agent discovery and details operations.

func (*AgentService) Get

func (s *AgentService) Get(
	ctx context.Context,
	hostname string,
) (*gen.GetAgentDetailsResponse, error)

Get retrieves detailed information about a specific agent by hostname.

func (*AgentService) List

func (s *AgentService) List(
	ctx context.Context,
) (*gen.GetAgentResponse, error)

List retrieves all active agents.

type AuditService

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

AuditService provides audit log operations.

func (*AuditService) Export

Export retrieves all audit log entries for export.

func (*AuditService) Get

Get retrieves a single audit log entry by ID.

func (*AuditService) List

func (s *AuditService) List(
	ctx context.Context,
	limit int,
	offset int,
) (*gen.GetAuditLogsResponse, error)

List retrieves audit log entries with pagination.

type Client

type Client struct {
	// Agent provides agent discovery and details operations.
	Agent *AgentService

	// Node provides node management operations (hostname, status, disk,
	// memory, load, OS, uptime, network DNS/ping, command exec/shell).
	Node *NodeService

	// Job provides job queue operations (create, get, list, delete, retry).
	Job *JobService

	// Health provides health check operations (liveness, readiness, status).
	Health *HealthService

	// Audit provides audit log operations (list, get, export).
	Audit *AuditService

	// Metrics provides Prometheus metrics access.
	Metrics *MetricsService
	// contains filtered or unexported fields
}

Client is the top-level OSAPI SDK client. Use New() to create one.

func New

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

New creates an OSAPI SDK client.

type ExecRequest

type ExecRequest struct {
	// Command is the binary to execute (required).
	Command string

	// Args is the argument list passed to the command.
	Args []string

	// Cwd is the working directory. Empty uses the agent default.
	Cwd string

	// Timeout in seconds. Zero uses the server default (30s).
	Timeout int

	// Target specifies the host: "_any", "_all", hostname, or
	// label ("group:web").
	Target string
}

ExecRequest contains parameters for direct command execution.

type HealthService

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

HealthService provides health check operations.

func (*HealthService) Liveness

func (s *HealthService) Liveness(
	ctx context.Context,
) (*gen.GetHealthResponse, error)

Liveness checks if the API server process is alive.

func (*HealthService) Ready

Ready checks if the API server and its dependencies are ready to serve traffic.

func (*HealthService) Status

Status returns detailed system status including component health, NATS info, stream stats, and job queue counts. Requires authentication.

type JobService

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

JobService provides job queue operations.

func (*JobService) Create

func (s *JobService) Create(
	ctx context.Context,
	operation map[string]interface{},
	target string,
) (*gen.PostJobResponse, error)

Create creates a new job with the given operation and target.

func (*JobService) Delete

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

Delete deletes a job by ID.

func (*JobService) Get

func (s *JobService) Get(
	ctx context.Context,
	id string,
) (*gen.GetJobByIDResponse, error)

Get retrieves a job by ID.

func (*JobService) List

func (s *JobService) List(
	ctx context.Context,
	params ListParams,
) (*gen.GetJobResponse, error)

List retrieves jobs, optionally filtered by status.

func (*JobService) QueueStats

func (s *JobService) QueueStats(
	ctx context.Context,
) (*gen.GetJobStatusResponse, error)

QueueStats retrieves job queue statistics.

func (*JobService) Retry

func (s *JobService) Retry(
	ctx context.Context,
	id string,
	target string,
) (*gen.RetryJobByIDResponse, error)

Retry retries a failed job by ID, optionally on a different target.

type ListParams

type ListParams struct {
	// Status filters by job status (e.g., "pending", "completed").
	Status string

	// Limit is the maximum number of results. Zero uses server default.
	Limit int

	// Offset is the number of results to skip. Zero starts from the
	// beginning.
	Offset int
}

ListParams contains optional filters for listing jobs.

type MetricsService

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

MetricsService provides Prometheus metrics access.

func (*MetricsService) Get

func (s *MetricsService) Get(
	ctx context.Context,
) (string, error)

Get fetches the raw Prometheus metrics text from the /metrics endpoint.

type NodeService

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

NodeService provides node management operations.

func (*NodeService) Disk

func (s *NodeService) Disk(
	ctx context.Context,
	target string,
) (*gen.GetNodeDiskResponse, error)

Disk retrieves disk usage information from the target host.

func (*NodeService) Exec

Exec executes a command directly without a shell interpreter.

func (*NodeService) GetDNS

func (s *NodeService) GetDNS(
	ctx context.Context,
	target string,
	interfaceName string,
) (*gen.GetNodeNetworkDNSByInterfaceResponse, error)

GetDNS retrieves DNS configuration for a network interface on the target host.

func (*NodeService) Hostname

func (s *NodeService) Hostname(
	ctx context.Context,
	target string,
) (*gen.GetNodeHostnameResponse, error)

Hostname retrieves the hostname from the target host.

func (*NodeService) Load

func (s *NodeService) Load(
	ctx context.Context,
	target string,
) (*gen.GetNodeLoadResponse, error)

Load retrieves load average information from the target host.

func (*NodeService) Memory

func (s *NodeService) Memory(
	ctx context.Context,
	target string,
) (*gen.GetNodeMemoryResponse, error)

Memory retrieves memory usage information from the target host.

func (*NodeService) OS

func (s *NodeService) OS(
	ctx context.Context,
	target string,
) (*gen.GetNodeOSResponse, error)

OS retrieves operating system information from the target host.

func (*NodeService) Ping

func (s *NodeService) Ping(
	ctx context.Context,
	target string,
	address string,
) (*gen.PostNodeNetworkPingResponse, error)

Ping sends an ICMP ping to the specified address from the target host.

func (*NodeService) Shell

Shell executes a command through /bin/sh -c with shell features (pipes, redirects, variable expansion).

func (*NodeService) Status

func (s *NodeService) Status(
	ctx context.Context,
	target string,
) (*gen.GetNodeStatusResponse, error)

Status retrieves node status (OS info, disk, memory, load) from the target host.

func (*NodeService) UpdateDNS

func (s *NodeService) UpdateDNS(
	ctx context.Context,
	target string,
	interfaceName string,
	servers []string,
	searchDomains []string,
) (*gen.PutNodeNetworkDNSResponse, error)

UpdateDNS updates DNS configuration for a network interface on the target host.

func (*NodeService) Uptime

func (s *NodeService) Uptime(
	ctx context.Context,
	target string,
) (*gen.GetNodeUptimeResponse, error)

Uptime retrieves uptime information from the target host.

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.

func WithLogger

func WithLogger(
	logger *slog.Logger,
) Option

WithLogger sets a custom logger. Defaults to slog.Default().

type ShellRequest

type ShellRequest struct {
	// Command is the shell command string passed to /bin/sh -c (required).
	Command string

	// Cwd is the working directory. Empty uses the agent default.
	Cwd string

	// Timeout in seconds. Zero uses the server default (30s).
	Timeout int

	// Target specifies the host: "_any", "_all", hostname, or
	// label ("group:web").
	Target string
}

ShellRequest contains parameters for shell command execution.

Directories

Path Synopsis
Package gen provides primitives to interact with the openapi HTTP API.
Package gen provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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