@@ -48,6 +48,18 @@ type SSHPrivateKey struct {
4848 KnownHosts string `json:"knownHosts,omitempty"`
4949}
5050
51+ // DecodePrivateKey decodes the base64 encoded SSH private key.
52+ func (s * SSHPrivateKey ) DecodePrivateKey () ([]byte , error ) {
53+ if s .PrivateKey == "" {
54+ return nil , fmt .Errorf ("SSH private key is empty" )
55+ }
56+ privateKeyDecoded , err := base64 .StdEncoding .DecodeString (s .PrivateKey )
57+ if err != nil {
58+ return nil , fmt .Errorf ("failed to decode SSH private key: %w" , err )
59+ }
60+ return privateKeyDecoded , nil
61+ }
62+
5163// ParseConfig reads a YAML configuration file and returns a Config object.
5264func ParseConfig (path string ) (* Config , error ) {
5365 data , err := os .ReadFile (path )
@@ -134,9 +146,9 @@ func (c *Config) configureAuth() (auth transport.AuthMethod, err error) {
134146 }
135147
136148 if c .Authentication .SSHPrivateKey != nil {
137- privateKeyDecoded , err := base64 . StdEncoding . DecodeString ( c .Authentication .SSHPrivateKey .PrivateKey )
149+ privateKeyDecoded , err := c .Authentication .SSHPrivateKey .DecodePrivateKey ( )
138150 if err != nil {
139- return nil , fmt . Errorf ( "failed to decode SSH private key: %w" , err )
151+ return nil , err
140152 }
141153
142154 publicKeys , err := ssh .NewPublicKeys ("git" , privateKeyDecoded , "" )
0 commit comments