This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support SSH public key authentication for submodules (#102)
- Loading branch information
1 parent
d1998da
commit 1ea4c0b
Showing
4 changed files
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package in | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
type AgentRunner interface { | ||
Start() error | ||
AddKey(key string) error | ||
} | ||
|
||
func NewAgentRunner() AgentRunner { | ||
return &AgentRunnerImpl{ | ||
sockPath: "/tmp/ssh-agent.sock", | ||
} | ||
} | ||
|
||
type AgentRunnerImpl struct { | ||
sockPath string | ||
agent *exec.Cmd | ||
} | ||
|
||
func (r *AgentRunnerImpl) Start() error { | ||
if r.agent != nil { | ||
return nil // already running | ||
} | ||
agent := exec.Command("ssh-agent", "-a", r.sockPath) | ||
agent.Stdin = os.Stdin | ||
agent.Stderr = os.Stderr | ||
err := agent.Run() | ||
if err != nil { | ||
return err | ||
} | ||
r.agent = agent | ||
os.Setenv("SSH_AUTH_SOCK", r.sockPath) | ||
return nil | ||
} | ||
|
||
func (r AgentRunnerImpl) AddKey(key string) error { | ||
command := exec.Command("ssh-add", "-") | ||
command.Stderr = os.Stderr | ||
command.Stdin = strings.NewReader(key + "\n") // this trailing newline is mandatory or ssh-add will fail | ||
err := command.Run() | ||
if err != nil { | ||
return err | ||
} | ||
return 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