-
Notifications
You must be signed in to change notification settings - Fork 293
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
enhance: add support for args and aliases to credential tools #433
Conversation
@@ -136,7 +136,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 comment
The reason will be displayed to describe this comment to others. Learn more.
There was no need to be converting it to lowercase here.
04e1e48
to
2479f1f
Compare
Can this be a built-in credential tool, or are we going to publish a basic one to handle this? |
@cloudnautique we're going to have a generic credential tool that will be a separate repo. This PR is just the changes needed to support such a thing, plus a few other enhancements. |
2479f1f
to
00383b2
Compare
f4cb837
to
cb638ce
Compare
Signed-off-by: Grant Linville <[email protected]>
cb638ce
to
c9e6fea
Compare
pkg/types/credential_test.go
Outdated
originalName, alias, args, err := ParseCredentialArgs(tt.toolName, tt.input) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ParseCredentialArgs() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if originalName != tt.expectedName { | ||
t.Errorf("ParseCredentialArgs() originalName = %v, expectedName %v", originalName, tt.expectedName) | ||
} | ||
if alias != tt.expectedAlias { | ||
t.Errorf("ParseCredentialArgs() alias = %v, expectedAlias %v", alias, tt.expectedAlias) | ||
} | ||
if len(args) != len(tt.expectedArgs) { | ||
t.Errorf("ParseCredentialArgs() args = %v, expectedArgs %v", args, tt.expectedArgs) | ||
} | ||
for k, v := range tt.expectedArgs { | ||
if args[k] != v { | ||
t.Errorf("ParseCredentialArgs() args[%s] = %v, expectedArgs[%s] %v", k, args[k], k, v) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using the github.com/stretchr/testify/assert
and github.com/stretchr/testify/require
packages:
originalName, alias, args, err := ParseCredentialArgs(tt.toolName, tt.input) | |
if (err != nil) != tt.wantErr { | |
t.Errorf("ParseCredentialArgs() error = %v, wantErr %v", err, tt.wantErr) | |
return | |
} | |
if originalName != tt.expectedName { | |
t.Errorf("ParseCredentialArgs() originalName = %v, expectedName %v", originalName, tt.expectedName) | |
} | |
if alias != tt.expectedAlias { | |
t.Errorf("ParseCredentialArgs() alias = %v, expectedAlias %v", alias, tt.expectedAlias) | |
} | |
if len(args) != len(tt.expectedArgs) { | |
t.Errorf("ParseCredentialArgs() args = %v, expectedArgs %v", args, tt.expectedArgs) | |
} | |
for k, v := range tt.expectedArgs { | |
if args[k] != v { | |
t.Errorf("ParseCredentialArgs() args[%s] = %v, expectedArgs[%s] %v", k, args[k], k, v) | |
} | |
} | |
originalName, alias, args, err := ParseCredentialArgs(tt.toolName, tt.input) | |
// Require halts the test immediately when an assertion fails | |
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 marks the test as failed when an assertion fails, but doesn't halt, allowing the test to progress further and identify more potential issues | |
assert.Equal(t, v, args[k], "unexpected value for args[%s]", k) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh thanks lol. I let Copilot generate basically all of this stuff and did not bother to think how it could be improved. Lazy me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
pkg/runner/runner.go
Outdated
@@ -838,12 +848,21 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env | |||
return nil, fmt.Errorf("failed to find ID for tool %s", credToolName) | |||
} | |||
|
|||
subCtx, err := callCtx.SubCall(callCtx.Ctx, "", credToolRefs[0].ToolID, "", engine.CredentialToolCategory) // leaving callID as "" will cause it to be set by the engine | |||
input := "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
input := "" | |
var input string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
Signed-off-by: Grant Linville <[email protected]>
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestParseCredentialArgs(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
This adds support for aliases and arguments in credential tools. Read the docs changes in the PR to find out how it works.