From f48fad783122bb0e9ec3353b54ce1e47f5b7eab6 Mon Sep 17 00:00:00 2001 From: Rodrigo Navarro Date: Mon, 21 Oct 2024 10:03:19 -0300 Subject: [PATCH 1/2] add pty option --- .../java/com/plugin/sshjplugin/SSHJBuilder.java | 2 +- .../plugin/sshjplugin/SSHJNodeExecutorPlugin.java | 14 ++++++++++++++ .../plugin/sshjplugin/model/SSHJConnection.java | 3 +++ .../sshjplugin/model/SSHJConnectionParameters.java | 5 ++++- .../java/com/plugin/sshjplugin/model/SSHJExec.java | 8 ++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/plugin/sshjplugin/SSHJBuilder.java b/src/main/java/com/plugin/sshjplugin/SSHJBuilder.java index 6295459..1a07de9 100644 --- a/src/main/java/com/plugin/sshjplugin/SSHJBuilder.java +++ b/src/main/java/com/plugin/sshjplugin/SSHJBuilder.java @@ -22,7 +22,7 @@ static SSHJExec build(final INodeEntry nodeentry, SSHJExec sshbase = new SSHJExec(); final String commandString = StringUtils.join(args, " "); sshbase.setCommand(commandString); - + sshbase.setAllowPTY(sshjConnectionParameters.isAllocatePTY()); configureSSHBase(nodeentry, sshjConnectionParameters, sshbase, logger); addEnvVars(sshbase, dataContext); diff --git a/src/main/java/com/plugin/sshjplugin/SSHJNodeExecutorPlugin.java b/src/main/java/com/plugin/sshjplugin/SSHJNodeExecutorPlugin.java index 1f1499a..ae32564 100644 --- a/src/main/java/com/plugin/sshjplugin/SSHJNodeExecutorPlugin.java +++ b/src/main/java/com/plugin/sshjplugin/SSHJNodeExecutorPlugin.java @@ -78,6 +78,7 @@ public class SSHJNodeExecutorPlugin implements NodeExecutor, ProxySecretBundleCr public static final String NODE_ATTR_USE_SFTP = "use-sftp"; public static final String PROJECT_SSH_USER = PROJ_PROP_PREFIX + "ssh.user"; + public static final String CONFIG_SET_PTY = "always-set-pty"; public static final String FWK_PROP_SSH_AUTHENTICATION = FWK_PROP_PREFIX + NODE_ATTR_SSH_AUTHENTICATION; public static final String PROJ_PROP_SSH_AUTHENTICATION = PROJ_PROP_PREFIX + NODE_ATTR_SSH_AUTHENTICATION; @@ -105,6 +106,10 @@ public class SSHJNodeExecutorPlugin implements NodeExecutor, ProxySecretBundleCr public static final String FWK_PROP_USE_SFTP = FWK_PROP_PREFIX + NODE_ATTR_USE_SFTP; public static final String PROJ_PROP_USE_SFTP = PROJ_PROP_PREFIX + NODE_ATTR_USE_SFTP; + public static final String NODE_ATTR_ALWAYS_SET_PTY = "always-set-pty"; + public static final String FWK_PROP_SET_PTY = FWK_PROP_PREFIX + NODE_ATTR_ALWAYS_SET_PTY; + public static final String PROJ_PROP_SET_PTY = PROJ_PROP_PREFIX + NODE_ATTR_ALWAYS_SET_PTY; + public static final String SUDO_OPT_PREFIX = "sudo-"; public static final String DEFAULT_SUDO_PROMPT_PATTERN = "[sudo] password for"; @@ -182,6 +187,10 @@ public class SSHJNodeExecutorPlugin implements NodeExecutor, ProxySecretBundleCr "Use SFTP for file transfer", false, "false"); + public static final Property ALWAYS_SET_PTY = PropertyUtil.bool(CONFIG_SET_PTY, "Force PTY", + "Always force use of new pty, enabling this option will suppress some logging", + false, "false"); + private SSHClient sshClient; public void setSshClient(SSHClient sshClient) { @@ -210,6 +219,7 @@ public Description getDescription() { builder.property(SSH_KEEP_ALIVE_MAX_ALIVE_COUNT); builder.property(SSH_RETRY_ENABLE); builder.property(SSH_RETRY_COUNTER); + builder.property(ALWAYS_SET_PTY); //mapping config input on project and framework level builder.mapping(CONFIG_KEYPATH, PROJ_PROP_SSH_KEYPATH); @@ -233,6 +243,9 @@ public Description getDescription() { builder.mapping(CONFIG_RETRY_ENABLE, PROJ_PROP_RETRY_ENABLE); builder.frameworkMapping(CONFIG_RETRY_ENABLE, FWK_PROP_RETRY_ENABLE); + builder.mapping(CONFIG_SET_PTY, PROJ_PROP_SET_PTY); + builder.frameworkMapping(CONFIG_SET_PTY, FWK_PROP_SET_PTY); + return builder.build(); } @@ -246,6 +259,7 @@ public NodeExecutorResult executeCommand(ExecutionContext context, String[] comm node ); } + boolean success = false; final ExecutionListener listener = context.getExecutionListener(); diff --git a/src/main/java/com/plugin/sshjplugin/model/SSHJConnection.java b/src/main/java/com/plugin/sshjplugin/model/SSHJConnection.java index c8905b4..ca7f82e 100644 --- a/src/main/java/com/plugin/sshjplugin/model/SSHJConnection.java +++ b/src/main/java/com/plugin/sshjplugin/model/SSHJConnection.java @@ -66,4 +66,7 @@ static enum AuthenticationType { Map getSshConfig(); String getBindAddress(); + + boolean isAllocatePTY(); + } diff --git a/src/main/java/com/plugin/sshjplugin/model/SSHJConnectionParameters.java b/src/main/java/com/plugin/sshjplugin/model/SSHJConnectionParameters.java index a564279..6b34076 100644 --- a/src/main/java/com/plugin/sshjplugin/model/SSHJConnectionParameters.java +++ b/src/main/java/com/plugin/sshjplugin/model/SSHJConnectionParameters.java @@ -297,7 +297,10 @@ public Map getSshConfig() { public String getBindAddress() { return null; } - + @Override + public boolean isAllocatePTY() { + return propertyResolver.resolveBoolean(SSHJNodeExecutorPlugin.CONFIG_SET_PTY); + } diff --git a/src/main/java/com/plugin/sshjplugin/model/SSHJExec.java b/src/main/java/com/plugin/sshjplugin/model/SSHJExec.java index 8462c57..100572a 100644 --- a/src/main/java/com/plugin/sshjplugin/model/SSHJExec.java +++ b/src/main/java/com/plugin/sshjplugin/model/SSHJExec.java @@ -24,11 +24,16 @@ public class SSHJExec extends SSHJBase implements SSHJEnvironments { private String command = null; private int exitStatus = -1; private Map envVars = null; + private boolean allowPTY = false; public void setCommand(String command) { this.command = command; } + public void setAllowPTY(boolean allowPTY){ + this.allowPTY = allowPTY; + } + public void setPluginLogger(PluginLogger pluginLogger) { this.pluginLogger = pluginLogger; } @@ -53,6 +58,9 @@ public void execute(SSHClient ssh) { pluginLogger.log(3, "["+getPluginName()+"] starting session" ); session = ssh.startSession(); + if(this.allowPTY){ + session.allocateDefaultPTY(); + } pluginLogger.log(3, "["+getPluginName()+"] setting environments" ); From df4199efc82eaf18accd2cf139beb33705a84e99 Mon Sep 17 00:00:00 2001 From: Rodrigo Navarro Date: Tue, 22 Oct 2024 16:46:44 -0300 Subject: [PATCH 2/2] modified pty description --- src/main/java/com/plugin/sshjplugin/SSHJNodeExecutorPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/plugin/sshjplugin/SSHJNodeExecutorPlugin.java b/src/main/java/com/plugin/sshjplugin/SSHJNodeExecutorPlugin.java index ae32564..74cade1 100644 --- a/src/main/java/com/plugin/sshjplugin/SSHJNodeExecutorPlugin.java +++ b/src/main/java/com/plugin/sshjplugin/SSHJNodeExecutorPlugin.java @@ -188,7 +188,7 @@ public class SSHJNodeExecutorPlugin implements NodeExecutor, ProxySecretBundleCr false, "false"); public static final Property ALWAYS_SET_PTY = PropertyUtil.bool(CONFIG_SET_PTY, "Force PTY", - "Always force use of new pty, enabling this option will suppress some logging", + "Always force use of new pty", false, "false"); private SSHClient sshClient;