2323 tmpSockPath string
2424)
2525
26+ func setupProcessSSHAgent (sshAuthSock string ) error {
27+ SSHAuthSock = sshAuthSock
28+ return os .Setenv ("SSH_AUTH_SOCK" , SSHAuthSock )
29+ }
30+
2631func Init (ctx context.Context , keys []string ) error {
2732 for _ , key := range keys {
2833 if keyExists , err := util .FileExists (key ); ! keyExists {
@@ -35,10 +40,11 @@ func Init(ctx context.Context, keys []string) error {
3540 if len (keys ) > 0 {
3641 agentSock , err := runSSHAgentWithKeys (ctx , keys )
3742 if err != nil {
38- return err
43+ return fmt .Errorf ("unable to run ssh agent with specified keys: %s" , err )
44+ }
45+ if err := setupProcessSSHAgent (agentSock ); err != nil {
46+ return fmt .Errorf ("unable to init ssh auth socket to %q: %s" , agentSock , err )
3947 }
40- SSHAuthSock = agentSock
41-
4248 return nil
4349 }
4450
@@ -80,9 +86,11 @@ func Init(ctx context.Context, keys []string) error {
8086 if len (validKeys ) > 0 {
8187 agentSock , err := runSSHAgentWithKeys (ctx , validKeys )
8288 if err != nil {
83- return err
89+ return fmt .Errorf ("unable to run ssh agent with specified keys: %s" , err )
90+ }
91+ if err := setupProcessSSHAgent (agentSock ); err != nil {
92+ return fmt .Errorf ("unable to init ssh auth socket to %q: %s" , agentSock , err )
8493 }
85- SSHAuthSock = agentSock
8694 }
8795 }
8896
0 commit comments