@@ -419,9 +419,13 @@ func (r *Runner) start(callCtx engine.Context, state *State, monitor Monitor, en
419
419
return nil , err
420
420
}
421
421
422
- if len (callCtx .Tool .Credentials ) > 0 {
422
+ credTools , err := callCtx .Tool .GetCredentialTools (* callCtx .Program , callCtx .AgentGroup )
423
+ if err != nil {
424
+ return nil , err
425
+ }
426
+ if len (credTools ) > 0 {
423
427
var err error
424
- env , err = r .handleCredentials (callCtx , monitor , env )
428
+ env , err = r .handleCredentials (callCtx , monitor , env , credTools )
425
429
if err != nil {
426
430
return nil , err
427
431
}
@@ -552,9 +556,13 @@ func (r *Runner) resume(callCtx engine.Context, monitor Monitor, env []string, s
552
556
progress , progressClose := streamProgress (& callCtx , monitor )
553
557
defer progressClose ()
554
558
555
- if len (callCtx .Tool .Credentials ) > 0 {
559
+ credTools , err := callCtx .Tool .GetCredentialTools (* callCtx .Program , callCtx .AgentGroup )
560
+ if err != nil {
561
+ return nil , err
562
+ }
563
+ if len (credTools ) > 0 {
556
564
var err error
557
- env , err = r .handleCredentials (callCtx , monitor , env )
565
+ env , err = r .handleCredentials (callCtx , monitor , env , credTools )
558
566
if err != nil {
559
567
return nil , err
560
568
}
@@ -828,7 +836,7 @@ func getEventContent(content string, callCtx engine.Context) string {
828
836
return content
829
837
}
830
838
831
- func (r * Runner ) handleCredentials (callCtx engine.Context , monitor Monitor , env []string ) ([]string , error ) {
839
+ func (r * Runner ) handleCredentials (callCtx engine.Context , monitor Monitor , env []string , credToolRefs []types. ToolReference ) ([]string , error ) {
832
840
// Since credential tools (usually) prompt the user, we want to only run one at a time.
833
841
r .credMutex .Lock ()
834
842
defer r .credMutex .Unlock ()
@@ -845,10 +853,10 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
845
853
}
846
854
}
847
855
848
- for _ , credToolName := range callCtx . Tool . Credentials {
849
- toolName , credentialAlias , args , err := types .ParseCredentialArgs (credToolName , callCtx .Input )
856
+ for _ , ref := range credToolRefs {
857
+ toolName , credentialAlias , args , err := types .ParseCredentialArgs (ref . Reference , callCtx .Input )
850
858
if err != nil {
851
- return nil , fmt .Errorf ("failed to parse credential tool %q: %w" , credToolName , err )
859
+ return nil , fmt .Errorf ("failed to parse credential tool %q: %w" , ref . Reference , err )
852
860
}
853
861
854
862
credName := toolName
@@ -895,11 +903,6 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
895
903
// If the credential doesn't already exist in the store, run the credential tool in order to get the value,
896
904
// and save it in the store.
897
905
if ! exists || c .IsExpired () {
898
- credToolRefs , ok := callCtx .Tool .ToolMapping [credToolName ]
899
- if ! ok || len (credToolRefs ) != 1 {
900
- return nil , fmt .Errorf ("failed to find ID for tool %s" , credToolName )
901
- }
902
-
903
906
// If the existing credential is expired, we need to provide it to the cred tool through the environment.
904
907
if exists && c .IsExpired () {
905
908
credJSON , err := json .Marshal (c )
@@ -914,22 +917,22 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
914
917
if args != nil {
915
918
inputBytes , err := json .Marshal (args )
916
919
if err != nil {
917
- return nil , fmt .Errorf ("failed to marshal args for tool %s: %w" , credToolName , err )
920
+ return nil , fmt .Errorf ("failed to marshal args for tool %s: %w" , ref . Reference , err )
918
921
}
919
922
input = string (inputBytes )
920
923
}
921
924
922
- res , err := r .subCall (callCtx .Ctx , callCtx , monitor , env , credToolRefs [ 0 ] .ToolID , input , "" , engine .CredentialToolCategory )
925
+ res , err := r .subCall (callCtx .Ctx , callCtx , monitor , env , ref .ToolID , input , "" , engine .CredentialToolCategory )
923
926
if err != nil {
924
- return nil , fmt .Errorf ("failed to run credential tool %s: %w" , credToolName , err )
927
+ return nil , fmt .Errorf ("failed to run credential tool %s: %w" , ref . Reference , err )
925
928
}
926
929
927
930
if res .Result == nil {
928
- return nil , fmt .Errorf ("invalid state: credential tool [%s] can not result in a continuation" , credToolName )
931
+ return nil , fmt .Errorf ("invalid state: credential tool [%s] can not result in a continuation" , ref . Reference )
929
932
}
930
933
931
934
if err := json .Unmarshal ([]byte (* res .Result ), & c ); err != nil {
932
- return nil , fmt .Errorf ("failed to unmarshal credential tool %s response: %w" , credToolName , err )
935
+ return nil , fmt .Errorf ("failed to unmarshal credential tool %s response: %w" , ref . Reference , err )
933
936
}
934
937
c .ToolName = credName
935
938
c .Type = credentials .CredentialTypeTool
@@ -943,7 +946,7 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
943
946
}
944
947
945
948
// Only store the credential if the tool is on GitHub or has an alias, and the credential is non-empty.
946
- if (isGitHubTool (toolName ) && callCtx .Program .ToolSet [credToolRefs [ 0 ] .ToolID ].Source .Repo != nil ) || credentialAlias != "" {
949
+ if (isGitHubTool (toolName ) && callCtx .Program .ToolSet [ref .ToolID ].Source .Repo != nil ) || credentialAlias != "" {
947
950
if isEmpty {
948
951
log .Warnf ("Not saving empty credential for tool %s" , toolName )
949
952
} else if err := r .credStore .Add (callCtx .Ctx , * c ); err != nil {
0 commit comments