Skip to content

Go SDK for OSAPI — client library and orchestration primitives.

License

Notifications You must be signed in to change notification settings

osapi-io/osapi-sdk

Repository files navigation

release codecov go report card license build powered by conventional commits built with just gitHub commit activity

OSAPI SDK

A Go client library for the OSAPI REST API.

Usage

// Package main demonstrates basic usage of the OSAPI SDK.
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/osapi-io/osapi-sdk/pkg/osapi"
)
func main() {
url := os.Getenv("OSAPI_URL")
if url == "" {
url = "http://localhost:8080"
}
token := os.Getenv("OSAPI_TOKEN")
if token == "" {
log.Fatal("OSAPI_TOKEN environment variable is required")
}
client, err := osapi.New(url, token)
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Get hostname from any available agent.
hostnameResp, err := client.Node.Hostname(ctx, "_any")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Hostname response status: %d\n", hostnameResp.StatusCode())
// Execute a command on any available agent.
execResp, err := client.Node.Exec(ctx, osapi.ExecRequest{
Command: "uptime",
Target: "_any",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Exec response status: %d\n", execResp.StatusCode())
// List recent audit log entries.
auditResp, err := client.Audit.List(ctx, 10, 0)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Audit response status: %d\n", auditResp.StatusCode())
// Check API server health.
healthResp, err := client.Health.Liveness(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Health response status: %d\n", healthResp.StatusCode())
}

See the examples section for additional use cases.

Documentation

See the generated documentation for details on available packages and functions.

Contributing

See the Development guide for prerequisites, setup, and conventions. See the Contributing guide before submitting a PR.

License

The MIT License.

About

Go SDK for OSAPI — client library and orchestration primitives.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors