@@ -115,17 +115,22 @@ private void initialize() {
115115 }
116116 }
117117 // Set up the ssh keys if used
118- if (Boolean .parseBoolean (props .getProperty ("use_ssh_keys" , "false" ))) {
119- File sshDir = new File (FS .DETECTED .userHome (), ".ssh" );
120- JGitKeyCache cache = new JGitKeyCache ();
121- SshdSessionFactoryBuilder builder = new SshdSessionFactoryBuilder ();
122- if (props .containsKey ("private_key" )) {
123- File key = new File (props .getProperty ("private_key" ));
124- builder .setDefaultKeysProvider (file -> new CachingKeyPairProvider (List .of (key .getAbsoluteFile ().toPath ()), cache ));
125- }
126- builder .setHomeDirectory (FS .DETECTED .userHome ());
127- builder .setSshDirectory (sshDir );
128- sshdSessionFactory = builder .build (cache );
118+ if (props .containsKey ("use_ssh_keys" ) && Boolean .parseBoolean (props .getProperty ("use_ssh_keys" ))) {
119+ try {
120+ File sshDir = new File (FS .DETECTED .userHome (), ".ssh" );
121+ JGitKeyCache cache = new JGitKeyCache ();
122+ SshdSessionFactoryBuilder builder = new SshdSessionFactoryBuilder ();
123+ if (props .containsKey ("private_key" )) {
124+ File key = new File (props .getProperty ("private_key" ));
125+ builder .setDefaultKeysProvider (file -> new CachingKeyPairProvider (List .of (key .getAbsoluteFile ().toPath ()), cache ));
126+ }
127+ builder .setHomeDirectory (FS .DETECTED .userHome ());
128+ builder .setSshDirectory (sshDir );
129+ sshdSessionFactory = builder .build (cache );
130+ } catch (NullPointerException e ) {
131+ logger .log (Level .WARNING , "Failed to open .ssh/private_key" , e );
132+ }
133+
129134 }
130135 // Setup basic username/password auth
131136 if (props .containsKey ("username" ) && props .containsKey ("password" )) {
@@ -268,7 +273,7 @@ private synchronized void processAlarmConfigMessages(String rawPath, String alar
268273 PushCommand pushCommand = git .push ();
269274 pushCommand .setRemote (REMOTE_NAME );
270275 pushCommand .setForce (true );
271- if (Boolean .parseBoolean (props .getProperty ("use_ssh_keys" , "false" ))) {
276+ if (Boolean .parseBoolean (props .getProperty ("use_ssh_keys" ))) {
272277 pushCommand .setTransportConfigCallback (transport -> {
273278 SshTransport sshTransport = (SshTransport ) transport ;
274279 sshTransport .setSshSessionFactory (sshdSessionFactory );
0 commit comments