Skip to content

Commit ebc128c

Browse files
committed
update for stacked contexts
Signed-off-by: Grant Linville <[email protected]>
1 parent a28b579 commit ebc128c

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

credentials.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ type Credential struct {
2020
}
2121

2222
type CredentialRequest struct {
23-
Content string `json:"content"`
24-
AllContexts bool `json:"allContexts"`
25-
Context string `json:"context"`
26-
Name string `json:"name"`
23+
Content string `json:"content"`
24+
AllContexts bool `json:"allContexts"`
25+
Context []string `json:"context"`
26+
Name string `json:"name"`
2727
}

gptscript.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,12 @@ func (g *GPTScript) PromptResponse(ctx context.Context, resp PromptResponse) err
307307
return err
308308
}
309309

310-
func (g *GPTScript) ListCredentials(ctx context.Context, credCtx string, allContexts bool) ([]Credential, error) {
310+
func (g *GPTScript) ListCredentials(ctx context.Context, credCtxs []string, allContexts bool) ([]Credential, error) {
311311
req := CredentialRequest{}
312312
if allContexts {
313313
req.AllContexts = true
314314
} else {
315-
req.Context = credCtx
315+
req.Context = credCtxs
316316
}
317317

318318
out, err := g.runBasicCommand(ctx, "credentials", req)
@@ -337,9 +337,9 @@ func (g *GPTScript) CreateCredential(ctx context.Context, cred Credential) error
337337
return err
338338
}
339339

340-
func (g *GPTScript) RevealCredential(ctx context.Context, credCtx, name string) (Credential, error) {
340+
func (g *GPTScript) RevealCredential(ctx context.Context, credCtxs []string, name string) (Credential, error) {
341341
out, err := g.runBasicCommand(ctx, "credentials/reveal", CredentialRequest{
342-
Context: credCtx,
342+
Context: credCtxs,
343343
Name: name,
344344
})
345345
if err != nil {
@@ -355,7 +355,7 @@ func (g *GPTScript) RevealCredential(ctx context.Context, credCtx, name string)
355355

356356
func (g *GPTScript) DeleteCredential(ctx context.Context, credCtx, name string) error {
357357
_, err := g.runBasicCommand(ctx, "credentials/delete", CredentialRequest{
358-
Context: credCtx,
358+
Context: []string{credCtx}, // Only one context can be specified for delete operations
359359
Name: name,
360360
})
361361
return err

gptscript_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"testing"
1313

1414
"github.com/getkin/kin-openapi/openapi3"
15-
"github.com/stretchr/testify/assert"
15+
"github.com/stretchr/testify/require"
1616
)
1717

1818
var g *GPTScript
@@ -1467,21 +1467,21 @@ func TestCredentials(t *testing.T) {
14671467
Env: map[string]string{"ENV": "testing"},
14681468
RefreshToken: "my-refresh-token",
14691469
})
1470-
assert.NoError(t, err)
1470+
require.NoError(t, err)
14711471

14721472
// List
1473-
creds, err := g.ListCredentials(context.Background(), "testing", false)
1474-
assert.NoError(t, err)
1475-
assert.GreaterOrEqual(t, len(creds), 1)
1473+
creds, err := g.ListCredentials(context.Background(), []string{"testing"}, false)
1474+
require.NoError(t, err)
1475+
require.GreaterOrEqual(t, len(creds), 1)
14761476

14771477
// Reveal
1478-
cred, err := g.RevealCredential(context.Background(), "testing", name)
1479-
assert.NoError(t, err)
1480-
assert.Contains(t, cred.Env, "ENV")
1481-
assert.Equal(t, cred.Env["ENV"], "testing")
1482-
assert.Equal(t, cred.RefreshToken, "my-refresh-token")
1478+
cred, err := g.RevealCredential(context.Background(), []string{"testing"}, name)
1479+
require.NoError(t, err)
1480+
require.Contains(t, cred.Env, "ENV")
1481+
require.Equal(t, cred.Env["ENV"], "testing")
1482+
require.Equal(t, cred.RefreshToken, "my-refresh-token")
14831483

14841484
// Delete
14851485
err = g.DeleteCredential(context.Background(), "testing", name)
1486-
assert.NoError(t, err)
1486+
require.NoError(t, err)
14871487
}

0 commit comments

Comments
 (0)