The osapi package provides a typed Go client for the OSAPI REST API. Create a
client with New() and use domain-specific services to interact with the API.
Quick Start
import "github.com/osapi-io/osapi/pkg/sdk/client"
c := client.New("https://localhost:8080", "your-jwt-token")
resp, err := c.Hostname.Get(ctx, "_any")
How the services are made
internal/sdk/gen writes the services and their types from the spec of the API,
in just sdk-generate. Each group of the API is a service, and each operation
is a method:
- The service has the words of the group's path, such as
NetworkDNS for
/api/node/{hostname}/network/dns.
- The method has the name of the method in the group's definition, such as
Get. The CLI command has the same name.
- A type of an answer has the name of its schema, such as
NetworkDnsEntry. A
{job_id, results} answer is a Collection of its item.
- A method with a body takes the target, then one input struct, such as
NetworkDNSUpdateInput: the keys of the path and the fields of the body.
- A method with no body takes the parameters of the path, then a struct of the
parameters of the query that a request can leave out.
- Each answer outside 2xx is one of the error types of the SDK.
The methods that upload a file, File.Upload and File.Update, and
File.GetChanged are written by hand.
The same run writes a program for each service,
examples/sdk/client/<service>.go. It calls each method with the input of each
example of the method's definition, and prints the answer. just examples-check
compiles each program, so an example cannot go stale.
Services
Each service has a page, which internal/sdk/gen writes from the same model:
its methods with their signatures, doc comments and permissions, the code of
each example of the method's definition, and its types. The services of a node
act on the hosts of a target. The services of the controller act on the
controller itself.
The pages are in a folder for each area, such as Networking or Fleet. The UI's
Behaviors page has the same areas, in the same order. Each behavior and each
endpoint group declares its area in Go, and internal/area gives the label and
the order of each area. The spec carries them, and the generator reads them from
the spec.
Services
| Service | Description |
|---|
| Service | The systemd services of the host. |
Software
| Service | Description |
|---|
| Package | The packages installed on the host. |
| PackageUpdates | The updates the package index has for the host. |
Config
| Service | Description |
|---|
| Hostname | Get or set the hostname of target hosts. |
| NTP | The NTP servers of chrony, and its sync status. |
| NodeFile | Files of the object store, deployed to the host. |
| Schedule | The cron entries that osapi deploys. |
| Sysctl | Kernel parameters, written to sysctl.d files and applied. |
| Timezone | The timezone of the host. |
Node
| Service | Description |
|---|
| Load | Get the load averages of target hosts. |
| OS | Get the operating system of target hosts. |
| Power | Reboot or shut down the host. |
| Process | The processes of the host. |
| Status | The status summary of a node. |
| Uptime | Get the uptime of target hosts. |
Logs
| Service | Description |
|---|
| Log | The entries of the systemd journal. |
| LogSource | The sources that write to the systemd journal. |
Networking
| Service | Description |
|---|
| Connectivity | Whether the host reaches an address, by ICMP ping. |
| DNS | The DNS resolvers of each interface of the host. |
| Interface | The network interfaces of the host. |
| InterfaceRoute | The routes of an interface. |
Security
| Service | Description |
|---|
| Certificate | The certificate authorities that the host trusts. |
| Group | The groups of the host. |
| User | The users of the host. |
| UserPassword | The password of a user. |
| UserSSHKey | The authorized SSH keys of a user. |
Containers
| Service | Description |
|---|
| Docker | The Docker containers of the host. |
| Image | The Docker images of the host. |
Object Store
| Service | Description |
|---|
| File | Object Store file management operations. |
Secrets
| Service | Description |
|---|
| Secret | The vaults of the controller and the metadata of their keys. No operation gives a value. |
Command
| Service | Description |
|---|
| Command | Run a command on target hosts. |
Hardware
| Service | Description |
|---|
| Disk | Get the disk usage of target hosts. |
| Memory | Get the memory usage of target hosts. |
Audit
| Service | Description |
|---|
| Audit | Audit log endpoints for viewing API activity. |
Fleet
| Service | Description |
|---|
| Admission | Admit, reject and revoke the nodes that ask to join. |
| Agent | Operations related to agent discovery and details. |
| Catalog | The behaviors, the permissions and the roles that the controller serves, for the UI. |
| Health | Health check endpoints for liveness, readiness, and detailed status. |
| Job | Operations related to the job queue. |
| Telemetry | Telemetry through the controller, such as the spans of a trace. |
Client Options
| Option | Description |
|---|
WithLogger(logger) | Set custom slog.Logger |
WithHTTPTransport(transport) | Set custom http.RoundTripper |
WithLogger defaults to slog.Default(). WithHTTPTransport sets the base
transport for HTTP requests.
Targeting
Most operations accept a target parameter:
| Target | Behavior |
|---|
_any | Send to any available agent (load balanced) |
_all | Broadcast to every agent |
hostname | Send to a specific host |
key:value | Send to agents matching a label |