Skip to content

Commit 58c9f93

Browse files
committed
docs(sdk/go): add documentation and CI job (3/3)
Add Go SDK documentation pages and CI integration. Documentation (Fern MDX): - Getting Started: installation, connection, first API call - Architecture: module structure, transport layer, sub-clients - Error Handling: error codes, type checking, retry configuration - Authentication: OIDC flows, token refresh, TLS configuration CI integration: - Go job in branch-checks workflow (lint, build, test, proto check) - Mise task for proto generation from monorepo context Builds on PRs 1/3 and 2/3. Merge those first. Resolves #2044 Signed-off-by: Roland Huß <roland@jolokia.org> Assisted-By: 🤖 Claude Code
1 parent 614c8c1 commit 58c9f93

194 files changed

Lines changed: 50259 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/branch-checks.yml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,31 @@ jobs:
190190

191191
- name: Lint
192192
run: mise run markdown:lint
193+
194+
go:
195+
name: Go
196+
needs: pr_metadata
197+
if: needs.pr_metadata.outputs.should_run == 'true'
198+
runs-on: linux-amd64-cpu8
199+
container:
200+
image: ghcr.io/nvidia/openshell/ci:latest
201+
credentials:
202+
username: ${{ github.actor }}
203+
password: ${{ secrets.GITHUB_TOKEN }}
204+
steps:
205+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
206+
207+
- name: Install tools
208+
run: mise install --locked
209+
210+
- name: Lint
211+
run: mise run go:lint
212+
213+
- name: Build
214+
run: mise run go:build
215+
216+
- name: Test
217+
run: mise run go:test
218+
219+
- name: Proto check
220+
run: mise run go:proto:check

‎docs/index.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ navigation:
2323
title: "Observability"
2424
- folder: kubernetes
2525
title: "Kubernetes"
26+
- section: "SDKs"
27+
slug: sdks
28+
contents:
29+
- section: "Go SDK"
30+
slug: go
31+
contents:
32+
- page: "Getting Started"
33+
path: sdks/go/getting-started.mdx
34+
- page: "Architecture"
35+
path: sdks/go/architecture.mdx
36+
- page: "Error Handling"
37+
path: sdks/go/error-handling.mdx
38+
- page: "Authentication"
39+
path: sdks/go/authentication.mdx
2640
- folder: reference
2741
title: "Reference"
2842
- folder: security

‎docs/sdks/go/architecture.mdx‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
title: "Architecture"
5+
description: "Module structure, gRPC transport layer, and proto isolation pattern in the Go SDK."
6+
keywords: "Go SDK, Architecture, gRPC, Protobuf, Module Structure, Transport"
7+
---
8+
9+
The Go SDK follows a layered architecture that keeps protocol details
10+
internal while exposing idiomatic Go types to consumers.
11+
12+
## Module Structure
13+
14+
```
15+
sdk/go/
16+
├── openshell/v1/ # Public API surface
17+
│ ├── client.go # Top-level Client with sub-clients
18+
│ ├── gateway/ # Gateway client factory (reads CLI config)
19+
│ ├── edge/ # Edge API client
20+
│ ├── fake/ # In-memory fakes for testing
21+
│ ├── types/ # Domain types (Config, errors, options)
22+
│ ├── oidc/ # OIDC authentication
23+
│ └── internal/ # Internal helpers (not importable)
24+
│ ├── converter/ # Proto-to-SDK type conversion
25+
│ └── grpc/ # gRPC connection management
26+
└── proto/ # Proto definitions + generated code
27+
├── openshellv1/ # Generated .pb.go files
28+
├── datamodelv1/
29+
└── sandboxv1/
30+
```
31+
32+
## Transport Layer
33+
34+
The SDK communicates with the OpenShell gateway over gRPC. The transport
35+
is fully internal, and consumers interact only with Go types.
36+
37+
```
38+
Consumer Code
39+
│
40+
▼
41+
openshell/v1.Client ← Public API (Go types)
42+
│
43+
▼
44+
internal/converter ← Proto ↔ SDK type conversion
45+
│
46+
▼
47+
internal/grpc ← Connection management, TLS, auth
48+
│
49+
▼
50+
gRPC transport ← Wire protocol
51+
```
52+
53+
## Proto Isolation
54+
55+
Generated protobuf types live in `proto/` packages and are never exposed
56+
through the public API. The `internal/converter` package handles all
57+
translation between proto messages and SDK domain types.
58+
59+
This means:
60+
61+
- Consumers never import `proto/` packages directly.
62+
- Proto schema changes do not break the public API.
63+
- Deep copies happen at the boundary, so returned values are safe to mutate.
64+
65+
## Sub-Clients
66+
67+
The top-level `Client` provides access to domain-specific sub-clients:
68+
69+
| Method | Returns | Purpose |
70+
|--------|---------|---------|
71+
| `Sandboxes()` | `SandboxInterface` | Create, list, get, delete sandboxes |
72+
| `Providers()` | `ProviderInterface` | List and inspect compute providers |
73+
| `Services()` | `ServiceInterface` | Manage sandbox services |
74+
| `Exec()` | `ExecInterface` | Execute commands in sandboxes |
75+
| `Files()` | `FileInterface` | Upload and download files |
76+
| `Health()` | `HealthInterface` | Gateway health checks |
77+
| `SSH()` | `SSHInterface` | SSH tunnel management |
78+
| `TCP()` | `TCPInterface` | TCP port forwarding |
79+
| `Config()` | `ConfigInterface` | Sandbox configuration management |
80+
| `Policy()` | `PolicyInterface` | Network policy management |
81+
82+
## Client Construction
83+
84+
There are two ways to create a client:
85+
86+
**From gateway configuration** (reads `~/.config/openshell/`):
87+
88+
```go
89+
client, err := gateway.NewClient("my-gateway")
90+
```
91+
92+
**From explicit configuration**:
93+
94+
```go
95+
client, err := v1.NewClient(types.Config{
96+
Address: "localhost:8080",
97+
Auth: myAuthProvider,
98+
})
99+
```
100+
101+
## Concurrency
102+
103+
All client methods are safe for concurrent use. The underlying gRPC
104+
connection handles multiplexing. Call `client.Close()` when done to
105+
release resources.

‎docs/sdks/go/authentication.mdx‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
title: "Authentication"
5+
description: "OIDC authentication, token refresh, and gateway auth configuration for the Go SDK."
6+
keywords: "Go SDK, Authentication, OIDC, Token Refresh, TLS, Security"
7+
---
8+
9+
The Go SDK supports multiple authentication modes depending on how the
10+
gateway is configured. The gateway client reads auth settings from the
11+
CLI configuration automatically.
12+
13+
## Authentication Modes
14+
15+
| Mode | When to Use | Configuration |
16+
|------|-------------|---------------|
17+
| **OIDC** | Production gateways with identity provider | `openshell gateway auth` configures tokens |
18+
| **API Key** | Simple deployments, development | Set via gateway config or `WithAuth` option |
19+
| **None** | Local development, insecure gateways | Default when no auth is configured |
20+
21+
## Automatic Auth (Recommended)
22+
23+
When using `gateway.NewClient()`, authentication is resolved automatically
24+
from the CLI configuration:
25+
26+
```go
27+
// Auth is read from ~/.config/openshell/<gateway>/config.yaml
28+
client, err := gateway.NewClient("my-gateway")
29+
```
30+
31+
The CLI stores OIDC tokens after `openshell gateway auth`. The SDK reads
32+
these tokens from disk and wraps them with `RefreshableToken` for
33+
automatic re-reading when the token file is updated.
34+
35+
## Token Refresh
36+
37+
You can wrap any auth provider with `NewTokenRefresher` to add
38+
token-expiry-aware refresh logic with configurable leeway:
39+
40+
```go
41+
import v1 "github.com/NVIDIA/OpenShell/sdk/go/openshell/v1"
42+
43+
refresher := v1.NewTokenRefresher(baseAuth,
44+
v1.WithLeeway(30 * time.Second),
45+
v1.WithLogger(myLogger),
46+
)
47+
48+
client, err := gateway.NewClient("my-gateway",
49+
gateway.WithAuth(refresher),
50+
)
51+
```
52+
53+
## Custom Auth Provider
54+
55+
For programmatic authentication, implement the `AuthProvider` interface
56+
or use the built-in providers:
57+
58+
```go
59+
// Static API key
60+
client, err := gateway.NewClient("my-gateway",
61+
gateway.WithAuth(v1.StaticToken("my-api-key")),
62+
)
63+
```
64+
65+
The `AuthProvider` interface provides gRPC per-RPC credentials. Each
66+
call attaches the token to the request metadata automatically.
67+
68+
## TLS Configuration
69+
70+
Control TLS settings when connecting to gateways:
71+
72+
```go
73+
client, err := gateway.NewClient("my-gateway",
74+
gateway.WithTLS(&types.TLSConfig{
75+
Insecure: false,
76+
CAFile: "/path/to/ca.crt",
77+
}),
78+
)
79+
```
80+
81+
For local development with self-signed certificates, you can skip
82+
verification, but this should never be used in production.
83+
84+
## Testing with Fakes
85+
86+
The fake client does not require authentication. Use it in tests to
87+
avoid gateway dependencies:
88+
89+
```go
90+
import "github.com/NVIDIA/OpenShell/sdk/go/openshell/v1/fake"
91+
92+
func TestMyFeature(t *testing.T) {
93+
client := fake.NewClient()
94+
// Use client.Sandboxes(), client.Exec(), etc.
95+
// No gateway connection or auth needed.
96+
}
97+
```

‎docs/sdks/go/error-handling.mdx‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
title: "Error Handling"
5+
description: "SDK error types, gRPC status code mapping, and retry patterns."
6+
keywords: "Go SDK, Errors, gRPC, Status Codes, Retry, Error Handling"
7+
---
8+
9+
The SDK translates gRPC status codes into typed Go errors. All errors
10+
returned by client methods can be inspected with `errors.As` to extract
11+
structured details.
12+
13+
## StatusError
14+
15+
The primary error type is `types.StatusError`:
16+
17+
```go
18+
import "github.com/NVIDIA/OpenShell/sdk/go/openshell/v1/types"
19+
20+
sandbox, err := client.Sandboxes().Get(ctx, "missing")
21+
if err != nil {
22+
var se *types.StatusError
23+
if errors.As(err, &se) {
24+
fmt.Printf("Code: %d, Message: %s\n", se.Code, se.Message)
25+
}
26+
}
27+
```
28+
29+
## Error Codes
30+
31+
The SDK defines error codes that map to gRPC status codes:
32+
33+
| SDK Error Code | gRPC Status | Meaning |
34+
|----------------|-------------|---------|
35+
| `ErrorNotFound` | `NOT_FOUND` | Resource does not exist |
36+
| `ErrorAlreadyExists` | `ALREADY_EXISTS` | Resource name conflict |
37+
| `ErrorInvalidArgument` | `INVALID_ARGUMENT` | Bad request parameters |
38+
| `ErrorPermissionDenied` | `PERMISSION_DENIED` | Insufficient credentials |
39+
| `ErrorUnavailable` | `UNAVAILABLE` | Gateway is unreachable |
40+
| `ErrorDeadlineExceeded` | `DEADLINE_EXCEEDED` | Request timed out |
41+
| `ErrorCancelled` | `CANCELLED` | Request was cancelled |
42+
| `ErrorInternal` | `INTERNAL` | Server-side failure |
43+
| `ErrorUnimplemented` | `UNIMPLEMENTED` | Operation not supported |
44+
| `ErrorConflict` | `ABORTED` / `FAILED_PRECONDITION` | Conflicting operation |
45+
46+
## Checking Error Types
47+
48+
Use helper functions or direct comparison:
49+
50+
```go
51+
if err != nil {
52+
var se *types.StatusError
53+
if errors.As(err, &se) {
54+
switch se.Code {
55+
case types.ErrorNotFound:
56+
// Handle missing resource
57+
case types.ErrorUnavailable:
58+
// Retry or fail over
59+
default:
60+
// Log and return
61+
}
62+
}
63+
}
64+
```
65+
66+
## Retry Configuration
67+
68+
Configure automatic retries for transient failures:
69+
70+
```go
71+
client, err := gateway.NewClient("my-gateway",
72+
gateway.WithRetryPolicy(&types.RetryPolicy{
73+
MaxRetries: 3,
74+
InitialWait: 100 * time.Millisecond,
75+
}),
76+
)
77+
```
78+
79+
The retry policy applies to `Unavailable` and `DeadlineExceeded` errors.
80+
Other error codes are returned immediately without retrying.
81+
82+
## Context Cancellation
83+
84+
All client methods accept a `context.Context`. Cancelled or timed-out
85+
contexts produce standard Go `context.Canceled` or
86+
`context.DeadlineExceeded` errors:
87+
88+
```go
89+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
90+
defer cancel()
91+
92+
sandboxes, err := client.Sandboxes().List(ctx)
93+
if errors.Is(err, context.DeadlineExceeded) {
94+
// Request timed out
95+
}
96+
```

0 commit comments

Comments
 (0)