Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Client

Constructor: v1.NewClient(config)

The ClientInterface is the root entry point for all SDK operations. It provides typed accessors for each resource domain and manages the underlying gRPC connection.

Methods

AccessorReturnsDescription
Sandboxes()SandboxInterfaceSandbox lifecycle management
Providers()ProviderInterfaceProvider CRUD and idempotent ensure
Services()ServiceInterfaceService exposure and management
Exec()ExecInterfaceCommand execution (run, stream, interactive)
Files()FileInterfaceFile upload and download
Health()HealthInterfaceGateway health checking
SSH()SSHInterfaceSSH session and tunnel management
TCP()TCPInterfaceTCP port forwarding
Config()ConfigInterfaceSandbox and gateway configuration
Policy()PolicyInterfaceDraft policy review workflow
Close()errorClose the gRPC connection

Sub-client hierarchy: Providers() has two nested accessors:

  • client.Providers().Profiles() returns ProfileInterface
  • client.Providers().Refresh() returns RefreshInterface

Creating a Client

import v1 "github.com/rhuss/openshell-sdk-go/openshell/v1"

client, err := v1.NewClient(v1.Config{
    Address: "gateway.example.com:443",
    Auth:    v1.StaticToken("my-token"),
})
if err != nil {
    log.Fatal(err)
}
defer client.Close()

Configuration

The Config struct controls connection behavior:

type Config struct {
    Address     string         // Gateway address (host:port)
    TLS         *TLSConfig     // TLS settings (nil uses system defaults)
    Auth        AuthProvider   // Authentication provider
    Timeout     time.Duration  // Default timeout for all operations (0 = no timeout)
    RetryPolicy *RetryPolicy   // Retry configuration (nil = no automatic retries)
    Logger      Logger         // Custom logger (nil = no logging)
}

Authentication providers:

  • v1.StaticToken(token) provides a fixed bearer token
  • v1.NoAuth() skips authentication (for local development)

Testing

For unit tests, use the fake client instead of a real connection:

import "github.com/rhuss/openshell-sdk-go/openshell/v1/fake"

client := fake.NewClient()
defer client.Close()

The fake client implements the full ClientInterface with in-memory stores. See Testing for details.

See also: Getting Started, Architecture