Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ Client
├── Providers() → ProviderInterface (CRUD + ensure)
│ ├── Profiles() → ProfileInterface (list, get, import, update, lint, delete)
│ └── Refresh() → RefreshInterface (configure, status, rotate, delete)
├── Secrets() → SecretInterface (update)
├── Workspaces() → WorkspaceInterface (create, get, list, delete, members)
└── Policy() → PolicyInterface (draft review, approve, reject, merge, status)
```
Expand Down Expand Up @@ -318,6 +319,7 @@ stream completion.
| Sandbox lifecycle (create, get, list, delete, watch, wait) | `SandboxInterface` | [Sandboxes](https://ai-openshell.github.io/sdk-go/api/sandboxes.html) |
| Command execution (collected, streamed, interactive PTY) | `ExecInterface` | [Exec](https://ai-openshell.github.io/sdk-go/api/exec.html) |
| Provider management (CRUD + idempotent ensure) | `ProviderInterface` | [Providers](https://ai-openshell.github.io/sdk-go/api/providers.html) |
| Secret metadata and value updates | `SecretInterface` | [Secrets](https://ai-openshell.github.io/sdk-go/api/secrets.html) |
| Provider profiles (list, import, lint, update) | `ProfileInterface` | [Profiles](https://ai-openshell.github.io/sdk-go/api/profiles.html) |
| Credential refresh (configure, rotate, status) | `RefreshInterface` | [Refresh](https://ai-openshell.github.io/sdk-go/api/refresh.html) |
| Service exposure (expose, list, delete) | `ServiceInterface` | [Services](https://ai-openshell.github.io/sdk-go/api/services.html) |
Expand Down
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [Sandbox Templates](api/sandbox-templates.md)
- [Exec](api/exec.md)
- [Providers](api/providers.md)
- [Secrets](api/secrets.md)
- [Profiles](api/profiles.md)
- [Refresh](api/refresh.md)
- [Services](api/services.md)
Expand Down
1 change: 1 addition & 0 deletions docs/src/api/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ for each resource domain and manages the underlying gRPC connection. The
| `Sandboxes()` | `SandboxInterface` | Sandbox lifecycle management |
| `SandboxTemplates()` | `SandboxTemplateInterface` | Reusable sandbox template management |
| `Providers()` | `ProviderInterface` | Provider CRUD and idempotent ensure |
| `Secrets()` | `SecretInterface` | Workspace secret updates |
| `Services()` | `ServiceInterface` | Service exposure and management |
| `ServiceRoutes()` | `ServiceDiscoveryInterface` | Installed route snapshots and watches (concrete client) |
| `Exec()` | `ExecInterface` | Command execution (run, stream, interactive) |
Expand Down
6 changes: 6 additions & 0 deletions docs/src/api/fake.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ client.AddProvider("default", &types.Provider{
Spec: types.ProviderSpec{Type: "docker"},
})

client.AddSecret("default", &types.Secret{
Name: "provider-api-key",
ResourceVersion: 1,
})

client.AddWorkspace(&types.Workspace{Name: "staging"})
client.AddMember("staging", &types.WorkspaceMember{
PrincipalSubject: "subject-123",
Expand All @@ -95,6 +100,7 @@ additive concrete-client accessors such as `SandboxTemplates()`:
| `Sandboxes()` | `SandboxInterface` | Full CRUD, Watch, WaitReady |
| `SandboxTemplates()` | `SandboxTemplateInterface` | Full CRUD |
| `Providers()` | `ProviderInterface` | Full CRUD, Ensure |
| `Secrets()` | `SecretInterface` | Partial update with optimistic concurrency |
| `Workspaces()` | `WorkspaceInterface` | Full CRUD, Members |
| `Health()` | `HealthInterface` | Configurable result |
| `Policy()` | `PolicyInterface` | List, GetStatus (draft ops return Unimplemented) |
Expand Down
36 changes: 36 additions & 0 deletions docs/src/api/secrets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Secrets

Accessor: `client.Secrets()`

Workspace secrets hold values that OpenShell does not return from ordinary
resource operations. Updating a secret returns metadata only; the value is not
included in the response.

## Update

`Update` applies only the fields whose pointers or maps are non-nil. Use a
non-nil empty labels map to remove all labels. `ExpectedResourceVersion`
provides optimistic concurrency when supplied.

```go
value := os.Getenv("NEW_API_KEY")
description := "rotated API key"
expectedVersion := secret.ResourceVersion

updated, err := client.Secrets().Update(ctx, "default", "provider-api-key", &v1.SecretUpdate{
Value: &value,
Description: &description,
Labels: map[string]string{"environment": "production"},
ExpectedResourceVersion: &expectedVersion,
RequestID: uuid.NewString(),
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("updated secret metadata to version %d\n", updated.ResourceVersion)
```

Do not log secret values or include them in error messages. A non-nil empty
`Value` is rejected by the server.

See also: [Error Handling](../error-handling.md), [Testing](../testing.md)
6 changes: 6 additions & 0 deletions openshell/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ClientInterface interface {
SandboxSuspendResume() SandboxSuspendResumeInterface
SandboxLogsWatch() SandboxLogsWatchInterface
Providers() ProviderInterface
Secrets() SecretInterface
Services() ServiceInterface
Exec() ExecInterface
Files() FileInterface
Expand Down Expand Up @@ -59,6 +60,7 @@ type Client struct {
logsWatch SandboxLogsWatchInterface
templates SandboxTemplateInterface
providers ProviderInterface
secrets SecretInterface
services ServiceInterface
serviceRoutes ServiceDiscoveryInterface
exec ExecInterface
Expand Down Expand Up @@ -108,6 +110,7 @@ func NewClient(cfg Config) (*Client, error) {
c.logsWatch = sandboxes
c.templates = newSandboxTemplateClient(conn)
c.providers = newProviderClient(conn)
c.secrets = newSecretClient(conn)
c.services = newServiceClient(conn)
c.serviceRoutes = newServiceDiscoveryClient(conn)
c.exec = newExecClient(conn, c.sandboxes)
Expand Down Expand Up @@ -143,6 +146,9 @@ func (c *Client) SandboxLogsWatch() SandboxLogsWatchInterface { return c.logsWat
// Providers returns the provider sub-client.
func (c *Client) Providers() ProviderInterface { return c.providers }

// Secrets returns the workspace secret sub-client.
func (c *Client) Secrets() SecretInterface { return c.secrets }

// Services returns the service sub-client.
func (c *Client) Services() ServiceInterface { return c.services }

Expand Down
1 change: 1 addition & 0 deletions openshell/v1/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestNewClient_ValidConfig(t *testing.T) {

assert.NotNil(t, client.Sandboxes())
assert.NotNil(t, client.Providers())
assert.NotNil(t, client.Secrets())
assert.NotNil(t, client.Exec())
assert.NotNil(t, client.Files())
assert.NotNil(t, client.Health())
Expand Down
16 changes: 16 additions & 0 deletions openshell/v1/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Client struct {
sandboxStore *objectStore[*types.Sandbox]
templateStore *objectStore[*types.SandboxWorkloadTemplate]
providerStore *objectStore[*types.Provider]
secretStore *objectStore[*types.Secret]
workspaceStore *objectStore[*types.Workspace]
memberStore *objectStore[*types.WorkspaceMember]
sandboxBroadcaster *watchBroadcaster[*types.Sandbox]
Expand All @@ -29,6 +30,7 @@ type Client struct {
logsWatch v1.SandboxLogsWatchInterface
templates v1.SandboxTemplateInterface
providers v1.ProviderInterface
secrets v1.SecretInterface
services v1.ServiceInterface
exec v1.ExecInterface
files v1.FileInterface
Expand Down Expand Up @@ -78,6 +80,7 @@ func NewClient(opts ...ClientOption) *Client {
sandboxStore: newobjectStore(sandboxName, copySandbox),
templateStore: newobjectStore(sandboxWorkloadTemplate, copySandboxWorkloadTemplate),
providerStore: newobjectStore(providerName, copyProvider),
secretStore: newobjectStore(secretName, copySecret),
workspaceStore: newobjectStore(workspaceName, copyWorkspace),
memberStore: newobjectStore(memberName, copyMember),
sandboxBroadcaster: newWatchBroadcaster[*types.Sandbox](),
Expand All @@ -90,6 +93,7 @@ func NewClient(opts ...ClientOption) *Client {
fc.logsWatch = sandboxes
fc.templates = newFakeSandboxTemplateClient(fc.templateStore, fc.isClosed)
fc.providers = newFakeProviderClient(fc.providerStore, fc.isClosed)
fc.secrets = newFakeSecretClient(fc.secretStore, fc.isClosed)
fc.services = newFakeServiceClient(fc.isClosed)
fc.exec = newFakeExecClient(fc.isClosed)
fc.files = newFakeFileClient(fc.isClosed)
Expand Down Expand Up @@ -138,6 +142,9 @@ func (fc *Client) SandboxLogsWatch() v1.SandboxLogsWatchInterface {
// Providers returns the provider sub-client.
func (fc *Client) Providers() v1.ProviderInterface { return fc.providers }

// Secrets returns the workspace secret sub-client.
func (fc *Client) Secrets() v1.SecretInterface { return fc.secrets }

// Services returns the service sub-client.
func (fc *Client) Services() v1.ServiceInterface { return fc.services }

Expand Down Expand Up @@ -209,6 +216,15 @@ func (fc *Client) AddProvider(workspace string, p *types.Provider) {
fc.providerStore.Insert(workspace, p)
}

// AddSecret inserts secret metadata directly into the store. The secret is
// deep-copied and its value is never retained by the fake client.
func (fc *Client) AddSecret(workspace string, secret *types.Secret) {
if secret == nil {
return
}
fc.secretStore.Insert(workspace, secret)
}

// AddWorkspace inserts a workspace directly into the store without triggering
// any side effects. This is intended for pre-seeding test fixtures before
// the test begins. The workspace is deep-copied on insert.
Expand Down
78 changes: 78 additions & 0 deletions openshell/v1/fake/secret.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package fake

import (
"context"
"fmt"
"time"

"github.com/ai-openshell/sdk-go/openshell/v1/types"
)

func secretName(secret *types.Secret) string {
return secret.Name
}

func copySecret(secret *types.Secret) *types.Secret {
if secret == nil {
return nil
}
result := *secret
result.Labels = copyStringMap(secret.Labels)
result.Annotations = copyStringMap(secret.Annotations)
if secret.DeletionTimestamp != nil {
deletionTimestamp := *secret.DeletionTimestamp
result.DeletionTimestamp = &deletionTimestamp
}
if secret.RefreshUse != nil {
result.RefreshUse = &types.SecretRefreshUse{
AllowedEndpoints: append([]string(nil), secret.RefreshUse.AllowedEndpoints...),
}
}
return &result
}

type fakeSecretClient struct {
store *objectStore[*types.Secret]
closedFunc func() bool
}

func newFakeSecretClient(store *objectStore[*types.Secret], closedFunc func() bool) *fakeSecretClient {
return &fakeSecretClient{store: store, closedFunc: closedFunc}
}

func (c *fakeSecretClient) Update(_ context.Context, workspace, name string, update *types.SecretUpdate) (*types.Secret, error) {
if c.closedFunc() {
return nil, &types.StatusError{Code: types.ErrorUnavailable, Message: "client is closed"}
}
if update == nil {
return nil, &types.StatusError{Code: types.ErrorInvalidArgument, Message: "secret update must not be nil"}
}

secret, err := c.store.Get(workspace, name)
if err != nil {
return nil, err
}
if update.ExpectedResourceVersion != nil && *update.ExpectedResourceVersion != secret.ResourceVersion {
return nil, &types.StatusError{
Code: types.ErrorConflict,
Message: fmt.Sprintf("secret %q resource version does not match", name),
}
}
if update.Value != nil {
if *update.Value == "" {
return nil, &types.StatusError{Code: types.ErrorInvalidArgument, Message: "secret value must not be empty"}
}
secret.ValueUpdateTime = time.Now().UTC()
}
if update.Description != nil {
secret.Description = *update.Description
}
if update.Labels != nil {
secret.Labels = copyStringMap(update.Labels)
}
secret.ResourceVersion++
return c.store.Update(workspace, secret)
}
130 changes: 130 additions & 0 deletions openshell/v1/fake/secret_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package fake

import (
"context"
"testing"
"time"

"github.com/ai-openshell/sdk-go/openshell/v1/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func newTestSecretClient() (*fakeSecretClient, *objectStore[*types.Secret]) {
store := newobjectStore(secretName, copySecret)
return newFakeSecretClient(store, func() bool { return false }), store
}

func TestSecretUpdate(t *testing.T) {
client, store := newTestSecretClient()
store.Insert("default", &types.Secret{
Name: "api-key",
Description: "old description",
Labels: map[string]string{"rotation": "pending"},
ResourceVersion: 3,
ValueUpdateTime: time.Date(2026, time.November, 1, 0, 0, 0, 0, time.UTC),
RefreshUse: &types.SecretRefreshUse{AllowedEndpoints: []string{"https://auth.example.com/token"}},
})

value := "new-value"
description := "rotated"
version := uint64(3)
result, err := client.Update(context.Background(), "default", "api-key", &types.SecretUpdate{
Value: &value,
Description: &description,
Labels: map[string]string{"rotation": "complete"},
ExpectedResourceVersion: &version,
})

require.NoError(t, err)
assert.Equal(t, "rotated", result.Description)
assert.Equal(t, map[string]string{"rotation": "complete"}, result.Labels)
assert.Equal(t, uint64(4), result.ResourceVersion)
assert.True(t, result.ValueUpdateTime.After(time.Date(2026, time.November, 1, 0, 0, 0, 0, time.UTC)))
assert.Equal(t, []string{"https://auth.example.com/token"}, result.RefreshUse.AllowedEndpoints)
}

func TestSecretUpdateClearsLabelsAndDescription(t *testing.T) {
client, store := newTestSecretClient()
store.Insert("default", &types.Secret{
Name: "api-key",
Description: "old description",
Labels: map[string]string{"environment": "production"},
ResourceVersion: 1,
})
emptyDescription := ""

result, err := client.Update(context.Background(), "default", "api-key", &types.SecretUpdate{
Description: &emptyDescription,
Labels: map[string]string{},
})

require.NoError(t, err)
assert.Empty(t, result.Description)
assert.Empty(t, result.Labels)
assert.NotNil(t, result.Labels)
}

func TestSecretUpdateDeepCopiesLabels(t *testing.T) {
client, store := newTestSecretClient()
store.Insert("default", &types.Secret{Name: "api-key", ResourceVersion: 1})
labels := map[string]string{"environment": "production"}

result, err := client.Update(context.Background(), "default", "api-key", &types.SecretUpdate{Labels: labels})
require.NoError(t, err)
labels["environment"] = "mutated"
result.Labels["environment"] = "result-mutated"

stored, err := store.Get("default", "api-key")
require.NoError(t, err)
assert.Equal(t, "production", stored.Labels["environment"])
}

func TestSecretUpdateRejectsResourceVersionMismatch(t *testing.T) {
client, store := newTestSecretClient()
store.Insert("default", &types.Secret{Name: "api-key", ResourceVersion: 2})
version := uint64(1)

result, err := client.Update(context.Background(), "default", "api-key", &types.SecretUpdate{
ExpectedResourceVersion: &version,
})

assert.Nil(t, result)
require.Error(t, err)
assert.True(t, types.IsConflict(err))
}

func TestSecretUpdateRejectsEmptyValue(t *testing.T) {
client, store := newTestSecretClient()
store.Insert("default", &types.Secret{Name: "api-key", ResourceVersion: 1})
emptyValue := ""

result, err := client.Update(context.Background(), "default", "api-key", &types.SecretUpdate{Value: &emptyValue})

assert.Nil(t, result)
require.Error(t, err)
assert.True(t, types.IsInvalidArgument(err))
}

func TestSecretUpdateNotFound(t *testing.T) {
client, _ := newTestSecretClient()

result, err := client.Update(context.Background(), "default", "missing", &types.SecretUpdate{})

assert.Nil(t, result)
require.Error(t, err)
assert.True(t, types.IsNotFound(err))
}

func TestSecretUpdateRejectsNilUpdate(t *testing.T) {
client, _ := newTestSecretClient()

result, err := client.Update(context.Background(), "default", "api-key", nil)

assert.Nil(t, result)
require.Error(t, err)
assert.True(t, types.IsInvalidArgument(err))
}
Loading