Skip to content

Commit

Permalink
Merge pull request #66 from rundeck-plugins/RUN-2634-pty
Browse files Browse the repository at this point in the history
RPL-40: add pty option
  • Loading branch information
ronaveva authored Oct 28, 2024
2 parents 7655934 + df4199e commit b2d0971
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/plugin/sshjplugin/SSHJBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/plugin/sshjplugin/SSHJNodeExecutorPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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",
false, "false");

private SSHClient sshClient;

public void setSshClient(SSHClient sshClient) {
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}

Expand All @@ -246,6 +259,7 @@ public NodeExecutorResult executeCommand(ExecutionContext context, String[] comm
node
);
}

boolean success = false;

final ExecutionListener listener = context.getExecutionListener();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/plugin/sshjplugin/model/SSHJConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ static enum AuthenticationType {
Map<String, String> getSshConfig();

String getBindAddress();

boolean isAllocatePTY();

}
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ public Map<String, String> getSshConfig() {
public String getBindAddress() {
return null;
}

@Override
public boolean isAllocatePTY() {
return propertyResolver.resolveBoolean(SSHJNodeExecutorPlugin.CONFIG_SET_PTY);
}



Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/plugin/sshjplugin/model/SSHJExec.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ public class SSHJExec extends SSHJBase implements SSHJEnvironments {
private String command = null;
private int exitStatus = -1;
private Map<String, String> 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;
}
Expand All @@ -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" );

Expand Down

0 comments on commit b2d0971

Please sign in to comment.