6
6
"errors"
7
7
"fmt"
8
8
"sort"
9
+ "strings"
9
10
"sync"
10
11
"time"
11
12
@@ -791,9 +792,18 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
791
792
refresh bool
792
793
)
793
794
794
- c , exists , err = r .credStore .Get (callCtx .Ctx , credName )
795
- if err != nil {
796
- return nil , fmt .Errorf ("failed to get credentials for tool %s: %w" , toolName , err )
795
+ // Only try to look up the cred if the tool is on GitHub or has an alias.
796
+ // If it is a GitHub tool and has an alias, the alias overrides the tool name, so we use it as the credential name.
797
+ if isGitHubTool (toolName ) && credentialAlias == "" {
798
+ c , exists , err = r .credStore .Get (callCtx .Ctx , toolName )
799
+ if err != nil {
800
+ return nil , fmt .Errorf ("failed to get credentials for tool %s: %w" , toolName , err )
801
+ }
802
+ } else if credentialAlias != "" {
803
+ c , exists , err = r .credStore .Get (callCtx .Ctx , credentialAlias )
804
+ if err != nil {
805
+ return nil , fmt .Errorf ("failed to get credential %s: %w" , credentialAlias , err )
806
+ }
797
807
}
798
808
799
809
if c == nil {
@@ -859,17 +869,22 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
859
869
}
860
870
861
871
if ! resultCredential .Ephemeral {
862
- if isEmpty {
863
- log .Warnf ("Not saving empty credential for tool %s" , toolName )
864
- } else {
865
- if refresh {
866
- err = r .credStore .Refresh (callCtx .Ctx , resultCredential )
872
+ // Only store the credential if the tool is on GitHub or has an alias, and the credential is non-empty.
873
+ if (isGitHubTool (toolName ) && callCtx .Program .ToolSet [ref .ToolID ].Source .Repo != nil ) || credentialAlias != "" {
874
+ if isEmpty {
875
+ log .Warnf ("Not saving empty credential for tool %s" , toolName )
867
876
} else {
868
- err = r .credStore .Add (callCtx .Ctx , resultCredential )
869
- }
870
- if err != nil {
871
- return nil , fmt .Errorf ("failed to save credential for tool %s: %w" , toolName , err )
877
+ if refresh {
878
+ err = r .credStore .Refresh (callCtx .Ctx , resultCredential )
879
+ } else {
880
+ err = r .credStore .Add (callCtx .Ctx , resultCredential )
881
+ }
882
+ if err != nil {
883
+ return nil , fmt .Errorf ("failed to save credential for tool %s: %w" , toolName , err )
884
+ }
872
885
}
886
+ } else {
887
+ log .Warnf ("Not saving credential for tool %s - credentials will only be saved for tools from GitHub, or tools that use aliases." , toolName )
873
888
}
874
889
}
875
890
} else {
@@ -891,3 +906,7 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
891
906
892
907
return env , nil
893
908
}
909
+
910
+ func isGitHubTool (toolName string ) bool {
911
+ return strings .HasPrefix (toolName , "github.com" )
912
+ }
0 commit comments