@@ -48,52 +48,51 @@ type sshConfig struct {
48
48
IdentityFile string
49
49
}
50
50
51
- func AddSSHConfig (cfg config.PipedGit ) error {
51
+ func AddSSHConfig (cfg config.PipedGit ) ( string , error ) {
52
52
cfgPath := cfg .SSHConfigFilePath
53
53
if cfgPath == "" {
54
54
home , err := os .UserHomeDir ()
55
55
if err != nil {
56
- return fmt .Errorf ("failed to detect the current user's home directory: %w" , err )
56
+ return "" , fmt .Errorf ("failed to detect the current user's home directory: %w" , err )
57
57
}
58
58
cfgPath = path .Join (home , ".ssh" , "config" )
59
59
}
60
60
sshDir := filepath .Dir (cfgPath )
61
61
62
62
if err := os .MkdirAll (sshDir , 0700 ); err != nil {
63
- return fmt .Errorf ("failed to create a directory %s: %v" , sshDir , err )
63
+ return "" , fmt .Errorf ("failed to create a directory %s: %v" , sshDir , err )
64
64
}
65
65
66
66
sshKey , err := cfg .LoadSSHKey ()
67
67
if err != nil {
68
- return err
68
+ return "" , err
69
69
}
70
70
71
71
sshKeyFile , err := os .CreateTemp (sshDir , "piped-ssh-key-*" )
72
72
if err != nil {
73
- return err
73
+ return "" , err
74
74
}
75
75
76
- // TODO: Remove this key file when Piped terminating.
77
76
if _ , err := sshKeyFile .Write (sshKey ); err != nil {
78
- return err
77
+ return sshKeyFile . Name (), err
79
78
}
80
79
81
80
configData , err := generateSSHConfig (cfg , sshKeyFile .Name ())
82
81
if err != nil {
83
- return err
82
+ return sshKeyFile . Name (), err
84
83
}
85
84
86
85
f , err := os .OpenFile (cfgPath , os .O_APPEND | os .O_CREATE | os .O_WRONLY , 0644 )
87
86
if err != nil {
88
- return fmt .Errorf ("could not create/append to %s: %v" , cfgPath , err )
87
+ return sshKeyFile . Name (), fmt .Errorf ("could not create/append to %s: %v" , cfgPath , err )
89
88
}
90
89
defer f .Close ()
91
90
92
91
if _ , err := f .Write ([]byte (configData )); err != nil {
93
- return fmt .Errorf ("failed to write sshConfig to %s: %v" , cfgPath , err )
92
+ return sshKeyFile . Name (), fmt .Errorf ("failed to write sshConfig to %s: %v" , cfgPath , err )
94
93
}
95
94
96
- return nil
95
+ return sshKeyFile . Name (), nil
97
96
}
98
97
99
98
func generateSSHConfig (cfg config.PipedGit , sshKeyFile string ) (string , error ) {
0 commit comments