package com.cgi.eoss.ftep.clouds.service;

import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.transport.verification.PromiscuousVerifier;

import java.io.Closeable;
import java.io.IOException;

/**
 */
public class SSHSession implements Closeable {

    private final SSHClient sshClient;

    public SSHSession(String host, String username, String privateKey, String publicKey) throws IOException {
        sshClient = new SSHClient();
        sshClient.addHostKeyVerifier(new PromiscuousVerifier());
        sshClient.connect(host);
        sshClient.authPublickey(username, sshClient.loadKeys(privateKey, publicKey, null));
    }

    public CommandResponse exec(String cmd) throws IOException {
        try (Session session = sshClient.startSession()) {
            return new CommandResponse(session.exec(cmd));
        }
    }

    @Override
    public void close() throws IOException {
        this.sshClient.disconnect();
    }


}

@@ -36,16 +36,51 @@
 rvice;%0A%0A
+import lombok.extern.log4j.Log4j2;%0A
 import n
@@ -297,16 +297,24 @@
 /**%0A */%0A
+@Log4j2%0A
 public c
@@ -877,14 +877,41 @@
     
-return
+CommandResponse commandResponse =
  new
@@ -943,24 +943,196 @@
 exec(cmd));%0A
+            LOG.debug(%22Exit status: %7B%7D, output: %7B%7D for command %7B%7D%22, commandResponse.getExitStatus(), commandResponse.getOutput(), cmd);%0A            return commandResponse;%0A
         %7D%0A  

Add logging for SSH commands