-
Notifications
You must be signed in to change notification settings - Fork 297
enhance: add support for args and aliases to credential tools #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
g-linville
merged 9 commits into
gptscript-ai:main
from
g-linville:credentials-with-args
Jun 6, 2024
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c9e6fea
enhance: add support for args and aliases to credential tools
g-linville fe56699
PR feedback
g-linville a7e0ee7
don't parse creds as comma separated
g-linville c68506a
bump golangci-lint version
g-linville e8ac806
update golangci config
g-linville b480699
update golangci config
g-linville f22fcbe
skip make validate on windows
g-linville dd2936b
fix GH workflow
g-linville be307eb
fix GH workflow
g-linville File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ run: | |
|
||
output: | ||
formats: | ||
- github-actions | ||
- format: github-actions | ||
|
||
linters: | ||
disable-all: true | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,7 +138,7 @@ func isParam(line string, tool *types.Tool) (_ bool, err error) { | |
return false, err | ||
} | ||
case "credentials", "creds", "credential", "cred": | ||
tool.Parameters.Credentials = append(tool.Parameters.Credentials, csv(strings.ToLower(value))...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was no need to be converting it to lowercase here. |
||
tool.Parameters.Credentials = append(tool.Parameters.Credentials, value) | ||
default: | ||
return false, nil | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParseCredentialArgs(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 |
||
tests := []struct { | ||
name string | ||
toolName string | ||
input string | ||
expectedName string | ||
expectedAlias string | ||
expectedArgs map[string]string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "empty", | ||
toolName: "", | ||
expectedName: "", | ||
expectedAlias: "", | ||
}, | ||
{ | ||
name: "tool name only", | ||
toolName: "myCredentialTool", | ||
expectedName: "myCredentialTool", | ||
expectedAlias: "", | ||
}, | ||
{ | ||
name: "tool name and alias", | ||
toolName: "myCredentialTool as myAlias", | ||
expectedName: "myCredentialTool", | ||
expectedAlias: "myAlias", | ||
}, | ||
{ | ||
name: "tool name with one arg", | ||
toolName: "myCredentialTool with value1 as arg1", | ||
expectedName: "myCredentialTool", | ||
expectedAlias: "", | ||
expectedArgs: map[string]string{ | ||
"arg1": "value1", | ||
}, | ||
}, | ||
{ | ||
name: "tool name with two args", | ||
toolName: "myCredentialTool with value1 as arg1 and value2 as arg2", | ||
expectedName: "myCredentialTool", | ||
expectedAlias: "", | ||
expectedArgs: map[string]string{ | ||
"arg1": "value1", | ||
"arg2": "value2", | ||
}, | ||
}, | ||
{ | ||
name: "tool name with alias and one arg", | ||
toolName: "myCredentialTool as myAlias with value1 as arg1", | ||
expectedName: "myCredentialTool", | ||
expectedAlias: "myAlias", | ||
expectedArgs: map[string]string{ | ||
"arg1": "value1", | ||
}, | ||
}, | ||
{ | ||
name: "tool name with alias and two args", | ||
toolName: "myCredentialTool as myAlias with value1 as arg1 and value2 as arg2", | ||
expectedName: "myCredentialTool", | ||
expectedAlias: "myAlias", | ||
expectedArgs: map[string]string{ | ||
"arg1": "value1", | ||
"arg2": "value2", | ||
}, | ||
}, | ||
{ | ||
name: "tool name with quoted args", | ||
toolName: `myCredentialTool with "value one" as arg1 and "value two" as arg2`, | ||
expectedName: "myCredentialTool", | ||
expectedAlias: "", | ||
expectedArgs: map[string]string{ | ||
"arg1": "value one", | ||
"arg2": "value two", | ||
}, | ||
}, | ||
{ | ||
name: "tool name with arg references", | ||
toolName: `myCredentialTool with ${var1} as arg1 and ${var2} as arg2`, | ||
input: `{"var1": "value1", "var2": "value2"}`, | ||
expectedName: "myCredentialTool", | ||
expectedAlias: "", | ||
expectedArgs: map[string]string{ | ||
"arg1": "value1", | ||
"arg2": "value2", | ||
}, | ||
}, | ||
{ | ||
name: "tool name with alias but no 'as' (invalid)", | ||
toolName: "myCredentialTool myAlias", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "tool name with 'as' but no alias (invalid)", | ||
toolName: "myCredentialTool as", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "tool with 'with' but no args (invalid)", | ||
toolName: "myCredentialTool with", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "tool with args but no 'with' (invalid)", | ||
toolName: "myCredentialTool value1 as arg1", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "tool with trailing 'and' (invalid)", | ||
toolName: "myCredentialTool with value1 as arg1 and", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "tool with quoted arg but the quote is unterminated (invalid)", | ||
toolName: `myCredentialTool with "value one" as arg1 and "value two as arg2`, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "invalid input", | ||
toolName: "myCredentialTool", | ||
input: `{"asdf":"asdf"`, | ||
wantErr: true, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
originalName, alias, args, err := ParseCredentialArgs(tt.toolName, tt.input) | ||
if tt.wantErr { | ||
require.Error(t, err, "expected an error but got none") | ||
return | ||
} | ||
|
||
require.NoError(t, err, "did not expect an error but got one") | ||
require.Equal(t, tt.expectedName, originalName, "unexpected original name") | ||
require.Equal(t, tt.expectedAlias, alias, "unexpected alias") | ||
require.Equal(t, len(tt.expectedArgs), len(args), "unexpected number of args") | ||
|
||
for k, v := range tt.expectedArgs { | ||
assert.Equal(t, v, args[k], "unexpected value for args[%s]", k) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.