Skip to content

Commit

Permalink
Merge pull request #3 from jasonwee/support-pki
Browse files Browse the repository at this point in the history
support pki using keyfile
  • Loading branch information
jasonwee authored Feb 3, 2020
2 parents fc92bbc + 3477006 commit 115e6fe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/java/io/jenkins/plugins/sample/MTRBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class MTRBuilder extends Builder implements SimpleBuildStep {
private String nodes;

private String sshUsername;
private String sshKeyfile;
private String sshPassword;
private int sshPort;

Expand All @@ -52,9 +53,10 @@ public class MTRBuilder extends Builder implements SimpleBuildStep {
private Integer id;

@DataBoundConstructor
public MTRBuilder(String nodes, String sshUsername, String sshPassword, int sshPort, String ip2locationPyPath) {
public MTRBuilder(String nodes, String sshUsername, String sshKeyfile, String sshPassword, int sshPort, String ip2locationPyPath) {
this.nodes = nodes;
this.sshUsername = sshUsername;
this.sshKeyfile = sshKeyfile;
this.sshPassword = sshPassword;
this.sshPort = sshPort;
this.ip2locationPyPath = ip2locationPyPath;
Expand All @@ -76,6 +78,14 @@ public void setSshUsername(String sshUsername) {
this.sshUsername = sshUsername;
}

public String getSshKeyfile() {
return sshKeyfile;
}

public void setSshKeyfile(String sshKeyfile) {
this.sshKeyfile = sshKeyfile;
}

public String getSshPassword() {
return sshPassword;
}
Expand Down Expand Up @@ -272,7 +282,10 @@ private Session createSession(final PrintStream logger, String sNode) throws JSc

JSch jsch = new JSch();
Session session = jsch.getSession(getSshUsername(), sNode, getSshPort());
session.setPassword(getSshPassword());
if (sshKeyfile != null && !sshKeyfile.isEmpty())
jsch.addIdentity(sshKeyfile);
else
session.setPassword(getSshPassword());

final Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<f:entry title="${%SSHUsername}" field="sshUsername">
<f:textbox />
</f:entry>
<f:entry title="${%SSHKeyfile}" field="sshKeyfile">
<f:textbox />
</f:entry>
<f:entry title="${%SSHPassword}" field="sshPassword">
<f:textbox />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SSHUsername=SSH Username
SSHKeyfile=SSH KeyFile
SSHPassword=SSH Password
SSHPort=SSH Port
IP2LocationPyPath=IP2Location python path
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
ssh keyfile common between nodes, you should setup a monitoring user and its keyfile for this.
</div>

0 comments on commit 115e6fe

Please sign in to comment.