-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
540 additions
and
323 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,53 @@ | ||
package agent | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
"sync" | ||
|
||
"golang.org/x/crypto/ssh" | ||
"golang.org/x/crypto/ssh/agent" | ||
) | ||
|
||
var ( | ||
// Keep a single agent instance for all connection attempts | ||
inst agent.ExtendedAgent | ||
mu sync.Mutex | ||
) | ||
|
||
func getAgent() (agent.ExtendedAgent, error) { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
|
||
if inst != nil { | ||
return inst, nil | ||
} | ||
|
||
sock := os.Getenv("SSH_AUTH_SOCK") | ||
if sock == "" { | ||
return nil, fmt.Errorf("SSH_AUTH_SOCK is not set") | ||
} | ||
|
||
conn, err := net.Dial("unix", sock) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not dial agent: %v", err) | ||
} | ||
|
||
inst = agent.NewClient(conn) | ||
return inst, nil | ||
} | ||
|
||
func GetSigners() ([]ssh.Signer, error) { | ||
agent, err := getAgent() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
signers, err := agent.Signers() | ||
if err != nil { | ||
return nil, fmt.Errorf("could not retrieve signers from agent: %v", err) | ||
} | ||
|
||
return signers, nil | ||
} |
This file contains 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 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 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
Oops, something went wrong.