4
4
"fmt"
5
5
"os"
6
6
"os/exec"
7
+ "os/signal"
7
8
"strings"
8
9
9
10
"github.com/spf13/cobra"
@@ -18,11 +19,18 @@ func gitssh() *cobra.Command {
18
19
Hidden : true ,
19
20
Short : `Wraps the "ssh" command and uses the coder gitssh key for authentication` ,
20
21
RunE : func (cmd * cobra.Command , args []string ) error {
22
+ ctx := cmd .Context ()
23
+
24
+ // Catch interrupt signals as a best-effort attempt to clean
25
+ // up the temporary key file.
26
+ ctx , stop := signal .NotifyContext (ctx , interruptSignals ... )
27
+ defer stop ()
28
+
21
29
client , err := createAgentClient (cmd )
22
30
if err != nil {
23
31
return xerrors .Errorf ("create agent client: %w" , err )
24
32
}
25
- key , err := client .AgentGitSSHKey (cmd . Context () )
33
+ key , err := client .AgentGitSSHKey (ctx )
26
34
if err != nil {
27
35
return xerrors .Errorf ("get agent git ssh token: %w" , err )
28
36
}
@@ -45,7 +53,7 @@ func gitssh() *cobra.Command {
45
53
}
46
54
47
55
args = append ([]string {"-i" , privateKeyFile .Name ()}, args ... )
48
- c := exec .CommandContext (cmd . Context () , "ssh" , args ... )
56
+ c := exec .CommandContext (ctx , "ssh" , args ... )
49
57
c .Stderr = cmd .ErrOrStderr ()
50
58
c .Stdout = cmd .OutOrStdout ()
51
59
c .Stdin = cmd .InOrStdin ()
0 commit comments